From 3487e0a0f3a3ff265add2eebb729a44b306b79e2 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 2 May 2013 14:46:12 +0530 Subject: [PATCH] [price list] added currency property, validates currency, duplication in Item Price --- home/page/latest_updates/latest_updates.js | 2 ++ setup/doctype/price_list/price_list.txt | 13 ++++++++++--- setup/doctype/price_list/test_price_list.py | 3 ++- stock/doctype/item/item.js | 2 ++ stock/doctype/item/item.py | 18 +++++++++++++----- stock/doctype/item/test_item.py | 8 ++++++++ 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js index b768f1aa1e..e11b9c9243 100644 --- a/home/page/latest_updates/latest_updates.js +++ b/home/page/latest_updates/latest_updates.js @@ -1,4 +1,6 @@ erpnext.updates = [ + ["2nd May", ["Buying: Warehouse must belong to same company as transaction", + "Price List": "Added Currency Field. One price list can have only one currency"]], ["18th April", ["Cost Center: Set a default Cost Center for a Company"]], ["12th April", ["Employee: List of Leave Approvers who can approve the Employee's Leave Applications"]], ["10th April", ["Redesigned File Uploads and added File Manager in Setup"]], diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt index a230f5b98c..bce8aae6e7 100644 --- a/setup/doctype/price_list/price_list.txt +++ b/setup/doctype/price_list/price_list.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-25 11:35:09", "docstatus": 0, - "modified": "2013-01-22 14:56:41", + "modified": "2013-05-02 14:44:24", "modified_by": "Administrator", "owner": "Administrator" }, @@ -52,13 +52,21 @@ "oldfieldtype": "Data", "reqd": 1 }, + { + "doctype": "DocField", + "fieldname": "currency", + "fieldtype": "Link", + "label": "Currency", + "options": "Currency", + "reqd": 1 + }, { "depends_on": "price_list_name", "doctype": "DocField", "fieldname": "how_to_upload", "fieldtype": "HTML", "label": "How to upload", - "options": "
Use the Data Import Tool to upload, update Item Prices in bulk:\n
    \n
  1. Go to Data Import Tool.\n
  2. Select \"Item\"\n
  3. Check on \"With Data\"\n
  4. Download \"Item Price\" from Child Tables.\n
  5. Update the prices required and add new rows if required.\n
  6. Check on \"Overwrite\"\n
  7. Upload the modified sheet.\n
\n" + "options": "
Use the Data Import Tool to upload, update Item Prices in bulk:\n
    \n
  1. Go to Data Import Tool.\n
  2. Select \"Item\"\n
  3. Check on \"With Data\"\n
  4. Download \"Item Price\" from Child Tables.\n
  5. Update the prices required and add new rows if required.\n
  6. Check on \"Overwrite\"\n
  7. Upload the modified sheet.\n
\n" }, { "cancel": 0, @@ -78,7 +86,6 @@ "cancel": 1, "create": 1, "doctype": "DocPerm", - "match": "", "role": "Sales Master Manager", "write": 1 } diff --git a/setup/doctype/price_list/test_price_list.py b/setup/doctype/price_list/test_price_list.py index 53b86a39fc..30262dc8aa 100644 --- a/setup/doctype/price_list/test_price_list.py +++ b/setup/doctype/price_list/test_price_list.py @@ -1,6 +1,7 @@ test_records = [ [{ "doctype": "Price List", - "price_list_name": "_Test Price List" + "price_list_name": "_Test Price List", + "currency": "INR" }] ] \ No newline at end of file diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js index 8b3e04484a..2635f3e904 100644 --- a/stock/doctype/item/item.js +++ b/stock/doctype/item/item.js @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +cur_frm.add_fetch("price_list_name", "currency", "ref_currency") + cur_frm.cscript.refresh = function(doc) { // make sensitive fields(has_serial_no, is_stock_item, valuation_method) // read only if any stock ledger entry exists diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index c6bf017647..8a804d8c13 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -24,6 +24,8 @@ from webnotes import msgprint, _ from webnotes.model.controller import DocListController +class PriceListCurrencyMismatch(Exception): pass + class DocType(DocListController): def validate(self): if not self.doc.stock_uom: @@ -34,7 +36,7 @@ class DocType(DocListController): self.add_default_uom_in_conversion_factor_table() self.valiadte_item_type() self.check_for_active_boms() - self.check_ref_rate_detail() + self.validate_price_lists() self.fill_customer_code() self.check_item_tax() self.validate_barcode() @@ -122,14 +124,20 @@ class DocType(DocListController): if cstr(self.doc.fields.get(d)) != 'Yes': _check_for_active_boms(fl[d]) - def check_ref_rate_detail(self): - check_list=[] + def validate_price_lists(self): + price_lists=[] for d in getlist(self.doclist,'ref_rate_details'): - if d.price_list_name in check_list: + if d.price_list_name in price_lists: msgprint(_("Cannot have two prices for same Price List") + ": " + d.price_list_name, raise_exception= webnotes.DuplicateEntryError) else: - check_list.append(d.price_list_name) + price_list_currency = webnotes.conn.get_value("Price List", d.price_list_name, "currency") + if price_list_currency and d.ref_currency != price_list_currency: + msgprint(_("Currency does not match Price List Currency for Price List") \ + + ": " + d.price_list_name, raise_exception=PriceListCurrencyMismatch) + + price_lists.append(d.price_list_name) + def fill_customer_code(self): """ Append all the customer codes and insert into "customer_code" field of item table """ diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py index a59747c3e3..f5a688ca70 100644 --- a/stock/doctype/item/test_item.py +++ b/stock/doctype/item/test_item.py @@ -28,6 +28,14 @@ class TestItem(unittest.TestCase): item.doclist.append(webnotes.doc(item_price.fields.copy())) self.assertRaises(webnotes.DuplicateEntryError, item.insert) + def test_price_list_mismatch(self): + from stock.doctype.item.item import PriceListCurrencyMismatch + item = webnotes.bean(copy=test_records[0]) + item.doc.item_code = "_Test Item 11" + item_price = item.doclist.get({"doctype": "Item Price"})[0].ref_currency="USD" + self.assertRaises(PriceListCurrencyMismatch, item.insert) + + test_records = [ [{ "doctype": "Item",