From c98f37f91cab52b4deb0274dfc38552e8d2d8f61 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 25 Apr 2017 17:43:04 +0530 Subject: [PATCH] Patch for reverting manufacturers table from item --- erpnext/patches.txt | 1 + .../v8_0/manufacturer_childtable_migrate.py | 24 ------------------- .../revert_manufacturers_table_from_item.py | 22 +++++++++++++++++ 3 files changed, 23 insertions(+), 24 deletions(-) delete mode 100644 erpnext/patches/v8_0/manufacturer_childtable_migrate.py create mode 100644 erpnext/patches/v8_0/revert_manufacturers_table_from_item.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c396402c80f..773583e37ce 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -390,3 +390,4 @@ erpnext.patches.v8_0.enable_booking_asset_depreciation_automatically erpnext.patches.v8_0.set_project_copied_from erpnext.patches.v8_0.update_status_as_paid_for_completed_expense_claim erpnext.patches.v7_2.stock_uom_in_selling +erpnext.patches.v8_0.revert_manufacturers_table_from_item \ No newline at end of file diff --git a/erpnext/patches/v8_0/manufacturer_childtable_migrate.py b/erpnext/patches/v8_0/manufacturer_childtable_migrate.py deleted file mode 100644 index 87a34315784..00000000000 --- a/erpnext/patches/v8_0/manufacturer_childtable_migrate.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2017, Frappe and Contributors -# License: GNU General Public License v3. See license.txt - -from __future__ import unicode_literals -import frappe - -def execute(): - - # reading from json and writing it to mariadb - # reload_doc needed here with information because new table introduced - frappe.reload_doc('stock', 'doctype', 'item_manufacturer') - # reload_doctype is a simpler concept of reload_doc - frappe.reload_doctype('Item') - - item_manufacturers = frappe.get_all("Item", fields=["name", "manufacturer", "manufacturer_part_no"]) - for item in item_manufacturers: - if item.manufacturer or item.manufacturer_part_no: - item_doc = frappe.get_doc("Item", item.name) - item_doc.append("manufacturers", { - "manufacturer": item.manufacturer, - "manufacturer_part_no": item.manufacturer_part_no - }) - - item_doc.get("manufacturers")[0].db_update() \ No newline at end of file diff --git a/erpnext/patches/v8_0/revert_manufacturers_table_from_item.py b/erpnext/patches/v8_0/revert_manufacturers_table_from_item.py new file mode 100644 index 00000000000..60cbb33b80b --- /dev/null +++ b/erpnext/patches/v8_0/revert_manufacturers_table_from_item.py @@ -0,0 +1,22 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + if frappe.db.exists("DocType", "Item Manufacturer"): + frappe.reload_doctype("Item") + item_manufacturers = frappe.db.sql(""" + select parent, manufacturer, manufacturer_part_no + from `tabItem Manufacturer` + """, as_dict=1) + + for im in item_manufacturers: + frappe.db.sql(""" + update tabItem + set manufacturer=%s, manufacturer_part_no=%s + where name=%s + """, (im.manufacturer, im.manufacturer_part_no, im.parent)) + + frappe.delete_doc("DocType", "Item Manufacturer") \ No newline at end of file