2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

fix: valuation calculation when batches

- use InvoiceItem batch on getStockTransfer
This commit is contained in:
18alantom 2023-02-27 18:54:49 +05:30
parent 9646580b38
commit 7029fa79ae
4 changed files with 14 additions and 12 deletions

View File

@ -546,6 +546,7 @@ export abstract class Invoice extends Transactional {
const item = row.item; const item = row.item;
const quantity = row.stockNotTransferred; const quantity = row.stockNotTransferred;
const trackItem = itemDoc.trackItem; const trackItem = itemDoc.trackItem;
const batchNumber = row.batchNumber || null;
let rate = row.rate as Money; let rate = row.rate as Money;
if (this.exchangeRate && this.exchangeRate > 1) { if (this.exchangeRate && this.exchangeRate > 1) {
@ -561,6 +562,7 @@ export abstract class Invoice extends Transactional {
quantity, quantity,
location, location,
rate, rate,
batchNumber,
}); });
} }

View File

@ -29,6 +29,7 @@ export abstract class InvoiceItem extends Doc {
quantity?: number; quantity?: number;
transferQuantity?: number; transferQuantity?: number;
unitConversionFactor?: number; unitConversionFactor?: number;
batchNumber?: string;
tax?: string; tax?: string;
stockNotTransferred?: number; stockNotTransferred?: number;

View File

@ -11,6 +11,7 @@ import {
type Item = string; type Item = string;
type Location = string; type Location = string;
type BatchNo = string;
export async function getRawStockLedgerEntries(fyo: Fyo) { export async function getRawStockLedgerEntries(fyo: Fyo) {
const fieldnames = [ const fieldnames = [
@ -37,29 +38,27 @@ export function getStockLedgerEntries(
valuationMethod: ValuationMethod valuationMethod: ValuationMethod
): ComputedStockLedgerEntry[] { ): ComputedStockLedgerEntry[] {
const computedSLEs: ComputedStockLedgerEntry[] = []; const computedSLEs: ComputedStockLedgerEntry[] = [];
const stockQueues: Record<Item, Record<Location, StockQueue>> = {}; const stockQueues: Record<
Item,
Record<Location, Record<BatchNo, StockQueue>>
> = {};
for (const sle of rawSLEs) { for (const sle of rawSLEs) {
const name = safeParseInt(sle.name); const name = safeParseInt(sle.name);
const date = new Date(sle.date); const date = new Date(sle.date);
const rate = safeParseFloat(sle.rate); const rate = safeParseFloat(sle.rate);
const { const { item, location, quantity, referenceName, referenceType } = sle;
item, const batchNumber = sle.batchNumber ?? '';
location,
batchNumber,
quantity,
referenceName,
referenceType,
} = sle;
if (quantity === 0) { if (quantity === 0) {
continue; continue;
} }
stockQueues[item] ??= {}; stockQueues[item] ??= {};
stockQueues[item][location] ??= new StockQueue(); stockQueues[item][location] ??= {};
stockQueues[item][location][batchNumber] ??= new StockQueue();
const q = stockQueues[item][location]; const q = stockQueues[item][location][batchNumber];
const initialValue = q.value; const initialValue = q.value;
let incomingRate: number | null; let incomingRate: number | null;

View File

@ -5,7 +5,7 @@ export interface RawStockLedgerEntry {
date: string; date: string;
item: string; item: string;
rate: string; rate: string;
batchNumber: string; batchNumber: string | null;
quantity: number; quantity: number;
location: string; location: string;
referenceName: string; referenceName: string;