mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix: unable to pay multiple invoices
This commit is contained in:
parent
7c03b98d67
commit
5f937b041b
@ -129,7 +129,6 @@ export class Payment extends Transactional {
|
||||
?.label!} does not exist`
|
||||
);
|
||||
}
|
||||
console.log(refDoc);
|
||||
|
||||
if (!refDoc) {
|
||||
continue;
|
||||
@ -259,8 +258,9 @@ export class Payment extends Transactional {
|
||||
|
||||
for (const row of forReferences) {
|
||||
this.validateReferenceType(row);
|
||||
await this.validateReferenceOutstanding(row);
|
||||
}
|
||||
|
||||
await this.validateReferenceOutstanding();
|
||||
}
|
||||
|
||||
validateReferenceType(row: PaymentFor) {
|
||||
@ -274,13 +274,19 @@ export class Payment extends Transactional {
|
||||
}
|
||||
}
|
||||
|
||||
async validateReferenceOutstanding(row: PaymentFor) {
|
||||
const referenceDoc = await this.fyo.doc.getDoc(
|
||||
row.referenceType as string,
|
||||
row.referenceName as string
|
||||
);
|
||||
async validateReferenceOutstanding() {
|
||||
let outstandingAmount = this.fyo.pesa(0);
|
||||
for (const row of this.for ?? []) {
|
||||
const referenceDoc = (await this.fyo.doc.getDoc(
|
||||
row.referenceType as string,
|
||||
row.referenceName as string
|
||||
)) as Invoice;
|
||||
|
||||
outstandingAmount = outstandingAmount.add(
|
||||
referenceDoc.outstandingAmount ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
const outstandingAmount = referenceDoc.outstandingAmount as Money;
|
||||
const amount = this.amount as Money;
|
||||
|
||||
if (amount.gt(0) && amount.lte(outstandingAmount)) {
|
||||
@ -317,7 +323,7 @@ export class Payment extends Transactional {
|
||||
);
|
||||
|
||||
const previousOutstandingAmount = referenceDoc.outstandingAmount as Money;
|
||||
const outstandingAmount = previousOutstandingAmount.sub(this.amount!);
|
||||
const outstandingAmount = previousOutstandingAmount.sub(row.amount!);
|
||||
await referenceDoc.setAndSync({ outstandingAmount });
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,6 @@ export class PaymentFor extends Doc {
|
||||
|
||||
validations: ValidationMap = {
|
||||
referenceName: async (value: DocValue) => {
|
||||
console.log(value);
|
||||
const exists = await this.fyo.db.exists(
|
||||
this.referenceType!,
|
||||
value as string
|
||||
|
Loading…
Reference in New Issue
Block a user