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 <pratheeps2024@gmail.com>

* fix(coa_importer): check permissions in `unset_existing_data`

---------

Co-authored-by: Pratheep S <pratheeps2024@gmail.com>
(cherry picked from commit 8c1a1aafe6)

# Conflicts:
#	erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py
This commit is contained in:
Diptanil Saha
2026-06-19 15:08:20 +05:30
committed by Mergify
parent 6c37acc180
commit a1570bd80d

View File

@@ -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):