From 31561c3f9abc49731ae87dca0b0340b55fdd658e Mon Sep 17 00:00:00 2001 From: Frappe PR Bot Date: Thu, 26 Aug 2021 19:57:56 +0530 Subject: [PATCH] fix: cannot reconcile bank transactions against internal transfer payment entries (#27148) * fix: cannot reconcile bank transactions against internal transfer payment entries (#26932) * fix: Only set Clearance Date for Payment Entries of type Internal Transfer if both Transactions have been reconciled * fix: Reset clearance_date for intra-company Payment Entries that have only been reconciled with one Bank Transaction * fix: indentation and args Co-authored-by: Saqib Co-authored-by: Nabin Hait (cherry picked from commit 842ceb1301c60f4442313c3c266d4fc194f5172c) # Conflicts: # erpnext/patches.txt * fix: merge conflict * fixed patches Co-authored-by: Ganga Manoj Co-authored-by: Nabin Hait --- .../bank_transaction/bank_transaction.py | 16 +++++++ erpnext/patches.txt | 1 + ...e_date_for_intracompany_payment_entries.py | 45 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 erpnext/patches/v13_0/reset_clearance_date_for_intracompany_payment_entries.py diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index 0544a469d60..7ea71fc103a 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -55,6 +55,11 @@ class BankTransaction(StatusUpdater): self.clear_sales_invoice(payment_entry, for_cancel=for_cancel) def clear_simple_entry(self, payment_entry, for_cancel=False): + if payment_entry.payment_document == "Payment Entry": + if frappe.db.get_value("Payment Entry", payment_entry.payment_entry, "payment_type") == "Internal Transfer": + if len(get_reconciled_bank_transactions(payment_entry)) < 2: + return + clearance_date = self.date if not for_cancel else None frappe.db.set_value( payment_entry.payment_document, payment_entry.payment_entry, @@ -70,6 +75,17 @@ class BankTransaction(StatusUpdater): ), "clearance_date", clearance_date) +def get_reconciled_bank_transactions(payment_entry): + reconciled_bank_transactions = frappe.get_all( + 'Bank Transaction Payments', + filters = { + 'payment_entry': payment_entry.payment_entry + }, + fields = ['parent'] + ) + + return reconciled_bank_transactions + def get_total_allocated_amount(payment_entry): return frappe.db.sql(""" SELECT diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 86bd65a82ea..760211ecffd 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -303,3 +303,4 @@ erpnext.patches.v13_0.update_recipient_email_digest erpnext.patches.v13_0.shopify_deprecation_warning erpnext.patches.v13_0.add_custom_field_for_south_africa #2 erpnext.patches.v13_0.rename_discharge_ordered_date_in_ip_record +erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries diff --git a/erpnext/patches/v13_0/reset_clearance_date_for_intracompany_payment_entries.py b/erpnext/patches/v13_0/reset_clearance_date_for_intracompany_payment_entries.py new file mode 100644 index 00000000000..1da5275761b --- /dev/null +++ b/erpnext/patches/v13_0/reset_clearance_date_for_intracompany_payment_entries.py @@ -0,0 +1,45 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals + +import frappe + +def execute(): + """ + Reset Clearance Date for Payment Entries of type Internal Transfer that have only been reconciled with one Bank Transaction. + This will allow the Payment Entries to be reconciled with the second Bank Transaction using the Bank Reconciliation Tool. + """ + + intra_company_pe = get_intra_company_payment_entries_with_clearance_dates() + reconciled_bank_transactions = get_reconciled_bank_transactions(intra_company_pe) + + for payment_entry in reconciled_bank_transactions: + if len(reconciled_bank_transactions[payment_entry]) == 1: + frappe.db.set_value('Payment Entry', payment_entry, 'clearance_date', None) + +def get_intra_company_payment_entries_with_clearance_dates(): + return frappe.get_all( + 'Payment Entry', + filters = { + 'payment_type': 'Internal Transfer', + 'clearance_date': ["not in", None] + }, + pluck = 'name' + ) + +def get_reconciled_bank_transactions(intra_company_pe): + """Returns dictionary where each key:value pair is Payment Entry : List of Bank Transactions reconciled with Payment Entry""" + + reconciled_bank_transactions = {} + + for payment_entry in intra_company_pe: + reconciled_bank_transactions[payment_entry] = frappe.get_all( + 'Bank Transaction Payments', + filters = { + 'payment_entry': payment_entry + }, + pluck='parent' + ) + + return reconciled_bank_transactions \ No newline at end of file