fix: quantity handling in batch wise item

This commit is contained in:
suhailanzar
2025-06-30 10:56:17 +05:30
parent 7e515f7be9
commit 5a3f109b7e
2 changed files with 41 additions and 2 deletions
+13 -1
View File
@@ -1087,10 +1087,22 @@ export async function getPricingRule(
continue;
}
const itemQuantity: Record<string, number> = {};
for (const item of doc.items) {
if (!item?.item) continue;
if (!itemQuantity[item.item]) {
itemQuantity[item.item] = item.quantity ?? 0;
} else {
itemQuantity[item.item] += item.quantity ?? 0;
}
}
const filtered = filterPricingRules(
doc as SalesInvoice,
pricingRuleDocsForItem,
item.quantity as number,
itemQuantity[item.item as string],
item.amount as Money
);
+28 -1
View File
@@ -690,12 +690,39 @@ export default defineComponent({
)) as number;
if (item.hasBatch) {
const addQty = quantity ?? 1;
if (existingItems.length > 0) {
for (let item of existingItems) {
const availableQty = await fyo.db.getStockQuantity(
item.item as string,
undefined,
undefined,
undefined,
item.batch
);
if (
item.batch != null &&
availableQty != null &&
availableQty > (item.quantity as number)
) {
const currentQty = item.quantity ?? 0;
await item.set('quantity', currentQty + addQty);
await this.applyPricingRule();
await this.sinvDoc.runFormulas();
return;
}
}
}
await this.sinvDoc.append('items', {
rate: item.rate as Money,
item: item.name,
quantity: quantity ? quantity : 1,
quantity: addQty,
hsnCode: itemsHsncode,
});
await this.applyPricingRule();
await this.sinvDoc.runFormulas();
return;
}