From a1570bd80d0b97397bac9bff799beecf943aed1d Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Fri, 19 Jun 2026 15:08:20 +0530 Subject: [PATCH] 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 --- .../chart_of_accounts_importer.py | 11 +++++++++-- 1 file changed, 9 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..e9b2744e3ce 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 @@ -74,8 +74,15 @@ def validate_company(company): @frappe.whitelist() +<<<<<<< HEAD def import_coa(file_name, company): +======= +def import_coa(file_name: str, company: str): + frappe.only_for("Accounts Manager") + +>>>>>>> 8c1a1aafe6 (fix(coa_importer): allow importing COA through `import_coa` only for `Accounts Manager` (#56132)) # delete existing data for accounts + frappe.has_permission("Company", "write", company, throw=True) unset_existing_data(company) # create accounts @@ -451,6 +458,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 +470,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):