From 285963acdba73bfdb0f9e5d7f4fac3d765b282d6 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 30 Aug 2023 10:43:00 +0530 Subject: [PATCH] feat: unreconcile support for journal entry --- .../unreconcile_payments.js | 2 +- .../unreconcile_payments.py | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.js b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.js index ef7c958113..c522567637 100644 --- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.js +++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.js @@ -6,7 +6,7 @@ frappe.ui.form.on("Unreconcile Payments", { frm.set_query("voucher_type", function() { return { filters: { - name: "Payment Entry" + name: ["in", ["Payment Entry", "Journal Entry"]] } } }); diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py index 8aef772ad5..a32313f4a5 100644 --- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py +++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py @@ -2,15 +2,21 @@ # For license information, please see license.txt import frappe -from frappe import qb +from frappe import _, qb from frappe.model.document import Document from frappe.query_builder import Criterion from frappe.query_builder.functions import Abs, Sum +from frappe.utils.data import comma_and from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries, update_voucher_outstanding class UnreconcilePayments(Document): + def validate(self): + self.supported_types = ["Payment Entry", "Journal Entry"] + if not self.voucher_type in self.supported_types: + frappe.throw(_("Only {0} are supported").format(comma_and(self.supported_types))) + @frappe.whitelist() def get_allocations_from_payment(self): allocated_references = [] @@ -26,14 +32,24 @@ class UnreconcilePayments(Document): .run(as_dict=True) ) elif self.voucher_type == "Journal Entry": - jea = qb.DocType("Journal Entry Account") + # for journals, using payment ledger to fetch allocation. + # this way we can avoid vaildating account type and reference details individually on child table + + ple = qb.DocType("Payment Ledger Entry") allocated_references = ( - qb.from_(jea) + qb.from_(ple) .select( - jea.reference_type, jea.reference_name, Sum(jea.allocated_amount).as_("allocated_amount") + ple.against_voucher_type.as_("reference_doctype"), + ple.against_voucher_no.as_("reference_name"), + Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"), ) - .where((jea.docstatus == 1) & (jea.parent == self.voucher_no)) - .groupby(jea.reference_name) + .where( + (ple.docstatus == 1) + & (ple.voucher_type == self.voucher_type) + & (ple.voucher_no == self.voucher_no) + & (ple.voucher_no != ple.against_voucher_no) + ) + .groupby(ple.against_voucher_type, ple.against_voucher_no) .run(as_dict=True) )