2
0
mirror of https://github.com/frappe/books.git synced 2025-02-03 20:48:29 +00:00
books/models/baseModels/Transaction/TransactionServer.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

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();
},
2019-12-26 19:15:25 +05:30
async afterSubmit() {
// post ledger entries
const entries = await this.getPosting();
await entries.post();
2019-12-26 19:15:25 +05:30
// update outstanding amounts
await frappe.db.update(this.doctype, {
name: this.name,
outstandingAmount: this.baseGrandTotal,
});
2019-12-26 19:15:25 +05:30
let party = await frappe.doc.getDoc(
'Party',
this.customer || this.supplier
);
2019-12-26 19:15:25 +05:30
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.
2021-11-21 19:08:04 +05:30
await frappe.db.update('Payment', {
name: paymentReference,
submitted: 0,
cancelled: 1,
});
}
const entries = await this.getPosting();
await entries.postReverse();
},
};