Merge pull request #6447 from nabinhait/patch_fix_legacy_migration

Patch fixed for legacy migration
diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py
index 529401c..2488dd6 100644
--- a/erpnext/accounts/doctype/budget/budget.py
+++ b/erpnext/accounts/doctype/budget/budget.py
@@ -51,6 +51,9 @@
 
 def validate_expense_against_budget(args):
 	args = frappe._dict(args)
+	if not args.cost_center:
+		return
+		
 	if frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"}):
 		cc_lft, cc_rgt = frappe.db.get_value("Cost Center", args.cost_center, ["lft", "rgt"])
 
diff --git a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py
index 52433a5..40423c8 100644
--- a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py
+++ b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py
@@ -27,6 +27,7 @@
 		time_sheet.update_cost()
 		time_sheet.calculate_total_amounts()
 		time_sheet.flags.ignore_validate = True
+		time_sheet.flags.ignore_links = True
 		time_sheet.save(ignore_permissions=True)
 
 		# To ignore validate_mandatory_fields function
diff --git a/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py b/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py
index 0eff8d4..a7cb0d7 100644
--- a/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py
+++ b/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py
@@ -17,10 +17,10 @@
 			add_timesheet_detail(time_sheet, args)
 
 		time_sheet.docstatus = tlb.docstatus
+		time_sheet.flags.ignore_links = True
 		time_sheet.save(ignore_permissions=True)
 
 def get_timesheet_data(data):
-	time_log = frappe.get_all('Time Log', fields=["*"],
-		filters = {'name': data.time_log})[0]
-
-	return get_timelog_data(time_log)
\ No newline at end of file
+	time_log = frappe.get_all('Time Log', fields=["*"], filters = {'name': data.time_log})
+	if time_log:
+		return get_timelog_data(time_log[0])
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/move_timelogbatch_from_salesinvoiceitem_to_salesinvoicetimesheet.py b/erpnext/patches/v7_0/move_timelogbatch_from_salesinvoiceitem_to_salesinvoicetimesheet.py
index 7f3b755..ea7cb06 100644
--- a/erpnext/patches/v7_0/move_timelogbatch_from_salesinvoiceitem_to_salesinvoicetimesheet.py
+++ b/erpnext/patches/v7_0/move_timelogbatch_from_salesinvoiceitem_to_salesinvoicetimesheet.py
@@ -5,6 +5,8 @@
 	frappe.reload_doc('accounts', 'doctype', 'sales_invoice_payment')
 	for time_sheet in frappe.db.sql(""" select sales_invoice, name, total_billing_amount from `tabTimesheet`
 		where sales_invoice is not null and docstatus < 2""", as_dict=True):
+		if not frappe.db.exists('Sales Invoice', time_sheet.sales_invoice):
+			continue
 		si_doc = frappe.get_doc('Sales Invoice', time_sheet.sales_invoice)
 		ts = si_doc.append('timesheets',{})
 		ts.time_sheet = time_sheet.name
diff --git a/erpnext/patches/v7_0/remove_features_setup.py b/erpnext/patches/v7_0/remove_features_setup.py
index 60d1926..596f7a9 100644
--- a/erpnext/patches/v7_0/remove_features_setup.py
+++ b/erpnext/patches/v7_0/remove_features_setup.py
@@ -7,6 +7,8 @@
 	frappe.reload_doctype('Stock Settings')
 	stock_settings = frappe.get_doc('Stock Settings', 'Stock Settings')
 	stock_settings.show_barcode_field = cint(frappe.db.get_value("Features Setup", None, "fs_item_barcode"))
+	if not frappe.db.exists("UOM", stock_settings.stock_uom):
+		stock_settings.stock_uom = None
 	stock_settings.save()
 
 	create_compact_item_print_custom_field()
diff --git a/erpnext/patches/v7_0/setup_account_table_for_expense_claim_type_if_exists.py b/erpnext/patches/v7_0/setup_account_table_for_expense_claim_type_if_exists.py
index 9622490..c565707 100644
--- a/erpnext/patches/v7_0/setup_account_table_for_expense_claim_type_if_exists.py
+++ b/erpnext/patches/v7_0/setup_account_table_for_expense_claim_type_if_exists.py
@@ -16,4 +16,5 @@
 				"company": frappe.db.get_value("Account", expense_claim_type.default_account, "company"),
 				"default_account": expense_claim_type.default_account,
 			})
+			doc.flags.ignore_mandatory = True
 			doc.save(ignore_permissions=True)
\ No newline at end of file
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 938e73c..e1fb87a 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -71,7 +71,7 @@
 						"freeze_account": "No"
 					})
 					ac_doc.flags.ignore_permissions = True
-
+					ac_doc.flags.ignore_mandatory = True
 					try:
 						ac_doc.insert()
 						msgprint(_("Account head {0} created").format(ac_doc.name))