From bc9006ff3058cf64f6856613b6bea338c0df76e4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 18 Sep 2017 13:16:04 +0530 Subject: [PATCH] Delete GST related doctypes and reports if account is from outside India (#10808) --- erpnext/patches.txt | 3 ++- erpnext/patches/v8_1/setup_gst_india.py | 18 +++++++++++------- ..._gst_doctypes_for_outside_india_accounts.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 erpnext/patches/v8_9/delete_gst_doctypes_for_outside_india_accounts.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5bfd34e8695..74bd37a39cb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -436,4 +436,5 @@ erpnext.patches.v8_7.add_more_gst_fields erpnext.patches.v8_7.fix_purchase_receipt_status erpnext.patches.v8_6.rename_bom_update_tool erpnext.patches.v8_9.set_print_zero_amount_taxes -erpnext.patches.v8_9.set_default_customer_group \ No newline at end of file +erpnext.patches.v8_9.set_default_customer_group +erpnext.patches.v8_9.delete_gst_doctypes_for_outside_india_accounts \ No newline at end of file diff --git a/erpnext/patches/v8_1/setup_gst_india.py b/erpnext/patches/v8_1/setup_gst_india.py index 566069369c5..f329916ed50 100644 --- a/erpnext/patches/v8_1/setup_gst_india.py +++ b/erpnext/patches/v8_1/setup_gst_india.py @@ -2,21 +2,25 @@ import frappe from frappe.email import sendmail_to_system_managers def execute(): - frappe.reload_doc('regional', 'doctype', 'gst_settings') - frappe.reload_doc('regional', 'doctype', 'gst_hsn_code') frappe.reload_doc('stock', 'doctype', 'item') frappe.reload_doc("stock", "doctype", "customs_tariff_number") + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + frappe.reload_doc('regional', 'doctype', 'gst_settings') + frappe.reload_doc('regional', 'doctype', 'gst_hsn_code') + for report_name in ('GST Sales Register', 'GST Purchase Register', 'GST Itemised Sales Register', 'GST Itemised Purchase Register'): frappe.reload_doc('regional', 'report', frappe.scrub(report_name)) - if frappe.db.get_single_value('System Settings', 'country')=='India': - from erpnext.regional.india.setup import setup - delete_custom_field_tax_id_if_exists() - setup(patch=True) - send_gst_update_email() + from erpnext.regional.india.setup import setup + delete_custom_field_tax_id_if_exists() + setup(patch=True) + send_gst_update_email() def delete_custom_field_tax_id_if_exists(): for field in frappe.db.sql_list("""select name from `tabCustom Field` where fieldname='tax_id' diff --git a/erpnext/patches/v8_9/delete_gst_doctypes_for_outside_india_accounts.py b/erpnext/patches/v8_9/delete_gst_doctypes_for_outside_india_accounts.py new file mode 100644 index 00000000000..2b4ac58a67c --- /dev/null +++ b/erpnext/patches/v8_9/delete_gst_doctypes_for_outside_india_accounts.py @@ -0,0 +1,13 @@ +import frappe + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + if frappe.db.exists("DocType", "GST Settings"): + frappe.delete_doc("DocType", "GST Settings") + frappe.delete_doc("DocType", "GST HSN Code") + + for report_name in ('GST Sales Register', 'GST Purchase Register', + 'GST Itemised Sales Register', 'GST Itemised Purchase Register'): + + frappe.delete_doc('Report', report_name) \ No newline at end of file