From a36be35c47caf792b37f30f51eff534880c1bd5d Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:44:28 +0200 Subject: [PATCH] refactor: validate_return_against_account (#43778) --- erpnext/controllers/accounts_controller.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 634ae933a8e..2c96d4ac398 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -354,12 +354,17 @@ class AccountsController(TransactionBase): self.doctype in ["Sales Invoice", "Purchase Invoice"] and self.is_return and self.return_against ): cr_dr_account_field = "debit_to" if self.doctype == "Sales Invoice" else "credit_to" - cr_dr_account_label = "Debit To" if self.doctype == "Sales Invoice" else "Credit To" + cr_dr_account_label = self.meta.get_label(cr_dr_account_field) cr_dr_account = self.get(cr_dr_account_field) - if frappe.get_value(self.doctype, self.return_against, cr_dr_account_field) != cr_dr_account: + original_account = frappe.get_value(self.doctype, self.return_against, cr_dr_account_field) + if original_account != cr_dr_account: frappe.throw( - _("'{0}' account: '{1}' should match the Return Against Invoice").format( - frappe.bold(cr_dr_account_label), frappe.bold(cr_dr_account) + _( + "Please set {0} to {1}, the same account that was used in the original invoice {2}." + ).format( + frappe.bold(_(cr_dr_account_label, context=self.doctype)), + frappe.bold(cr_dr_account), + frappe.bold(self.return_against), ) ) -- GitLab