mirror of
https://github.com/frappe/books.git
synced 2026-08-24 02:24:17 -05:00
Merge pull request #1361 from Gadha2311/return-outstandingzero
fix : set outstanding to zero for return payments
This commit is contained in:
@@ -1047,19 +1047,15 @@ export abstract class Invoice extends Transactional {
|
||||
if (sinvreturnedDoc.outstandingAmount?.isZero()) {
|
||||
return this.grandTotal?.abs();
|
||||
} else {
|
||||
const totalPaid = sinvreturnedDoc.grandTotal
|
||||
?.abs()
|
||||
.sub(sinvreturnedDoc.outstandingAmount as Money);
|
||||
const totalPaid = sinvreturnedDoc
|
||||
.grandTotal!.abs()
|
||||
.sub(sinvreturnedDoc.outstandingAmount!);
|
||||
|
||||
if (!sinvreturnedDoc.isReturn) {
|
||||
return totalPaid?.abs();
|
||||
}
|
||||
const outstandingAmount = this.grandTotal!.abs();
|
||||
|
||||
if (!this.grandTotal?.isNegative()) {
|
||||
this.grandTotal = this.grandTotal?.neg();
|
||||
}
|
||||
|
||||
return this.grandTotal?.add(totalPaid as Money).abs();
|
||||
return outstandingAmount.lte(totalPaid)
|
||||
? outstandingAmount
|
||||
: totalPaid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1290,18 +1286,21 @@ export abstract class Invoice extends Transactional {
|
||||
paymentType = PaymentTypeEnum.Receive;
|
||||
}
|
||||
}
|
||||
const paymentAmount = this.isReturn
|
||||
? outstandingAmount
|
||||
: outstandingAmount?.abs();
|
||||
|
||||
const data = {
|
||||
party: this.party,
|
||||
date: new Date().toISOString(),
|
||||
paymentType,
|
||||
amount: this.outstandingAmount?.abs(),
|
||||
amount: paymentAmount,
|
||||
[accountField]: this.account,
|
||||
for: [
|
||||
{
|
||||
referenceType: this.schemaName,
|
||||
referenceName: this.name,
|
||||
amount: this.outstandingAmount,
|
||||
amount: this.isReturn ? this.grandTotal : outstandingAmount,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1313,7 +1312,6 @@ export abstract class Invoice extends Transactional {
|
||||
|
||||
return this.fyo.doc.getNewDoc(ModelNameEnum.Payment, data) as Payment;
|
||||
}
|
||||
|
||||
async getStockTransfer(isAuto = false): Promise<StockTransfer | null> {
|
||||
if (!this.isSubmitted) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user