brotherton-erpnext/erpnext/patches/v11_0/make_location_from_warehouse.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

33 lines
1.0 KiB
Python

# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils.nestedset import rebuild_tree
def execute():
if not frappe.db.get_value('Asset', {'docstatus': ('<', 2) }, 'name'): return
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="lft asc"):
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
rebuild_tree("Location", "parent_location")
def get_parent_warehouse_name(warehouse):
return frappe.db.get_value('Warehouse', warehouse, 'warehouse_name')