diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 4bbb3e9e70..2828d7788b 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -528,3 +528,4 @@ erpnext.patches.v11_0.create_salary_structure_assignments erpnext.patches.v11_0.rename_health_insurance erpnext.patches.v11_0.rebuild_tree_for_company erpnext.patches.v11_0.create_department_records_for_each_company +erpnext.patches.v11_0.make_location_from_warehouse \ No newline at end of file diff --git a/erpnext/patches/v11_0/make_location_from_warehouse.py b/erpnext/patches/v11_0/make_location_from_warehouse.py new file mode 100644 index 0000000000..a3c66635b2 --- /dev/null +++ b/erpnext/patches/v11_0/make_location_from_warehouse.py @@ -0,0 +1,27 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc('assets', 'doctype', 'location') + frappe.reload_doc('stock', 'doctype', 'warehouse') + + for d in frappe.get_all('Warehouse', + fields = ['warehouse_name', 'is_group', 'parent_warehouse'], order_by="is_group desc"): + try: + loc = frappe.new_doc('Location') + loc.location_name = d.warehouse_name + loc.is_group = d.is_group + loc.flags.ignore_mandatory = True + if d.parent_warehouse: + loc.parent_location = get_parent_warehouse_name(d.parent_warehouse) + + loc.save(ignore_permissions=True) + except frappe.DuplicateEntryError: + continue + +def get_parent_warehouse_name(warehouse): + return frappe.db.get_value('Warehouse', warehouse, 'warehouse_name') + \ No newline at end of file