Merge pull request #1272 from Gadha2311/loyaltypoint-grandtotal

fix: resolve issue in grand total calculation with loyalty points applied
This commit is contained in:
Able k Saju
2025-07-23 12:01:38 +05:30
committed by GitHub
3 changed files with 16 additions and 6 deletions
+14 -5
View File
@@ -79,7 +79,6 @@ export abstract class Invoice extends Transactional {
grandTotal?: Money;
baseGrandTotal?: Money;
outstandingAmount?: Money;
initialGrandTotal?: Money;
exchangeRate?: number;
setDiscountAmount?: boolean;
discountAmount?: Money;
@@ -889,11 +888,21 @@ 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 || !this.taxes.length) {
baseTotal = (this.netTotal as Money).sub(totalDiscount);
} else {
baseTotal = this.taxes
.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
@@ -903,7 +912,7 @@ export abstract class Invoice extends Transactional {
return this.grandTotal;
}
return this.initialGrandTotal?.sub(totalLotaltyAmount);
return baseTotal.sub(totalLoyaltyAmount);
}
formulas: FormulaMap = {
account: {
@@ -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');
}
+1
View File
@@ -616,6 +616,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(