mirror of
https://github.com/frappe/books.git
synced 2024-12-22 19:09:01 +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;
|
||||
}
|
||||
|
||||
if (!this.pricingRuleDetail?.length || !this.pricingRuleDetail.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.items = this.items.filter((item) => !item.isFreeItem);
|
||||
|
||||
for (const item of this.items) {
|
||||
const pricingRuleDetailForItem = this.pricingRuleDetail.filter(
|
||||
const pricingRuleDetailForItem = this.pricingRuleDetail?.filter(
|
||||
(doc) => doc.referenceItem === item.item
|
||||
);
|
||||
|
||||
if (!pricingRuleDetailForItem.length) {
|
||||
if (!pricingRuleDetailForItem?.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -358,38 +358,34 @@ export default defineComponent({
|
||||
this.row.setRate = rate;
|
||||
this.$emit('runSinvFormulas');
|
||||
},
|
||||
setQuantity(quantity: number) {
|
||||
this.row.setQuantity = quantity;
|
||||
this.$emit('runSinvFormulas');
|
||||
async setQuantity(quantity: number) {
|
||||
this.row.set('quantity', quantity);
|
||||
|
||||
if (!this.row.isFreeItem) {
|
||||
await this.updatePricingRuleItem();
|
||||
this.$emit('runSinvFormulas');
|
||||
}
|
||||
},
|
||||
setTransferUnit(unit: string) {
|
||||
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) {
|
||||
async removeAddedItem(row: SalesInvoiceItem) {
|
||||
this.row.parentdoc?.remove('items', row?.idx as number);
|
||||
|
||||
if (!row.isFreeItem) {
|
||||
this.updatePricingRuleItem();
|
||||
await this.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(
|
||||
(val) => val.isFreeItem
|
||||
).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);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user