mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
feat: batch-wise stock validation
This commit is contained in:
parent
8a4e1e4f41
commit
fef8a0af65
@ -138,9 +138,8 @@ export class StockManager {
|
||||
details.fromLocation,
|
||||
undefined,
|
||||
date,
|
||||
details.batchNumber
|
||||
undefined
|
||||
)) ?? 0;
|
||||
console.log(quantityBefore);
|
||||
|
||||
|
||||
const formattedDate = this.fyo.format(details.date, 'Datetime');
|
||||
@ -149,6 +148,30 @@ export class StockManager {
|
||||
quantityBefore += details.quantity;
|
||||
}
|
||||
|
||||
// batch-wise stock validation
|
||||
let itemsInBatch =
|
||||
(await this.fyo.db.getStockQuantity(
|
||||
details.item,
|
||||
details.fromLocation,
|
||||
undefined,
|
||||
date,
|
||||
details.batchNumber
|
||||
)) ?? 0;
|
||||
|
||||
|
||||
let ifItemHasBatchNumber= await this.fyo.getValue('Item', details.item, 'hasBatchNumber');
|
||||
|
||||
if ((ifItemHasBatchNumber && details.batchNumber) && details.quantity > itemsInBatch) {
|
||||
throw new ValidationError(
|
||||
[
|
||||
t`Insufficient Quantity in Batch ${details.batchNumber}`,
|
||||
t`Additional quantity (${details.quantity - itemsInBatch
|
||||
}) is required in batch ${details.batchNumber} to make the outward transfer of item ${details.item} from ${details.fromLocation
|
||||
} on ${formattedDate}`,
|
||||
].join('\n')
|
||||
);
|
||||
}
|
||||
|
||||
if (quantityBefore < details.quantity) {
|
||||
throw new ValidationError(
|
||||
[
|
||||
@ -165,7 +188,7 @@ export class StockManager {
|
||||
details.fromLocation,
|
||||
details.date.toISOString(),
|
||||
undefined,
|
||||
details.batchNumber
|
||||
undefined
|
||||
);
|
||||
if (quantityAfter === null) {
|
||||
// No future transactions
|
||||
|
Loading…
Reference in New Issue
Block a user