chore: fetch logic for payment entry
diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py
index c80365b..b6dd363 100644
--- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py
+++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py
@@ -82,10 +82,10 @@
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 @@
)
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 []
diff --git a/erpnext/public/js/utils/unreconcile.js b/erpnext/public/js/utils/unreconcile.js
index 509cd39..46555fe 100644
--- a/erpnext/public/js/utils/unreconcile.js
+++ b/erpnext/public/js/utils/unreconcile.js
@@ -20,6 +20,34 @@
}
},
+ 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 @@
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");