diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 37ce836c..6141cc03 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -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; } diff --git a/src/components/POS/SelectedItemRow.vue b/src/components/POS/SelectedItemRow.vue index 5545c528..d15a2ace 100644 --- a/src/components/POS/SelectedItemRow.vue +++ b/src/components/POS/SelectedItemRow.vue @@ -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); },