mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
feat: batchwise filters in stock ledger and stock balance
This commit is contained in:
parent
9a8e423b72
commit
b3e4073bb7
@ -25,9 +25,11 @@ export class StockBalance extends StockLedger {
|
||||
const filters = {
|
||||
item: this.item,
|
||||
location: this.location,
|
||||
batch: this.batch,
|
||||
fromDate: this.fromDate,
|
||||
toDate: this.toDate,
|
||||
};
|
||||
|
||||
const rawData = getStockBalanceEntries(this._rawData ?? [], filters);
|
||||
|
||||
return rawData.map((sbe, i) => {
|
||||
@ -41,7 +43,7 @@ export class StockBalance extends StockLedger {
|
||||
}
|
||||
|
||||
getFilters(): Field[] {
|
||||
return [
|
||||
const filters = [
|
||||
{
|
||||
fieldtype: 'Link',
|
||||
target: 'Item',
|
||||
@ -56,6 +58,17 @@ export class StockBalance extends StockLedger {
|
||||
label: t`Location`,
|
||||
fieldname: 'location',
|
||||
},
|
||||
...(this.hasBatches
|
||||
? [
|
||||
{
|
||||
fieldtype: 'Link',
|
||||
target: 'BatchNumber',
|
||||
placeholder: t`Batch`,
|
||||
label: t`Batch`,
|
||||
fieldname: 'batch',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
fieldtype: 'Date',
|
||||
placeholder: t`From Date`,
|
||||
@ -69,6 +82,8 @@ export class StockBalance extends StockLedger {
|
||||
fieldname: 'toDate',
|
||||
},
|
||||
] as Field[];
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
getColumns(): ColumnField[] {
|
||||
@ -89,6 +104,11 @@ export class StockBalance extends StockLedger {
|
||||
label: 'Location',
|
||||
fieldtype: 'Link',
|
||||
},
|
||||
...(this.hasBatches
|
||||
? ([
|
||||
{ fieldname: 'batch', label: 'Batch', fieldtype: 'Link' },
|
||||
] as ColumnField[])
|
||||
: []),
|
||||
{
|
||||
fieldname: 'balanceQuantity',
|
||||
label: 'Balance Qty.',
|
||||
|
@ -3,6 +3,7 @@ import { RawValueMap } from 'fyo/core/types';
|
||||
import { Action } from 'fyo/model/types';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { DateTime } from 'luxon';
|
||||
import { InventorySettings } from 'models/inventory/InventorySettings';
|
||||
import { ValuationMethod } from 'models/inventory/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import getCommonExportActions from 'reports/commonExporter';
|
||||
@ -26,6 +27,7 @@ export class StockLedger extends Report {
|
||||
|
||||
item?: string;
|
||||
location?: string;
|
||||
batch?: string;
|
||||
fromDate?: string;
|
||||
toDate?: string;
|
||||
ascending?: boolean;
|
||||
@ -34,6 +36,11 @@ export class StockLedger extends Report {
|
||||
|
||||
groupBy: 'none' | 'item' | 'location' = 'none';
|
||||
|
||||
get hasBatches(): boolean {
|
||||
return !!(this.fyo.singles.InventorySettings as InventorySettings)
|
||||
.enableBatches;
|
||||
}
|
||||
|
||||
constructor(fyo: Fyo) {
|
||||
super(fyo);
|
||||
this._setObservers();
|
||||
@ -110,6 +117,10 @@ export class StockLedger extends Report {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.batch && row.batchNumber !== this.batch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const date = row.date.valueOf();
|
||||
if (toDate && date > toDate) {
|
||||
continue;
|
||||
@ -260,11 +271,11 @@ export class StockLedger extends Report {
|
||||
label: 'Location',
|
||||
fieldtype: 'Link',
|
||||
},
|
||||
{
|
||||
fieldname: 'batchNumber',
|
||||
label: 'Batch No.',
|
||||
fieldtype: 'Link',
|
||||
},
|
||||
...(this.hasBatches
|
||||
? ([
|
||||
{ fieldname: 'batch', label: 'Batch', fieldtype: 'Link' },
|
||||
] as ColumnField[])
|
||||
: []),
|
||||
{
|
||||
fieldname: 'quantity',
|
||||
label: 'Quantity',
|
||||
@ -344,6 +355,17 @@ export class StockLedger extends Report {
|
||||
label: t`Location`,
|
||||
fieldname: 'location',
|
||||
},
|
||||
...(this.hasBatches
|
||||
? ([
|
||||
{
|
||||
fieldtype: 'Link',
|
||||
target: 'BatchNumber',
|
||||
placeholder: t`Batch`,
|
||||
label: t`Batch`,
|
||||
fieldname: 'batch',
|
||||
},
|
||||
] as Field[])
|
||||
: []),
|
||||
{
|
||||
fieldtype: 'Date',
|
||||
placeholder: t`From Date`,
|
||||
|
@ -117,7 +117,10 @@ export function getStockBalanceEntries(
|
||||
toDate?: string;
|
||||
}
|
||||
): StockBalanceEntry[] {
|
||||
const sbeMap: Record<Item, Record<Location, StockBalanceEntry>> = {};
|
||||
const sbeMap: Record<
|
||||
Item,
|
||||
Record<Location, Record<BatchNo, StockBalanceEntry>>
|
||||
> = {};
|
||||
|
||||
const fromDate = filters.fromDate ? Date.parse(filters.fromDate) : null;
|
||||
const toDate = filters.toDate ? Date.parse(filters.toDate) : null;
|
||||
@ -131,16 +134,19 @@ export function getStockBalanceEntries(
|
||||
continue;
|
||||
}
|
||||
|
||||
const batchNumber = sle.batchNumber || '';
|
||||
|
||||
sbeMap[sle.item] ??= {};
|
||||
sbeMap[sle.item][sle.location] ??= getSBE(
|
||||
sbeMap[sle.item][sle.location] ??= {};
|
||||
sbeMap[sle.item][sle.location][batchNumber] ??= getSBE(
|
||||
sle.item,
|
||||
sle.location,
|
||||
sle.batchNumber
|
||||
batchNumber
|
||||
);
|
||||
const date = sle.date.valueOf();
|
||||
|
||||
if (fromDate && date < fromDate) {
|
||||
const sbe = sbeMap[sle.item][sle.location]!;
|
||||
const sbe = sbeMap[sle.item][sle.location][batchNumber];
|
||||
updateOpeningBalances(sbe, sle);
|
||||
continue;
|
||||
}
|
||||
@ -149,13 +155,15 @@ export function getStockBalanceEntries(
|
||||
continue;
|
||||
}
|
||||
|
||||
const sbe = sbeMap[sle.item][sle.location]!;
|
||||
const sbe = sbeMap[sle.item][sle.location][batchNumber];
|
||||
updateCurrentBalances(sbe, sle);
|
||||
}
|
||||
|
||||
return Object.values(sbeMap)
|
||||
.map((sbes) => Object.values(sbes))
|
||||
.flat();
|
||||
.map((sbeBatched) =>
|
||||
Object.values(sbeBatched).map((sbes) => Object.values(sbes))
|
||||
)
|
||||
.flat(2);
|
||||
}
|
||||
|
||||
function getSBE(
|
||||
|
Loading…
Reference in New Issue
Block a user