From 81f91a42bfd91b292cf4adbfa7bd7da76704f063 Mon Sep 17 00:00:00 2001 From: Gadha2311 Date: Mon, 7 Jul 2025 15:08:52 +0530 Subject: [PATCH 1/3] fix: resolve issue in grand total calculation with loyalty points applied --- models/baseModels/Invoice/Invoice.ts | 20 ++++++++++++++----- .../POS/Classic/SelectedItemRow.vue | 2 +- src/pages/POS/POS.vue | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 59624588..2545c1b1 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -888,21 +888,31 @@ export abstract class Invoice extends Transactional { } async getLPAddedBaseGrandTotal() { - if (!this.initialGrandTotal) { - this.initialGrandTotal = this.grandTotal; + const totalDiscount = this.getTotalDiscount(); + + let baseTotal = this.fyo.pesa(0); + if (!this.taxes!.length) { + baseTotal = (this.netTotal as Money).sub(totalDiscount); + } else { + baseTotal = ((this.taxes ?? []) as Doc[]) + .map((doc) => doc.amount as Money) + .reduce((a, b) => { + return a.add(b.abs()); + }, (this.netTotal as Money).abs()) + .sub(totalDiscount); } - const totalLotaltyAmount = await getAddedLPWithGrandTotal( + const totalLoyaltyAmount = await getAddedLPWithGrandTotal( this.fyo, this.loyaltyProgram as string, this.loyaltyPoints as number ); if (this.isReturn) { - return this.grandTotal; + return baseTotal.abs().sub(totalLoyaltyAmount); } - return this.initialGrandTotal?.sub(totalLotaltyAmount); + return baseTotal.sub(totalLoyaltyAmount); } formulas: FormulaMap = { account: { diff --git a/src/components/POS/Classic/SelectedItemRow.vue b/src/components/POS/Classic/SelectedItemRow.vue index cb540f43..d92fecd7 100644 --- a/src/components/POS/Classic/SelectedItemRow.vue +++ b/src/components/POS/Classic/SelectedItemRow.vue @@ -459,7 +459,7 @@ export default defineComponent({ }, async removeAddedItem(row: SalesInvoiceItem) { this.row.parentdoc?.remove('items', row?.idx as number); - + this.row.runFormulas(); if (!row.isFreeItem) { this.$emit('applyPricingRule'); } diff --git a/src/pages/POS/POS.vue b/src/pages/POS/POS.vue index 472eecfd..340939ad 100644 --- a/src/pages/POS/POS.vue +++ b/src/pages/POS/POS.vue @@ -610,6 +610,7 @@ export default defineComponent({ async setLoyaltyPoints(value: number) { this.appliedLoyaltyPoints = value; await this.sinvDoc.set('redeemLoyaltyPoints', true); + await this.sinvDoc.runFormulas(); }, async selectedInvoiceName(doc: SalesInvoice) { const salesInvoiceDoc = (await this.fyo.doc.getDoc( From 6eba31958fcde5f611a0064d3a526bae9d3e53e5 Mon Sep 17 00:00:00 2001 From: Gadha2311 Date: Mon, 21 Jul 2025 10:39:12 +0530 Subject: [PATCH 2/3] fix: remove unnecessary tax type assertion --- models/baseModels/Invoice/Invoice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index 2545c1b1..ee41cc29 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -891,10 +891,10 @@ export abstract class Invoice extends Transactional { const totalDiscount = this.getTotalDiscount(); let baseTotal = this.fyo.pesa(0); - if (!this.taxes!.length) { + if (!this.taxes || !this.taxes.length) { baseTotal = (this.netTotal as Money).sub(totalDiscount); } else { - baseTotal = ((this.taxes ?? []) as Doc[]) + baseTotal = this.taxes .map((doc) => doc.amount as Money) .reduce((a, b) => { return a.add(b.abs()); From 45b649cc10a89325ea06f449106222a832006460 Mon Sep 17 00:00:00 2001 From: Gadha2311 Date: Wed, 23 Jul 2025 11:24:18 +0530 Subject: [PATCH 3/3] fix: transfer qty in loyalty returns --- models/baseModels/Invoice/Invoice.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index ee41cc29..ccf71f75 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -79,7 +79,6 @@ export abstract class Invoice extends Transactional { grandTotal?: Money; baseGrandTotal?: Money; outstandingAmount?: Money; - initialGrandTotal?: Money; exchangeRate?: number; setDiscountAmount?: boolean; discountAmount?: Money; @@ -909,7 +908,7 @@ export abstract class Invoice extends Transactional { ); if (this.isReturn) { - return baseTotal.abs().sub(totalLoyaltyAmount); + return this.grandTotal; } return baseTotal.sub(totalLoyaltyAmount);