Merge pull request #17690 from rohitwaghchaure/set_default_warehouse_from_the_stock_settings_v12

fix: while making the item, default warehouse not set even if the stock settings has the warehouse
This commit is contained in:
rohitwaghchaure 2019-05-23 15:04:43 +05:30 committed by GitHub
commit fd4815da53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -723,7 +723,18 @@ class Item(WebsiteGenerator):
'income_account': item.income_account
})
else:
self.append("item_defaults", {"company": frappe.defaults.get_defaults().company})
warehouse = ''
defaults = frappe.defaults.get_defaults() or {}
# To check default warehouse is belong to the default company
if defaults.get("default_warehouse") and frappe.db.exists("Warehouse",
{'name': defaults.default_warehouse, 'company': defaults.company}):
warehouse = defaults.default_warehouse
self.append("item_defaults", {
"company": defaults.get("company"),
"default_warehouse": warehouse
})
def update_variants(self):
if self.flags.dont_update_variants or \

View File

@ -220,17 +220,18 @@ def get_basic_details(args, item):
if item.variant_of:
item.update_template_tables()
from frappe.defaults import get_user_default_as_list
user_default_warehouse_list = get_user_default_as_list('Warehouse')
user_default_warehouse = user_default_warehouse_list[0] \
if len(user_default_warehouse_list) == 1 else ""
item_defaults = get_item_defaults(item.name, args.company)
item_group_defaults = get_item_group_defaults(item.name, args.company)
brand_defaults = get_brand_defaults(item.name, args.company)
warehouse = args.get("set_warehouse") or user_default_warehouse or item_defaults.get("default_warehouse") or\
item_group_defaults.get("default_warehouse") or brand_defaults.get("default_warehouse") or args.warehouse
warehouse = (args.get("set_warehouse") or item_defaults.get("default_warehouse") or
item_group_defaults.get("default_warehouse") or brand_defaults.get("default_warehouse") or args.warehouse)
if not warehouse:
defaults = frappe.defaults.get_defaults() or {}
if defaults.get("default_warehouse") and frappe.db.exists("Warehouse",
{'name': defaults.default_warehouse, 'company': args.company}):
warehouse = defaults.default_warehouse
if args.get('doctype') == "Material Request" and not args.get('material_request_type'):
args['material_request_type'] = frappe.db.get_value('Material Request',