From c711598940c04ed8cb7b7f873c343ab3665c21ad Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 2 May 2013 14:22:40 +0530 Subject: [PATCH] [doclist] new pattern / [item] pricelist must be unique / [formatter] show null floats as empty string --- controllers/buying_controller.py | 10 +++++----- stock/doctype/item/item.py | 12 ++++++------ stock/doctype/item/test_item.py | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index cd822e6ecc..0c25b9855e 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -47,13 +47,13 @@ class BuyingController(StockController): self.set_total_in_words() def validate_warehouse_belongs_to_company(self): - for d in self.doclist.get({"warehouse": True}): - warehouse_company = webnotes.conn.get_value("Warehouse", d.warehouse, "company") - if warehouse_company and warehouse_company != self.doc.company: + for warehouse, company in webnotes.conn.get_values("Warehouse", + self.doclist.get_distinct_values("warehouse"), "company").items(): + if company and company != self.doc.company: webnotes.msgprint(_("Warehouse must belong to company") + \ - (": %s (%s, %s)" % (d.warehouse, warehouse_company, self.doc.company)), + (": %s (%s, %s)" % (warehouse, company, self.doc.company)), raise_exception=WrongWarehouseCompany) - + def validate_stock_or_nonstock_items(self): items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})] if self.stock_items: diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index 6b6dfb3700..c6bf017647 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -23,6 +23,7 @@ from webnotes.model.bean import getlist from webnotes import msgprint, _ from webnotes.model.controller import DocListController + class DocType(DocListController): def validate(self): if not self.doc.stock_uom: @@ -124,13 +125,12 @@ class DocType(DocListController): def check_ref_rate_detail(self): check_list=[] for d in getlist(self.doclist,'ref_rate_details'): - if [cstr(d.price_list_name), cstr(d.ref_currency), - cint(d.selling), cint(d.buying)] in check_list: - msgprint("Ref Rate is entered twice for Price List : '%s' and Currency : '%s'." % - (d.price_list_name,d.ref_currency), raise_exception=1) + if d.price_list_name in check_list: + msgprint(_("Cannot have two prices for same Price List") + ": " + d.price_list_name, + raise_exception= webnotes.DuplicateEntryError) else: - check_list.append([cstr(d.price_list_name),cstr(d.ref_currency)]) - + check_list.append(d.price_list_name) + def fill_customer_code(self): """ Append all the customer codes and insert into "customer_code" field of item table """ cust_code=[] diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py index dbbeecc85b..a59747c3e3 100644 --- a/stock/doctype/item/test_item.py +++ b/stock/doctype/item/test_item.py @@ -20,6 +20,14 @@ import webnotes test_ignore = ["BOM"] +class TestItem(unittest.TestCase): + def test_duplicate_price_list(self): + item = webnotes.bean(copy=test_records[0]) + item.doc.item_code = "_Test Item 10" + item_price = item.doclist.get({"doctype": "Item Price"})[0] + item.doclist.append(webnotes.doc(item_price.fields.copy())) + self.assertRaises(webnotes.DuplicateEntryError, item.insert) + test_records = [ [{ "doctype": "Item", @@ -45,7 +53,14 @@ test_records = [ "warehouse": "_Test Warehouse", "warehouse_reorder_level": 20, "warehouse_reorder_qty": 20 - }], + }, { + "doctype": "Item Price", + "parentfield": "ref_rate_details", + "price_list_name": "_Test Price List", + "ref_rate": 100, + "ref_currency": "INR" + } + ], [{ "doctype": "Item", "item_code": "_Test Item Home Desktop 100",