chore: fetch logic for payment entry

This commit is contained in:
ruthra kumar 2023-08-29 15:15:14 +05:30
parent 25fe752185
commit 1981f3837a
2 changed files with 51 additions and 28 deletions

View File

@ -82,10 +82,10 @@ def get_linked_payments_for_doc(
ple = qb.DocType("Payment Ledger Entry")
if _dt in ["Sales Invoice", "Purchase Invoice"]:
criteria = [
(ple.company == company),
(ple.delinked == 0),
(ple.against_voucher_no == _dn),
(ple.amount < 0),
(ple.company == company),
]
res = (
@ -102,17 +102,26 @@ def get_linked_payments_for_doc(
)
return res
else:
return frappe.db.get_all(
"Payment Ledger Entry",
filters={
"delinked": 0,
"voucher_no": _dn,
"against_voucher_no": ["!=", _dn],
"amount": ["<", 0],
},
group_by="against_voucher_no",
fields=["against_voucher_type", "against_voucher_no", "Sum(amount_in_account_currency)"],
criteria = [
(ple.company == company),
(ple.delinked == 0),
(ple.voucher_no == _dn),
(ple.against_voucher_no != _dn),
]
query = (
qb.from_(ple)
.select(
ple.company,
ple.against_voucher_type.as_("voucher_type"),
ple.against_voucher_no.as_("voucher_no"),
Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"),
)
.where(Criterion.all(criteria))
.groupby(ple.against_voucher_no)
)
res = query.run(as_dict=True)
return res
return []

View File

@ -20,6 +20,34 @@ erpnext.accounts.unreconcile_payments = {
}
},
build_selection_map(frm, selections) {
// assuming each row is an individual voucher
// pass this to server side method that creates unreconcile doc for each row
let selection_map = [];
if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) {
selection_map = selections.map(function(elem) {
return {
company: elem.company,
voucher_type: elem.voucher_type,
voucher_no: elem.voucher_no,
against_voucher_type: frm.doc.doctype,
against_voucher_no: frm.doc.name
};
});
} else if (['Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
selection_map = selections.map(function(elem) {
return {
company: elem.company,
voucher_type: frm.doc.doctype,
voucher_no: frm.doc.name,
against_voucher_type: elem.voucher_type,
against_voucher_no: elem.voucher_no,
};
});
}
return selection_map;
},
build_unreconcile_dialog(frm) {
if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
let child_table_fields = [
@ -61,23 +89,9 @@ erpnext.accounts.unreconcile_payments = {
let selected_allocations = values.allocations.filter(x=>x.__checked);
if (selected_allocations.length > 0) {
// assuming each row is an individual voucher
// pass this to server side method that creates unreconcile doc for each row
if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) {
let selection_map = selected_allocations.map(function(elem) {
return {
company: elem.company,
voucher_type: elem.voucher_type,
voucher_no: elem.voucher_no,
against_voucher_type: frm.doc.doctype,
against_voucher_no: frm.doc.name
};
});
erpnext.utils.create_unreconcile_docs(selection_map);
d.hide();
}
let selection_map = erpnext.accounts.unreconcile_payments.build_selection_map(frm, selected_allocations);
erpnext.accounts.unreconcile_payments.create_unreconcile_docs(selection_map);
d.hide();
} else {
frappe.msgprint("No Selection");