From 4912288433b70605ae581475cc5fea72ac978dc0 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:18:51 +0100 Subject: [PATCH] fix: translate display text passed to validate_expense_account (#43057) --- .../purchase_invoice/purchase_invoice.py | 2 +- .../doctype/sales_invoice/sales_invoice.py | 2 +- .../sales_taxes_and_charges_template.py | 2 +- erpnext/accounts/party.py | 6 ++++-- erpnext/controllers/accounts_controller.py | 18 +++++++++--------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 46350105a36..d7763bee254 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -591,7 +591,7 @@ class PurchaseInvoice(BuyingController): def validate_expense_account(self): for item in self.get("items"): - validate_account_head(item.idx, item.expense_account, self.company, "Expense") + validate_account_head(item.idx, item.expense_account, self.company, _("Expense")) def set_against_expense_account(self, force=False): against_accounts = [] diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index dcc2b2d5e4c..69735c37b42 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -376,7 +376,7 @@ class SalesInvoice(SellingController): def validate_income_account(self): for item in self.get("items"): - validate_account_head(item.idx, item.income_account, self.company, "Income") + validate_account_head(item.idx, item.income_account, self.company, _("Income")) def set_tax_withholding(self): if self.get("is_opening") == "Yes": diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py index e0b4258b249..907b4cc6b19 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py @@ -69,7 +69,7 @@ def valdiate_taxes_and_charges_template(doc): for tax in doc.get("taxes"): validate_taxes_and_charges(tax) - validate_account_head(tax.idx, tax.account_head, doc.company) + validate_account_head(tax.idx, tax.account_head, doc.company, _("Taxes and Charges")) validate_cost_center(tax, doc) validate_inclusive_tax(tax, doc) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 052e634a1b4..f052a851364 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -563,9 +563,11 @@ def validate_party_accounts(doc): # validate if account is mapped for same company if account.account: - validate_account_head(account.idx, account.account, account.company) + validate_account_head(account.idx, account.account, account.company, _("Debtor/Creditor")) if account.advance_account: - validate_account_head(account.idx, account.advance_account, account.company) + validate_account_head( + account.idx, account.advance_account, account.company, _("Debtor/Creditor Advance") + ) @frappe.whitelist() diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index fee0827287d..30ebc1794fe 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2643,21 +2643,21 @@ def validate_taxes_and_charges(tax): tax.rate = None -def validate_account_head(idx, account, company, context=""): - account_company = frappe.get_cached_value("Account", account, "company") - is_group = frappe.get_cached_value("Account", account, "is_group") - - if account_company != company: +def validate_account_head(idx: int, account: str, company: str, context: str | None = None) -> None: + """Throw a ValidationError if the account belongs to a different company or is a group account.""" + if company != frappe.get_cached_value("Account", account, "company"): frappe.throw( - _("Row {0}: {3} Account {1} does not belong to Company {2}").format( - idx, frappe.bold(account), frappe.bold(company), context + _("Row {0}: The {3} Account {1} does not belong to the company {2}").format( + idx, frappe.bold(account), frappe.bold(company), context or "" ), title=_("Invalid Account"), ) - if is_group: + if frappe.get_cached_value("Account", account, "is_group"): frappe.throw( - _("Row {0}: Account {1} is a Group Account").format(idx, frappe.bold(account)), + _( + "You selected the account group {1} as {2} Account in row {0}. Please select a single account." + ).format(idx, frappe.bold(account), context or ""), title=_("Invalid Account"), )