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


import influxframework


def execute():
	influxframework.reload_doc("stock", "doctype", "stock_entry")
	if influxframework.db.has_column("Stock Entry", "add_to_transit"):
		influxframework.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'
            """
		)

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

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

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