mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
Merge pull request #1273 from suhailanzar/batch-discount
fix: quantity handling in batch wise item
This commit is contained in:
+13
-1
@@ -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
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user