From e569e2f98c8cb011a61a0f2ae409221b07385000 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Thu, 25 Jun 2026 16:11:29 +0530 Subject: [PATCH] fix: rewrite user-facing messages in Assets module Conservative cleanup of frappe.throw/msgprint messages per the message style guide; meaning, severity, and .format() arguments are unchanged: - index bare {} placeholders as {0}/{1}/... so translators can reorder - move f-strings / .format() / concatenation out of _() (they break gettext extraction and never translate) - wrap translatable dynamic values (DocType/Select labels) in _() - fix grammar and colloquialisms - drop no-op _() wrapping runtime-built strings Part of #53976. --- erpnext/assets/doctype/asset/asset.py | 16 +++++++++------- .../asset_capitalization/asset_capitalization.py | 2 +- .../doctype/asset_category/asset_category.py | 9 +++++---- .../deppreciation_schedule_controller.py | 6 +++--- .../assets/doctype/asset_repair/asset_repair.py | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index f2a71bb5f64..c00ea2b1b3f 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -327,7 +327,7 @@ class Asset(AccountsController): reference_doc = frappe.get_doc(reference_doc, reference_name) if reference_doc.get("company") != self.company: frappe.throw( - _("Company of asset {0} and purchase document {1} doesn't matches.").format( + _("Company of asset {0} and purchase document {1} does not match.").format( self.name, reference_doc.get("name") ) ) @@ -355,7 +355,7 @@ class Asset(AccountsController): ) if cost_center_company != self.company: frappe.throw( - _("Cost Center {} doesn't belong to Company {}").format( + _("Cost Center {0} does not belong to Company {1}").format( frappe.bold(self.cost_center), frappe.bold(self.company) ), title=_("Invalid Cost Center"), @@ -363,7 +363,7 @@ class Asset(AccountsController): if cost_center_is_group: frappe.throw( _( - "Cost Center {} is a group cost center and group cost centers cannot be used in transactions" + "Cost Center {0} is a group cost center and group cost centers cannot be used in transactions" ).format(frappe.bold(self.cost_center)), title=_("Invalid Cost Center"), ) @@ -372,7 +372,7 @@ class Asset(AccountsController): if not frappe.get_cached_value("Company", self.company, "depreciation_cost_center"): frappe.throw( _( - "Please set a Cost Center for the Asset or set an Asset Depreciation Cost Center for the Company {}" + "Please set a Cost Center for the Asset or set an Asset Depreciation Cost Center for the Company {0}" ).format(frappe.bold(self.company)), title=_("Missing Cost Center"), ) @@ -410,7 +410,7 @@ class Asset(AccountsController): for d in self.finance_books: if d.finance_book in finance_books: frappe.throw( - _("Row #{}: Please use a different Finance Book.").format(d.idx), + _("Row #{0}: Please use a different Finance Book.").format(d.idx), title=_("Duplicate Finance Book"), ) else: @@ -418,7 +418,9 @@ class Asset(AccountsController): if not d.finance_book: frappe.throw( - _("Row #{}: Finance Book should not be empty since you're using multiple.").format(d.idx), + _("Row #{0}: Finance Book should not be empty since you're using multiple.").format( + d.idx + ), title=_("Missing Finance Book"), ) @@ -1190,7 +1192,7 @@ def get_values_from_purchase_doc( matching_items = [item for item in purchase_doc.items if item.item_code == item_code] if not matching_items: - frappe.throw(_(f"Selected {doctype} does not contain the Item Code {item_code}")) + frappe.throw(_("Selected {0} does not contain the Item Code {1}").format(doctype, item_code)) first_item = matching_items[0] diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index 188254929d9..973f4de833b 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -186,7 +186,7 @@ class AssetCapitalization(StockController): target_asset = self.get_asset_for_validation(self.target_asset) if not target_asset.asset_type == "Composite Asset": - frappe.throw(_("Target Asset {0} needs to be composite asset").format(target_asset.name)) + frappe.throw(_("Target Asset {0} needs to be a composite asset").format(target_asset.name)) if target_asset.item_code != self.target_item_code: frappe.throw( diff --git a/erpnext/assets/doctype/asset_category/asset_category.py b/erpnext/assets/doctype/asset_category/asset_category.py index 7c0e0a50dad..5f936c35efc 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.py +++ b/erpnext/assets/doctype/asset_category/asset_category.py @@ -63,7 +63,7 @@ class AssetCategory(Document): for d in invalid_accounts: frappe.throw( - _("Row #{}: Currency of {} - {} doesn't matches company currency.").format( + _("Row #{0}: Currency of {1} - {2} does not match company currency.").format( d.idx, frappe.bold(frappe.unscrub(d.type)), frappe.bold(d.account) ), title=_("Invalid Account"), @@ -117,10 +117,11 @@ class AssetCategory(Document): missing_cwip_accounts_for_company.append(get_link_to_form("Company", d.company_name)) if missing_cwip_accounts_for_company: - msg = _("""To enable Capital Work in Progress Accounting,""") + " " - msg += _("""you must select Capital Work in Progress Account in accounts table""") + msg = _( + "To enable Capital Work in Progress Accounting, you must select Capital Work in Progress Account in accounts table" + ) msg += "

" - msg += _("You can also set default CWIP account in Company {}").format( + msg += _("You can also set default CWIP account in Company {0}").format( ", ".join(missing_cwip_accounts_for_company) ) frappe.throw(msg, title=_("Missing Account")) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/deppreciation_schedule_controller.py b/erpnext/assets/doctype/asset_depreciation_schedule/deppreciation_schedule_controller.py index f1be90edc46..60db6140ed9 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/deppreciation_schedule_controller.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/deppreciation_schedule_controller.py @@ -173,9 +173,9 @@ class DepreciationScheduleController(StraightLineMethod, WDVMethod): if days <= 0: frappe.throw( _( - """Error: This asset already has {0} depreciation periods booked. - The `depreciation start` date must be at least {1} periods after the `available for use` date. - Please correct the dates accordingly.""" + "Error: This asset already has {0} depreciation periods booked. " + "The `depreciation start` date must be at least {1} periods after the `available for use` date. " + "Please correct the dates accordingly." ).format( self.asset_doc.opening_number_of_booked_depreciations, self.asset_doc.opening_number_of_booked_depreciations, diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 69e9014c90b..e8b2f165c1f 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -293,8 +293,8 @@ class AssetRepair(AccountsController): if not stock_item.serial_and_batch_bundle and frappe.get_cached_value( "Item", stock_item.item_code, "has_serial_no" ): - msg = f"Serial No Bundle is mandatory for Item {stock_item.item_code}" - frappe.throw(_(msg), title=_("Missing Serial No Bundle")) + msg = _("Serial No Bundle is mandatory for Item {0}").format(stock_item.item_code) + frappe.throw(msg, title=_("Missing Serial No Bundle")) if stock_item.serial_and_batch_bundle: values_to_update = {