From a8e24cba46f18ac5789f08c3963d9938d3cd88dd Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 19 Jul 2018 14:33:31 +0530 Subject: [PATCH] Merge patch and delete fields from subscription (#14941) * Delete subscription records after migrating all records to auto-repeat * delete old fields from subscription --- erpnext/patches.txt | 1 - .../v10_1/drop_old_subscription_records.py | 6 --- .../transfer_subscription_to_auto_repeat.py | 46 ++++++++++++------- 3 files changed, 29 insertions(+), 24 deletions(-) delete mode 100644 erpnext/patches/v10_1/drop_old_subscription_records.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a9958cb988..20def27ced 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -524,7 +524,6 @@ erpnext.patches.v11_0.uom_conversion_data #30-06-2018 erpnext.patches.v10_0.taxes_issue_with_pos erpnext.patches.v11_0.update_account_type_in_party_type erpnext.patches.v10_1.transfer_subscription_to_auto_repeat -erpnext.patches.v10_1.drop_old_subscription_records erpnext.patches.v11_0.update_brand_in_item_price erpnext.patches.v11_0.create_default_success_action erpnext.patches.v11_0.add_healthcare_service_unit_tree_root diff --git a/erpnext/patches/v10_1/drop_old_subscription_records.py b/erpnext/patches/v10_1/drop_old_subscription_records.py deleted file mode 100644 index 7573f1568f..0000000000 --- a/erpnext/patches/v10_1/drop_old_subscription_records.py +++ /dev/null @@ -1,6 +0,0 @@ -from __future__ import unicode_literals -import frappe - - -def execute(): - frappe.db.sql('DELETE from `tabSubscription`') diff --git a/erpnext/patches/v10_1/transfer_subscription_to_auto_repeat.py b/erpnext/patches/v10_1/transfer_subscription_to_auto_repeat.py index a9078e305c..5c18985f7f 100644 --- a/erpnext/patches/v10_1/transfer_subscription_to_auto_repeat.py +++ b/erpnext/patches/v10_1/transfer_subscription_to_auto_repeat.py @@ -4,25 +4,21 @@ from frappe.model.utils.rename_field import rename_field def execute(): - to_rename = ['Purchase Order', 'Journal Entry', 'Sales Invoice', 'Payment Entry', - 'Delivery Note', 'Purchase Invoice', 'Quotation', 'Sales Order', - 'Purchase Receipt', 'Supplier Quotation'] - - frappe.reload_doc('accounts', 'doctype', 'sales_invoice') - frappe.reload_doc('accounts', 'doctype', 'purchase_invoice') - frappe.reload_doc('accounts', 'doctype', 'payment_entry') - frappe.reload_doc('accounts', 'doctype', 'journal_entry') - frappe.reload_doc('buying', 'doctype', 'purchase_order') - frappe.reload_doc('buying', 'doctype', 'supplier_quotation') frappe.reload_doc('desk', 'doctype', 'auto_repeat') - frappe.reload_doc('selling', 'doctype', 'quotation') - frappe.reload_doc('selling', 'doctype', 'sales_order') - frappe.reload_doc('stock', 'doctype', 'purchase_receipt') - frappe.reload_doc('stock', 'doctype', 'delivery_note') - for doctype in to_rename: - if frappe.db.has_column(doctype, 'subscription'): - rename_field(doctype, 'subscription', 'auto_repeat') + doctypes_to_rename = { + 'accounts': ['Journal Entry', 'Payment Entry', 'Purchase Invoice', 'Sales Invoice'], + 'buying': ['Purchase Order', 'Supplier Quotation'], + 'selling': ['Quotation', 'Sales Order'], + 'stock': ['Delivery Note', 'Purchase Receipt'] + } + + for module, doctypes in doctypes_to_rename.items(): + for doctype in doctypes: + frappe.reload_doc(module, 'doctype', frappe.scrub(doctype)) + + if frappe.db.has_column(doctype, 'subscription'): + rename_field(doctype, 'subscription', 'auto_repeat') subscriptions = frappe.db.sql('select * from `tabSubscription`', as_dict=1) @@ -30,3 +26,19 @@ def execute(): doc['doctype'] = 'Auto Repeat' auto_repeat = frappe.get_doc(doc) auto_repeat.db_insert() + + frappe.db.sql('delete from `tabSubscription`') + frappe.db.commit() + drop_columns_from_subscription() + +def drop_columns_from_subscription(): + fields_to_drop = {'Subscription': []} + for field in ['naming_series', 'reference_doctype', 'reference_document', 'start_date', + 'end_date', 'submit_on_creation', 'disabled', 'frequency', 'repeat_on_day', + 'next_schedule_date', 'notify_by_email', 'subject', 'recipients', 'print_format', + 'message', 'status', 'amended_from']: + + if field in frappe.db.get_table_columns("Subscription"): + fields_to_drop['Subscription'].append(field) + + frappe.model.delete_fields(fields_to_drop, delete=1) \ No newline at end of file