From ba6217356195a8561dfb5fcc5ffc27ba14fb8d56 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 4 Jul 2019 15:00:04 +0530 Subject: [PATCH] fix: default supplier was not set from the patch in item defaults for multi company instance --- erpnext/patches.txt | 3 ++- ...pdate_default_supplier_in_item_defaults.py | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v11_1/update_default_supplier_in_item_defaults.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 962ef8a8a8d..9827814f07e 100755 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -602,4 +602,5 @@ erpnext.patches.v11_1.delete_scheduling_tool erpnext.patches.v11_1.update_bank_transaction_status erpnext.patches.v11_1.renamed_delayed_item_report erpnext.patches.v11_1.set_missing_opportunity_from -erpnext.patches.v11_1.set_quotation_status \ No newline at end of file +erpnext.patches.v11_1.set_quotation_status +erpnext.patches.v11_1.update_default_supplier_in_item_defaults \ No newline at end of file diff --git a/erpnext/patches/v11_1/update_default_supplier_in_item_defaults.py b/erpnext/patches/v11_1/update_default_supplier_in_item_defaults.py new file mode 100644 index 00000000000..347dec1f74d --- /dev/null +++ b/erpnext/patches/v11_1/update_default_supplier_in_item_defaults.py @@ -0,0 +1,25 @@ +# Copyright (c) 2018, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + ''' + default supplier was not set in the item defaults for multi company instance, + this patch will set the default supplier + + ''' + if not frappe.db.has_column('Item', 'default_supplier'): + return + + frappe.reload_doc('stock', 'doctype', 'item_default') + frappe.reload_doc('stock', 'doctype', 'item') + + companies = frappe.get_all("Company") + if len(companies) > 1: + frappe.db.sql(""" UPDATE `tabItem Default`, `tabItem` + SET `tabItem Default`.default_supplier = `tabItem`.default_supplier + WHERE + `tabItem Default`.parent = `tabItem`.name and `tabItem Default`.default_supplier is null + and `tabItem`.default_supplier is not null and `tabItem`.default_supplier != '' """) \ No newline at end of file