mirror of
https://github.com/frappe/books.git
synced 2026-08-24 02:24:17 -05:00
fix: correct round-off account source allocation
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user