chore: fetch logic for payment entry
This commit is contained in:
parent
25fe752185
commit
1981f3837a
@ -82,10 +82,10 @@ def get_linked_payments_for_doc(
|
|||||||
ple = qb.DocType("Payment Ledger Entry")
|
ple = qb.DocType("Payment Ledger Entry")
|
||||||
if _dt in ["Sales Invoice", "Purchase Invoice"]:
|
if _dt in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
criteria = [
|
criteria = [
|
||||||
|
(ple.company == company),
|
||||||
(ple.delinked == 0),
|
(ple.delinked == 0),
|
||||||
(ple.against_voucher_no == _dn),
|
(ple.against_voucher_no == _dn),
|
||||||
(ple.amount < 0),
|
(ple.amount < 0),
|
||||||
(ple.company == company),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
res = (
|
res = (
|
||||||
@ -102,17 +102,26 @@ def get_linked_payments_for_doc(
|
|||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
return frappe.db.get_all(
|
criteria = [
|
||||||
"Payment Ledger Entry",
|
(ple.company == company),
|
||||||
filters={
|
(ple.delinked == 0),
|
||||||
"delinked": 0,
|
(ple.voucher_no == _dn),
|
||||||
"voucher_no": _dn,
|
(ple.against_voucher_no != _dn),
|
||||||
"against_voucher_no": ["!=", _dn],
|
]
|
||||||
"amount": ["<", 0],
|
|
||||||
},
|
query = (
|
||||||
group_by="against_voucher_no",
|
qb.from_(ple)
|
||||||
fields=["against_voucher_type", "against_voucher_no", "Sum(amount_in_account_currency)"],
|
.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 []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@ -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) {
|
build_unreconcile_dialog(frm) {
|
||||||
if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
|
if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
|
||||||
let child_table_fields = [
|
let child_table_fields = [
|
||||||
@ -61,23 +89,9 @@ erpnext.accounts.unreconcile_payments = {
|
|||||||
|
|
||||||
let selected_allocations = values.allocations.filter(x=>x.__checked);
|
let selected_allocations = values.allocations.filter(x=>x.__checked);
|
||||||
if (selected_allocations.length > 0) {
|
if (selected_allocations.length > 0) {
|
||||||
// assuming each row is an individual voucher
|
let selection_map = erpnext.accounts.unreconcile_payments.build_selection_map(frm, selected_allocations);
|
||||||
// pass this to server side method that creates unreconcile doc for each row
|
erpnext.accounts.unreconcile_payments.create_unreconcile_docs(selection_map);
|
||||||
if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) {
|
d.hide();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
frappe.msgprint("No Selection");
|
frappe.msgprint("No Selection");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user