2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50: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 quantity = row.stockNotTransferred;
const trackItem = itemDoc.trackItem;
const batchNumber = row.batchNumber || null;
let rate = row.rate as Money;
if (this.exchangeRate && this.exchangeRate > 1) {
@ -561,6 +562,7 @@ export abstract class Invoice extends Transactional {
quantity,
location,
rate,
batchNumber,
});
}

View File

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

View File

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

View File

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