diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 1ba752a1464..7e0e70924fd 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -300,6 +300,9 @@ doc_events = { }, ('Quotation', 'Sales Order', 'Sales Invoice'): { 'validate': ["erpnext.erpnext_integrations.taxjar_integration.set_sales_tax"] + }, + "Company": { + "on_trash": "erpnext.regional.india.utils.delete_gst_settings_for_company" } } diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index a4466e78f28..62c0187268b 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -849,4 +849,17 @@ def get_depreciation_amount(asset, depreciable_value, row): depreciation_amount = flt(depreciable_value * (flt(rate_of_depreciation) / 100)) - return depreciation_amount \ No newline at end of file + return depreciation_amount + +def delete_gst_settings_for_company(doc, method): + if doc.country != 'India': + return + + gst_settings = frappe.get_doc("GST Settings") + + for d in reversed(gst_settings.get('gst_accounts')): + if d.company == doc.name: + gst_settings.remove(d) + + gst_settings.save() + diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 8755125c810..34ee1a50f9f 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -393,6 +393,10 @@ class Company(NestedSet): frappe.db.sql("delete from `tabPurchase Taxes and Charges Template` where company=%s", self.name) frappe.db.sql("delete from `tabItem Tax Template` where company=%s", self.name) + # delete Process Deferred Accounts if no GL Entry found + if not frappe.db.get_value('GL Entry', {'company': self.name}): + frappe.db.sql("delete from `tabProcess Deferred Accounting` where company=%s", self.name) + @frappe.whitelist() def enqueue_replace_abbr(company, old, new): kwargs = dict(queue="long", company=company, old=old, new=new)