From fd8d6c62646f7c5491f469e230fa8c88afdae372 Mon Sep 17 00:00:00 2001 From: hrishikesh Date: Tue, 14 Jan 2025 17:58:55 +0530 Subject: [PATCH] feat: modify bank reco erpnext --- .../bank_reconciliation_tool_erpnext.js | 21 +++++++++--- .../bank_reconciliation_tool_erpnext.py | 34 +++++++++++++------ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.js b/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.js index 423bee1e025d..f82b55542724 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.js +++ b/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.js @@ -93,7 +93,13 @@ frappe.ui.form.on("Bank Reconciliation Tool ERPNext", { }); // frm.trigger("render_chart"); frm.trigger("get_account_opening_balance"); + frm.doc.difference_amount = (frm.doc.closing_balance_as_per_bank_statement - frm.doc.closing_balance_as_per_erp) + frm.refresh_fields(); frm.add_custom_button(__("Get Unreconciled Entries"), function () { + frm.set_value( + "difference_amount", + (frm.doc.closing_balance_as_per_bank_statement - frm.doc.closing_balance_as_per_erp) + ); frappe.call({ method: "erpnext.accounts.doctype.bank_reconciliation_tool_erpnext.bank_reconciliation_tool_erpnext.get_bank_transaction", args: { @@ -175,8 +181,14 @@ frappe.ui.form.on("Bank Reconciliation Tool ERPNext", { bnk_tr.deposit = 0; } } else if (i.doctype === "Journal Entry") { - bnk_tr.deposit = i.paid_amount; - bnk_tr.withdraw = i.paid_amount; // Confirm logic here. + if (i.bank == 'Credit'){ + bnk_tr.deposit = 0; + bnk_tr.withdraw = i.paid_amount; // Confirm logic here. + } + else if (i.bank == 'Debit'){ + bnk_tr.deposit = i.paid_amount; + bnk_tr.withdraw = 0; // Confirm logic here. + } } // Add the reference ID to the Set to track it @@ -200,7 +212,7 @@ frappe.ui.form.on("Bank Reconciliation Tool ERPNext", { method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", args: { bank_account: frm.doc.bank_account, - till_date: frappe.datetime.add_days(frm.doc.bank_statement_from_date, -1), + till_date: frappe.datetime.add_days(frm.doc.bank_statement_from_date, -1) }, callback: (response) => { frm.set_value("opening_balance", response.message); @@ -300,7 +312,6 @@ frappe.ui.form.on("Bank Reconciliation Tool ERPNext", { }, callback: () => { frm.refresh(); - frm.msgprint("Bank Transaction is Reconciled"); }, }); }, @@ -316,6 +327,8 @@ frappe.ui.form.on("Bank Reconciliation Tool ERPNext", { payment_document: i.reference_to, }, callback: function (r) { + frm.clear_table("matching_table"); + frm.refresh(); // console.log('GHJJHJHJHJBBJ') if (!r.exc) { if (r.message) { diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.py b/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.py index a72f6004294c..4014d0518a96 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool_erpnext/bank_reconciliation_tool_erpnext.py @@ -2,6 +2,7 @@ # For license information, please see license.txt import frappe +from frappe import _ from frappe.model.document import Document from frappe.utils import flt @@ -142,21 +143,33 @@ def get_erp_transaction(bank_account, company, from_statement_date=None, to_stat transaction_list = frappe.db.get_all( "Bank Transaction", {"bank_account": bank_account, "status": "Unreconciled"}, pluck="name" ) + result = [] for i in transaction_list: transaction = frappe.get_doc("Bank Transaction", i) # print("++++++++++++++++++++++++++++++++") - # print(transaction_list) + # # print(transaction_list) # print(get_linked_payments(transaction.name, document_types=["payment_entry","journal_entry"], from_date=from_statement_date, to_date=to_statement_date, filter_by_reference_date=None, from_reference_date=from_statement_date, to_reference_date=to_statement_date)) # print("++++++++++++++++++++++++++++++++") - return get_linked_payments( - transaction.name, - document_types=["payment_entry", "journal_entry"], - from_date=from_statement_date, - to_date=to_statement_date, - filter_by_reference_date=None, - from_reference_date=from_statement_date, - to_reference_date=to_statement_date, - ) + + for i in get_linked_payments(transaction.name, document_types=["payment_entry","journal_entry"], from_date=from_statement_date, to_date=to_statement_date, filter_by_reference_date=None, from_reference_date=from_statement_date, to_reference_date=to_statement_date): + if i['doctype'] == "Journal Entry": + list = frappe.db.get_all("Journal Entry Account", + { + 'account': "IDFC Bank - PP Ltd", + 'parent': i.name + }, + ['credit_in_account_currency', 'debit_in_account_currency', 'parent'] + ) + for j in list: + if j['credit_in_account_currency'] > 0: + i['bank'] = 'Credit' + elif j['debit_in_account_currency'] > 0: + i['bank'] = 'Debit' + result.append(i) + else: + result.append(i) + + return result # if from_statement_date and to_statement_date: # pe_list = frappe.db.get_all("Payment Entry",filters={'posting_date': ['between' ,[from_statement_date, to_statement_date]], 'bank_account':bank_account, 'company': company}, fields = ['posting_date', 'paid_amount', 'reference_no', 'payment_type']) # je_list = frappe.db.get_all("Journal Entry Account", filters={'bank_account': bank_account}, fields = ["parent", "account", "creation", "debit", "credit"]) @@ -178,6 +191,7 @@ def reconcile_bnk_transaction(bank_transaction_id, amount, name, payment_documen ) try: bnk_trn.save() + frappe.msgprint(_("Successfully Reconciled")) except Exception as e: frappe.msgprint("Please Reconcile again to ")