2
0
mirror of https://github.com/frappe/books.git synced 2024-11-12 16:36:27 +00:00

fix: unable to pay multiple invoices

This commit is contained in:
18alantom 2022-10-08 00:28:44 +05:30
parent 7c03b98d67
commit 5f937b041b
2 changed files with 15 additions and 10 deletions

View File

@ -129,7 +129,6 @@ export class Payment extends Transactional {
?.label!} does not exist` ?.label!} does not exist`
); );
} }
console.log(refDoc);
if (!refDoc) { if (!refDoc) {
continue; continue;
@ -259,8 +258,9 @@ export class Payment extends Transactional {
for (const row of forReferences) { for (const row of forReferences) {
this.validateReferenceType(row); this.validateReferenceType(row);
await this.validateReferenceOutstanding(row);
} }
await this.validateReferenceOutstanding();
} }
validateReferenceType(row: PaymentFor) { validateReferenceType(row: PaymentFor) {
@ -274,13 +274,19 @@ export class Payment extends Transactional {
} }
} }
async validateReferenceOutstanding(row: PaymentFor) { async validateReferenceOutstanding() {
const referenceDoc = await this.fyo.doc.getDoc( let outstandingAmount = this.fyo.pesa(0);
row.referenceType as string, for (const row of this.for ?? []) {
row.referenceName as string 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; const amount = this.amount as Money;
if (amount.gt(0) && amount.lte(outstandingAmount)) { if (amount.gt(0) && amount.lte(outstandingAmount)) {
@ -317,7 +323,7 @@ export class Payment extends Transactional {
); );
const previousOutstandingAmount = referenceDoc.outstandingAmount as Money; const previousOutstandingAmount = referenceDoc.outstandingAmount as Money;
const outstandingAmount = previousOutstandingAmount.sub(this.amount!); const outstandingAmount = previousOutstandingAmount.sub(row.amount!);
await referenceDoc.setAndSync({ outstandingAmount }); await referenceDoc.setAndSync({ outstandingAmount });
} }
} }

View File

@ -93,7 +93,6 @@ export class PaymentFor extends Doc {
validations: ValidationMap = { validations: ValidationMap = {
referenceName: async (value: DocValue) => { referenceName: async (value: DocValue) => {
console.log(value);
const exists = await this.fyo.db.exists( const exists = await this.fyo.db.exists(
this.referenceType!, this.referenceType!,
value as string value as string