# Copyright(c) 2020, SolutionERP LLC Pvt.Ltd.and Contributors
# License: GNU General Public License v3.See license.txt


import xhiveframework


def execute():
	xhiveframework.reload_doc("stock", "doctype", "stock_entry")
	if xhiveframework.db.has_column("Stock Entry", "add_to_transit"):
		xhiveframework.db.sql(
			"""
            UPDATE `tabStock Entry` SET
            stock_entry_type = 'Material Transfer',
            purpose = 'Material Transfer',
            add_to_transit = 1 WHERE stock_entry_type = 'Send to Warehouse'
            """
		)

		xhiveframework.db.sql(
			"""UPDATE `tabStock Entry` SET
            stock_entry_type = 'Material Transfer',
            purpose = 'Material Transfer'
            WHERE stock_entry_type = 'Receive at Warehouse'
            """
		)

		xhiveframework.reload_doc("stock", "doctype", "warehouse_type")
		if not xhiveframework.db.exists("Warehouse Type", "Transit"):
			doc = xhiveframework.new_doc("Warehouse Type")
			doc.name = "Transit"
			doc.insert()

		xhiveframework.reload_doc("stock", "doctype", "stock_entry_type")
		xhiveframework.delete_doc_if_exists("Stock Entry Type", "Send to Warehouse")
		xhiveframework.delete_doc_if_exists("Stock Entry Type", "Receive at Warehouse")
