From d7ad13a8a7d98e7977d25d1e8d2b1e281a3cdd2d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 19:38:34 +0530 Subject: [PATCH] [price list] [country] specify country for a price list --- home/page/latest_updates/latest_updates.js | 1 + patches/april_2013/p08_price_list_country.py | 4 + patches/patch_list.py | 1 + setup/doctype/price_list/price_list.js | 31 ++++++++ setup/doctype/price_list/price_list.py | 75 +++---------------- setup/doctype/price_list/price_list.txt | 39 +++++++++- setup/doctype/price_list_country/__init__.py | 0 .../price_list_country/price_list_country.py | 8 ++ .../price_list_country/price_list_country.txt | 36 +++++++++ stock/doctype/item_price/item_price.txt | 8 +- 10 files changed, 132 insertions(+), 71 deletions(-) create mode 100644 patches/april_2013/p08_price_list_country.py create mode 100644 setup/doctype/price_list_country/__init__.py create mode 100644 setup/doctype/price_list_country/price_list_country.py create mode 100644 setup/doctype/price_list_country/price_list_country.txt diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js index b768f1aa1e..4a09c5e2ff 100644 --- a/home/page/latest_updates/latest_updates.js +++ b/home/page/latest_updates/latest_updates.js @@ -1,4 +1,5 @@ erpnext.updates = [ + ["30th April", ["Price List: Valid for all countries or only valid for specific countries"]], ["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/patches/april_2013/p08_price_list_country.py b/patches/april_2013/p08_price_list_country.py new file mode 100644 index 0000000000..1179e1da5b --- /dev/null +++ b/patches/april_2013/p08_price_list_country.py @@ -0,0 +1,4 @@ +import webnotes + +def execute(): + webnotes.conn.sql("""update `tabPrice List` set valid_for_all_countries=1""") \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index c9a0ab5aed..83fb43fd14 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -249,4 +249,5 @@ patch_list = [ "execute:webnotes.reset_perms('File Data')", "patches.april_2013.p07_update_file_data_2", "patches.april_2013.rebuild_sales_browser", + "patches.april_2013.p08_price_list_country", ] \ No newline at end of file diff --git a/setup/doctype/price_list/price_list.js b/setup/doctype/price_list/price_list.js index 75d3d0f1c1..0020edaf20 100644 --- a/setup/doctype/price_list/price_list.js +++ b/setup/doctype/price_list/price_list.js @@ -14,10 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +cur_frm.cscript.onload = function() { + cur_frm.cscript.show_item_prices(); +} + cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.set_intro(""); if(doc.__islocal) { cur_frm.set_intro("Save this list to begin."); return; + } else { + cur_frm.cscript.show_item_prices(); } } + +cur_frm.cscript.show_item_prices = function() { + cur_frm.toggle_display("item_prices_section", cur_frm.doc.__item_price && cur_frm.doc.__item_price.length); + $(cur_frm.fields_dict.item_prices.wrapper).empty(); + if (!cur_frm.doc.__item_price) return; + var out = '\ + \ + \ + \ + \ + \ + \ + ' + + $.map(cur_frm.doc.__item_price.sort(function(a, b) { return a.parent.localeCompare(b.parent); }), function(d) { + return '' + + '' + + '' + + '' + + '' + + '' + }).join("\n") + + '\ +
' + wn._("Item Code") + '' + wn._("Price") + '' + wn._("Valid For Selling") + '' + wn._("Valid For Buying") + '
' + d.parent + '' + format_currency(d.ref_rate, d.ref_currency) + '' + (cint(d.selling) ? '' : "") + '' + (cint(d.buying) ? '' : "") + '
'; + $(out).appendTo($(cur_frm.fields_dict.item_prices.wrapper)); +} diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py index a88309b6db..9fef9154d7 100644 --- a/setup/doctype/price_list/price_list.py +++ b/setup/doctype/price_list/price_list.py @@ -16,73 +16,20 @@ from __future__ import unicode_literals import webnotes - -from webnotes.model.doc import Document -from webnotes import msgprint +from webnotes import msgprint, _ +from webnotes.utils import cint class DocType: def __init__(self, d, dl): self.doc, self.doclist = d, dl - self.cl = [] - - # validate currency - def is_currency_valid(self, currency): - if currency in self.cl: - return 1 - - if webnotes.conn.sql("select name from tabCurrency where name=%s", currency): - self.cl.append(currency) - return 1 - else: - return 0 - - def download_template(self, arg=None): - """download 3 column template with all Items""" - default_currency = webnotes.conn.get_default('currency') - item_list = webnotes.conn.sql("""select name from tabItem where - (ifnull(is_sales_item,'')='Yes' or ifnull(is_service_item,'')='Yes')""") - data = [self.get_price(i[0], default_currency) for i in item_list] - return [['Item', 'Rate', 'Currency']] + data - - def get_price(self, item, default_currency): - rate = webnotes.conn.sql("""select ref_rate, ref_currency from `tabItem Price` - where parent=%s and price_list_name=%s""", (item, self.doc.name)) - return [item, rate and rate[0][0] or 0, rate and rate[0][1] or default_currency] - - # update prices in Price List - def update_prices(self): - from webnotes.utils.datautils import read_csv_content_from_attached_file - data = read_csv_content_from_attached_file(self.doc) - webnotes.conn.auto_commit_on_many_writes = 1 - - updated = 0 - - for line in data: - if line and len(line)==3 and line[0]!='Item': - # if item exists - if webnotes.conn.sql("select name from tabItem where name=%s", line[0]): - if self.is_currency_valid(line[2]): - # if price exists - ref_ret_detail = webnotes.conn.sql("select name from `tabItem Price` where parent=%s and price_list_name=%s and ref_currency=%s", \ - (line[0], self.doc.name, line[2])) - if ref_ret_detail: - webnotes.conn.sql("update `tabItem Price` set ref_rate=%s where name=%s", (line[1], ref_ret_detail[0][0])) - else: - d = Document('Item Price') - d.parent = line[0] - d.parentfield = 'ref_rate_details' - d.parenttype = 'Item' - d.price_list_name = self.doc.name - d.ref_rate = line[1] - d.ref_currency = line[2] - d.save(1) - updated += 1 - else: - msgprint("[Ignored] Unknown currency '%s' for Item '%s'" % (line[2], line[0])) - else: - msgprint("[Ignored] Did not find Item '%s'" % line[1]) - - msgprint("%s items updated" % updated) - webnotes.conn.auto_commit_on_many_writes = 0 \ No newline at end of file + def onload(self): + self.doc.fields["__item_price"] = webnotes.conn.sql("""select parent, ref_rate, ref_currency, selling, buying + from `tabItem Price` where price_list_name=%s""", self.doc.name, as_dict=True) + + def validate(self): + if not (cint(self.doc.valid_for_all_countries) or len(self.doclist.get({"parentfield": "valid_for_countries"}))): + msgprint(_("""Please check "Valid For All Countries" or \ + enter atlease one row in the "Countries" table."""), raise_exception=True) + diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt index a230f5b98c..de945b4dd1 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-04-29 19:32:15", "modified_by": "Administrator", "owner": "Administrator" }, @@ -53,7 +53,41 @@ "reqd": 1 }, { - "depends_on": "price_list_name", + "default": "1", + "doctype": "DocField", + "fieldname": "valid_for_all_countries", + "fieldtype": "Check", + "label": "Valid for all countries" + }, + { + "description": "A list of Countries, for which, this Price List is valid", + "doctype": "DocField", + "fieldname": "valid_for_countries", + "fieldtype": "Table", + "label": "Valid for the following countries", + "options": "Price List Country" + }, + { + "doctype": "DocField", + "fieldname": "item_prices_section", + "fieldtype": "Section Break", + "label": "Item Prices" + }, + { + "doctype": "DocField", + "fieldname": "item_prices", + "fieldtype": "HTML", + "label": "Item Prices" + }, + { + "depends_on": "eval:!doc.__islocal", + "doctype": "DocField", + "fieldname": "section_break_1", + "fieldtype": "Section Break", + "label": "How to upload" + }, + { + "depends_on": "eval:!doc.__islocal", "doctype": "DocField", "fieldname": "how_to_upload", "fieldtype": "HTML", @@ -78,7 +112,6 @@ "cancel": 1, "create": 1, "doctype": "DocPerm", - "match": "", "role": "Sales Master Manager", "write": 1 } diff --git a/setup/doctype/price_list_country/__init__.py b/setup/doctype/price_list_country/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/price_list_country/price_list_country.py b/setup/doctype/price_list_country/price_list_country.py new file mode 100644 index 0000000000..928aa9ff9f --- /dev/null +++ b/setup/doctype/price_list_country/price_list_country.py @@ -0,0 +1,8 @@ +# For license information, please see license.txt + +from __future__ import unicode_literals +import webnotes + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl \ No newline at end of file diff --git a/setup/doctype/price_list_country/price_list_country.txt b/setup/doctype/price_list_country/price_list_country.txt new file mode 100644 index 0000000000..640b0a8052 --- /dev/null +++ b/setup/doctype/price_list_country/price_list_country.txt @@ -0,0 +1,36 @@ +[ + { + "creation": "2013-04-29 18:24:32", + "docstatus": 0, + "modified": "2013-04-29 18:24:32", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "autoname": "PLCNTRY-.#####", + "doctype": "DocType", + "istable": 1, + "module": "Setup", + "name": "__common__" + }, + { + "doctype": "DocField", + "fieldname": "country", + "fieldtype": "Link", + "label": "Country", + "name": "__common__", + "options": "Country", + "parent": "Price List Country", + "parentfield": "fields", + "parenttype": "DocType", + "permlevel": 0, + "reqd": 1 + }, + { + "doctype": "DocType", + "name": "Price List Country" + }, + { + "doctype": "DocField" + } +] \ No newline at end of file diff --git a/stock/doctype/item_price/item_price.txt b/stock/doctype/item_price/item_price.txt index 721902bc72..ad0b840c11 100644 --- a/stock/doctype/item_price/item_price.txt +++ b/stock/doctype/item_price/item_price.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-03-08 15:37:16", + "creation": "2013-04-29 15:18:04", "docstatus": 0, - "modified": "2013-03-21 17:29:15", + "modified": "2013-04-29 19:16:45", "modified_by": "Administrator", "owner": "Administrator" }, @@ -68,13 +68,13 @@ "doctype": "DocField", "fieldname": "selling", "fieldtype": "Check", - "label": "For Selling" + "label": "Valid For Selling" }, { "description": "Allow this price in purchase related forms", "doctype": "DocField", "fieldname": "buying", "fieldtype": "Check", - "label": "For Buying" + "label": "Valid For Buying" } ] \ No newline at end of file