From e6e5591088b646d70f72beb0dda324c7ab9ff8fb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2026 22:16:16 +0530 Subject: [PATCH] fix(coa_importer): allow importing COA through `import_coa` only for `Accounts Manager` (backport #56132) (#56140) * fix(coa_importer): allow importing COA through `import_coa` only for `Accounts Manager` (#56132) * fix(coa_importer): allow importing COA only for `Accounts Manager` Co-authored-by: Pratheep S * fix(coa_importer): check permissions in `unset_existing_data` --------- Co-authored-by: Pratheep S (cherry picked from commit 8c1a1aafe670f9b84bad518a6d3db2b7d4aad612) # Conflicts: # erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py * chore: resolve conflicts --------- Co-authored-by: Diptanil Saha --- .../chart_of_accounts_importer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py index 9c4f2f8fd49..b25d7f962c0 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py @@ -75,7 +75,10 @@ def validate_company(company): @frappe.whitelist() def import_coa(file_name, company): + frappe.only_for("Accounts Manager") + # delete existing data for accounts + frappe.has_permission("Company", "write", company, throw=True) unset_existing_data(company) # create accounts @@ -451,6 +454,7 @@ def unset_existing_data(company): fieldnames = get_linked_fields("Account").get("Company", {}).get("fieldname", []) linked = [{"fieldname": name} for name in fieldnames] update_values = {d.get("fieldname"): "" for d in linked} + frappe.db.set_value("Company", company, update_values, update_values) # remove accounts data from various doctypes @@ -462,8 +466,7 @@ def unset_existing_data(company): "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template", ]: - dt = frappe.qb.DocType(doctype) - frappe.qb.from_(dt).where(dt.company == company).delete().run() + frappe.get_query(doctype, delete=True, filters={"company": company}, ignore_permissions=False).run() def set_default_accounts(company):