2018-05-12 06:59:04 +00:00
|
|
|
# Copyright (c) 2017, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-05-12 06:59:04 +00:00
|
|
|
import frappe
|
2018-05-12 09:35:09 +00:00
|
|
|
from frappe.utils.nestedset import rebuild_tree
|
2018-05-12 06:59:04 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-05-12 06:59:04 +00:00
|
|
|
def execute():
|
2018-10-07 07:38:00 +00:00
|
|
|
if not frappe.db.get_value("Asset", {"docstatus": ("<", 2)}, "name"):
|
|
|
|
return
|
2018-05-12 06:59:04 +00:00
|
|
|
frappe.reload_doc("assets", "doctype", "location")
|
|
|
|
frappe.reload_doc("stock", "doctype", "warehouse")
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2018-05-12 06:59:04 +00:00
|
|
|
for d in frappe.get_all(
|
2018-05-21 11:13:50 +00:00
|
|
|
"Warehouse", fields=["warehouse_name", "is_group", "parent_warehouse"], order_by="lft asc"
|
|
|
|
):
|
2018-05-12 06:59:04 +00:00
|
|
|
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
|
|
|
|
|
2018-05-12 09:35:09 +00:00
|
|
|
rebuild_tree("Location", "parent_location")
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2018-05-12 06:59:04 +00:00
|
|
|
def get_parent_warehouse_name(warehouse):
|
|
|
|
return frappe.db.get_value("Warehouse", warehouse, "warehouse_name")
|