mirror of
https://github.com/frappe/books.git
synced 2025-01-10 18:24:40 +00:00
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import frappe from 'frappe';
|
|
|
|
export default {
|
|
async getPayments() {
|
|
let payments = await frappe.db.getAll({
|
|
doctype: 'PaymentFor',
|
|
fields: ['parent'],
|
|
filters: { referenceName: this.name },
|
|
orderBy: 'name',
|
|
});
|
|
if (payments.length != 0) {
|
|
return payments;
|
|
}
|
|
return [];
|
|
},
|
|
|
|
async beforeUpdate() {
|
|
const entries = await this.getPosting();
|
|
await entries.validateEntries();
|
|
},
|
|
|
|
async beforeInsert() {
|
|
const entries = await this.getPosting();
|
|
await entries.validateEntries();
|
|
},
|
|
|
|
async afterSubmit() {
|
|
// post ledger entries
|
|
const entries = await this.getPosting();
|
|
await entries.post();
|
|
|
|
// update outstanding amounts
|
|
await frappe.db.update(this.doctype, {
|
|
name: this.name,
|
|
outstandingAmount: this.baseGrandTotal,
|
|
});
|
|
|
|
let party = await frappe.doc.getDoc(
|
|
'Party',
|
|
this.customer || this.supplier
|
|
);
|
|
await party.updateOutstandingAmount();
|
|
},
|
|
|
|
async afterRevert() {
|
|
let paymentRefList = await this.getPayments();
|
|
for (let paymentFor of paymentRefList) {
|
|
const paymentReference = paymentFor.parent;
|
|
const payment = await frappe.doc.getDoc('Payment', paymentReference);
|
|
const paymentEntries = await payment.getPosting();
|
|
await paymentEntries.postReverse();
|
|
// To set the payment status as unsubmitted.
|
|
await frappe.db.update('Payment', {
|
|
name: paymentReference,
|
|
submitted: 0,
|
|
cancelled: 1,
|
|
});
|
|
}
|
|
const entries = await this.getPosting();
|
|
await entries.postReverse();
|
|
},
|
|
};
|