mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
fix: Update party outstanding amount
This commit is contained in:
parent
061c405212
commit
dc160a4232
@ -18,4 +18,19 @@ module.exports = class PartyServer extends BaseDocument {
|
||||
this.gstin = '';
|
||||
}
|
||||
}
|
||||
|
||||
async updateOutstandingAmount() {
|
||||
let isCustomer = this.customer;
|
||||
let doctype = isCustomer ? 'SalesInvoice' : 'PurchaseInvoice';
|
||||
let partyField = isCustomer ? 'customer' : 'supplier';
|
||||
let { totalOutstanding } = await frappe.db.knex
|
||||
.sum({ totalOutstanding: 'outstandingAmount' })
|
||||
.from(doctype)
|
||||
.where('submitted', 1)
|
||||
.andWhere(partyField, this.name)
|
||||
.first();
|
||||
|
||||
await this.set('outstandingAmount', this.round(totalOutstanding));
|
||||
await this.update();
|
||||
}
|
||||
};
|
||||
|
@ -42,9 +42,12 @@ module.exports = class PaymentServer extends BaseDocument {
|
||||
`Payment amount (${this.amount}) should be greater than 0 and less than Outstanding amount (${outstandingAmount})`
|
||||
);
|
||||
} else {
|
||||
// update outstanding amounts in invoice and party
|
||||
let newOutstanding = outstandingAmount - this.amount;
|
||||
await referenceDoc.set('outstandingAmount', newOutstanding);
|
||||
await referenceDoc.update();
|
||||
let party = await frappe.getDoc('Party', this.party);
|
||||
await party.updateOutstandingAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,21 @@ module.exports = {
|
||||
await entries.validateEntries();
|
||||
},
|
||||
|
||||
async beforeSubmit() {
|
||||
async afterSubmit() {
|
||||
// post ledger entries
|
||||
const entries = await this.getPosting();
|
||||
await entries.post();
|
||||
|
||||
// update outstanding amounts
|
||||
await frappe.db.setValue(
|
||||
this.doctype,
|
||||
this.name,
|
||||
'outstandingAmount',
|
||||
this.baseGrandTotal
|
||||
);
|
||||
|
||||
let party = await frappe.getDoc('Party', this.customer || this.supplier);
|
||||
await party.updateOutstandingAmount();
|
||||
},
|
||||
|
||||
async afterRevert() {
|
||||
|
Loading…
Reference in New Issue
Block a user