Merge pull request #1273 from suhailanzar/batch-discount

fix: quantity handling in batch wise item
This commit is contained in:
Able k Saju
2025-07-10 15:02:05 +05:30
committed by GitHub
2 changed files with 41 additions and 2 deletions
+13 -1
View File
@@ -1087,10 +1087,22 @@ export async function getPricingRule(
continue; 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( const filtered = filterPricingRules(
doc as SalesInvoice, doc as SalesInvoice,
pricingRuleDocsForItem, pricingRuleDocsForItem,
item.quantity as number, itemQuantity[item.item as string],
item.amount as Money item.amount as Money
); );
+28 -1
View File
@@ -690,12 +690,39 @@ export default defineComponent({
)) as number; )) as number;
if (item.hasBatch) { 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', { await this.sinvDoc.append('items', {
rate: item.rate as Money, rate: item.rate as Money,
item: item.name, item: item.name,
quantity: quantity ? quantity : 1, quantity: addQty,
hsnCode: itemsHsncode, hsnCode: itemsHsncode,
}); });
await this.applyPricingRule();
await this.sinvDoc.runFormulas();
return; return;
} }