From 1bcc19e01972bcd30182dbbebc998a55b3588588 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 1 Jul 2013 11:46:07 +0530 Subject: [PATCH] [item] default warehouse is selected with item --- buying/utils.py | 3 +++ setup/doctype/company/company.py | 4 ++-- stock/doctype/item/item.py | 9 ++++++++- stock/doctype/item/item.txt | 6 +++--- stock/doctype/item/test_item.py | 11 +++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/buying/utils.py b/buying/utils.py index 3c8f69366b..23d55938a2 100644 --- a/buying/utils.py +++ b/buying/utils.py @@ -51,6 +51,9 @@ def get_item_details(args): out.supplier_part_no = _get_supplier_part_no(args, item_bean) + if not out.warehouse: + out.warehouse = item_bean.doc.default_warehouse + if out.warehouse: out.projected_qty = get_projected_qty(item.name, out.warehouse) diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py index 54a293f6ea..446d602082 100644 --- a/setup/doctype/company/company.py +++ b/setup/doctype/company/company.py @@ -201,8 +201,8 @@ class DocType: for a in accounts: account_name = accounts[a] + " - " + self.doc.abbr - if not self.doc.fields[a] and webnotes.conn.exists("Account", account_name): - webnotes.conn.set(self.doc, account_name) + if not self.doc.fields.get(a) and webnotes.conn.exists("Account", account_name): + webnotes.conn.set(self.doc, a, account_name) if not self.doc.stock_adjustment_cost_center: webnotes.conn.set(self.doc, "stock_adjustment_cost_center", self.doc.cost_center) diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index 09a5ce6526..295bff328f 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -25,6 +25,7 @@ from webnotes import msgprint, _ from webnotes.model.controller import DocListController class PriceListCurrencyMismatch(Exception): pass +class WarehouseNotSet(Exception): pass class DocType(DocListController): def autoname(self): @@ -39,7 +40,8 @@ class DocType(DocListController): def validate(self): if not self.doc.stock_uom: msgprint(_("Please enter Default Unit of Measure"), raise_exception=1) - + + self.check_warehouse_is_set_for_stock_item() self.check_stock_uom_with_bin() self.validate_conversion_factor() self.add_default_uom_in_conversion_factor_table() @@ -60,6 +62,11 @@ class DocType(DocListController): self.validate_name_with_item_group() self.update_website() + def check_warehouse_is_set_for_stock_item(self): + if self.doc.is_stock_item=="Yes" and not self.doc.default_warehouse: + webnotes.msgprint(_("Default Warehouse is mandatory for Stock Item."), + raise_exception=WarehouseNotSet) + def add_default_uom_in_conversion_factor_table(self): uom_conv_list = [d.uom for d in self.doclist.get({"parentfield": "uom_conversion_details"})] if self.doc.stock_uom not in uom_conv_list: diff --git a/stock/doctype/item/item.txt b/stock/doctype/item/item.txt index 1273b12420..d5fcb9ef28 100644 --- a/stock/doctype/item/item.txt +++ b/stock/doctype/item/item.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-03 10:45:46", "docstatus": 0, - "modified": "2013-06-26 21:39:46", + "modified": "2013-07-01 11:45:59", "modified_by": "Administrator", "owner": "Administrator" }, @@ -205,11 +205,11 @@ }, { "depends_on": "eval:doc.is_stock_item==\"Yes\"", - "description": "Mandatory if Stock Item is \"Yes\"", + "description": "Mandatory if Stock Item is \"Yes\". Also the default warehouse where reserved quantity is set from Sales Order.", "doctype": "DocField", "fieldname": "default_warehouse", "fieldtype": "Link", - "label": "Default Reserved Warehouse", + "label": "Default Warehouse", "oldfieldname": "default_warehouse", "oldfieldtype": "Link", "options": "Warehouse", diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py index 2145631024..35cad9d211 100644 --- a/stock/doctype/item/test_item.py +++ b/stock/doctype/item/test_item.py @@ -35,6 +35,13 @@ class TestItem(unittest.TestCase): item_price = item.doclist.get({"doctype": "Item Price"})[0].ref_currency="USD" self.assertRaises(PriceListCurrencyMismatch, item.insert) + def test_default_warehouse(self): + from stock.doctype.item.item import WarehouseNotSet + item = webnotes.bean(copy=test_records[0]) + item.doc.is_stock_item = "Yes" + item.doc.default_warehouse = None + self.assertRaises(WarehouseNotSet, item.insert) + test_records = [ [{ @@ -77,6 +84,7 @@ test_records = [ "item_name": "_Test Item Home Desktop 100", "description": "_Test Item Home Desktop 100", "item_group": "_Test Item Group Desktops", + "default_warehouse": "_Test Warehouse", "is_stock_item": "Yes", "is_asset_item": "No", "has_batch_no": "No", @@ -101,6 +109,7 @@ test_records = [ "item_name": "_Test Item Home Desktop 200", "description": "_Test Item Home Desktop 200", "item_group": "_Test Item Group Desktops", + "default_warehouse": "_Test Warehouse", "is_stock_item": "Yes", "is_asset_item": "No", "has_batch_no": "No", @@ -140,6 +149,7 @@ test_records = [ "description": "_Test FG Item", "item_group": "_Test Item Group Desktops", "is_stock_item": "Yes", + "default_warehouse": "_Test Warehouse", "is_asset_item": "No", "has_batch_no": "No", "has_serial_no": "No", @@ -178,6 +188,7 @@ test_records = [ "description": "_Test Serialized Item", "item_group": "_Test Item Group Desktops", "is_stock_item": "Yes", + "default_warehouse": "_Test Warehouse", "is_asset_item": "No", "has_batch_no": "No", "has_serial_no": "Yes",