mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix(accounts): preserve links when replacing chart of accounts
This commit is contained in:
@@ -475,22 +475,19 @@ def unset_existing_data(company):
|
||||
# remove accounts data from 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, dict.fromkeys(fieldnames, ""))
|
||||
|
||||
frappe.db.set_value("Company", company, update_values, update_values)
|
||||
# import_coa authorizes company replacement; Accounts Manager cannot delete purchase templates.
|
||||
for doctype in ("Sales Taxes and Charges Template", "Purchase Taxes and Charges Template"):
|
||||
for name in frappe.get_all(doctype, filters={"company": company}, pluck="name"):
|
||||
frappe.delete_doc(doctype, name, ignore_permissions=True)
|
||||
|
||||
# remove accounts data from various doctypes
|
||||
for doctype in [
|
||||
"Account",
|
||||
"Party Account",
|
||||
"Mode of Payment Account",
|
||||
"Tax Withholding Account",
|
||||
"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()
|
||||
for doctype in ("Party Account", "Mode of Payment Account", "Tax Withholding Account"):
|
||||
frappe.db.delete(doctype, {"company": company})
|
||||
|
||||
# Delete children before their parents, preserving link checks and account validation.
|
||||
for name in frappe.get_all("Account", filters={"company": company}, order_by="lft desc", pluck="name"):
|
||||
frappe.delete_doc("Account", name)
|
||||
|
||||
|
||||
def validate_user_perms(company):
|
||||
|
||||
Reference in New Issue
Block a user