mirror of
https://github.com/frappe/books.git
synced 2025-01-03 15:17:30 +00:00
fix: remove free item when quantity decreses
This commit is contained in:
parent
3126379d80
commit
720ab08ec4
@ -1121,18 +1121,14 @@ export abstract class Invoice extends Transactional {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.pricingRuleDetail?.length || !this.pricingRuleDetail.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.items = this.items.filter((item) => !item.isFreeItem);
|
this.items = this.items.filter((item) => !item.isFreeItem);
|
||||||
|
|
||||||
for (const item of this.items) {
|
for (const item of this.items) {
|
||||||
const pricingRuleDetailForItem = this.pricingRuleDetail.filter(
|
const pricingRuleDetailForItem = this.pricingRuleDetail?.filter(
|
||||||
(doc) => doc.referenceItem === item.item
|
(doc) => doc.referenceItem === item.item
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!pricingRuleDetailForItem.length) {
|
if (!pricingRuleDetailForItem?.length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,38 +358,34 @@ export default defineComponent({
|
|||||||
this.row.setRate = rate;
|
this.row.setRate = rate;
|
||||||
this.$emit('runSinvFormulas');
|
this.$emit('runSinvFormulas');
|
||||||
},
|
},
|
||||||
setQuantity(quantity: number) {
|
async setQuantity(quantity: number) {
|
||||||
this.row.setQuantity = quantity;
|
this.row.set('quantity', quantity);
|
||||||
|
|
||||||
|
if (!this.row.isFreeItem) {
|
||||||
|
await this.updatePricingRuleItem();
|
||||||
this.$emit('runSinvFormulas');
|
this.$emit('runSinvFormulas');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setTransferUnit(unit: string) {
|
async removeAddedItem(row: SalesInvoiceItem) {
|
||||||
this.row.setTransferUnit = unit;
|
|
||||||
this.row._applyFormula('transferUnit');
|
|
||||||
},
|
|
||||||
setTransferQty(quantity: number) {
|
|
||||||
this.row.transferQuantity = quantity;
|
|
||||||
this.row._applyFormula('transferQuantity');
|
|
||||||
this.$emit('runSinvFormulas');
|
|
||||||
},
|
|
||||||
removeAddedItem(row: SalesInvoiceItem) {
|
|
||||||
this.row.parentdoc?.remove('items', row?.idx as number);
|
this.row.parentdoc?.remove('items', row?.idx as number);
|
||||||
|
|
||||||
if (!row.isFreeItem) {
|
if (!row.isFreeItem) {
|
||||||
this.updatePricingRuleItem();
|
await this.updatePricingRuleItem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async updatePricingRuleItem() {
|
async updatePricingRuleItem() {
|
||||||
const pricingRule = await this.row.parentdoc?.getPricingRule() as ApplicablePricingRules[];
|
const pricingRule =
|
||||||
|
(await this.row.parentdoc?.getPricingRule()) as ApplicablePricingRules[];
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
const appliedPricingRuleCount = this.row.parentdoc?.items?.filter(
|
const appliedPricingRuleCount = this.row.parentdoc?.items?.filter(
|
||||||
(val) => val.isFreeItem
|
(val) => val.isFreeItem
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
if (appliedPricingRuleCount !== pricingRule?.length) {
|
if (appliedPricingRuleCount !== pricingRule?.length) {
|
||||||
this.row.parentdoc?.appendPricingRuleDetail(pricingRule);
|
await this.row.parentdoc?.appendPricingRuleDetail(pricingRule);
|
||||||
|
|
||||||
this.row.parentdoc?.applyProductDiscount();
|
await this.row.parentdoc?.applyProductDiscount();
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user