fix: correct round-off account source allocation

This commit is contained in:
Gadha2311
2026-01-30 14:44:16 +05:30
parent 69604d011c
commit 0aab1167a4
2 changed files with 31 additions and 11 deletions
+8 -6
View File
@@ -461,7 +461,10 @@ export class Payment extends Transactional {
);
const previousOutstandingAmount = referenceDoc.outstandingAmount as Money;
const outstandingAmount = previousOutstandingAmount.sub(row.amount!);
const isReturnInvoice = (referenceDoc as Invoice).isReturn;
const outstandingAmount = isReturnInvoice
? previousOutstandingAmount.add(row.amount!)
: previousOutstandingAmount.sub(row.amount!);
await referenceDoc.setAndSync({ outstandingAmount });
}
}
@@ -505,11 +508,10 @@ export class Payment extends Transactional {
ref.referenceType!,
ref.referenceName
);
const outstandingAmount = (refDoc.outstandingAmount as Money).add(
ref.amount!
);
const isReturnInvoice = (refDoc as Invoice).isReturn;
const outstandingAmount = isReturnInvoice
? (refDoc.outstandingAmount as Money).sub(ref.amount!)
: (refDoc.outstandingAmount as Money).add(ref.amount!);
await refDoc.setAndSync({ outstandingAmount });
}
}
+23 -5
View File
@@ -43,12 +43,12 @@ export class SalesInvoice extends Invoice {
this.loyaltyProgram
)) as LoyaltyProgram;
let totalAmount;
let loyaltyAmount;
if (this.isReturn) {
totalAmount = this.fyo.pesa(await getReturnLoyaltyPoints(this));
loyaltyAmount = this.fyo.pesa(await getReturnLoyaltyPoints(this));
} else {
totalAmount = await getAddedLPWithGrandTotal(
loyaltyAmount = await getAddedLPWithGrandTotal(
this.fyo,
this.loyaltyProgram as string,
this.loyaltyPoints as number
@@ -57,10 +57,28 @@ export class SalesInvoice extends Invoice {
await posting.debit(
loyaltyProgramDoc.expenseAccount as string,
totalAmount
loyaltyAmount
);
await posting.credit(this.account!, totalAmount);
await posting.credit(this.account!, loyaltyAmount);
const { debit, credit } = posting._getTotalDebitAndCredit();
const difference = debit.sub(credit);
const absoluteValue = difference.abs();
if (!absoluteValue.eq(0)) {
if (difference.gt(0)) {
await posting.credit(
loyaltyProgramDoc.expenseAccount as string,
absoluteValue
);
} else {
await posting.debit(
loyaltyProgramDoc.expenseAccount as string,
absoluteValue
);
}
}
}
if (this.taxes) {