[price list] country-wise price list

This commit is contained in:
Anand Doshi 2013-05-02 16:25:59 +05:30
parent 9d504e4706
commit ff1e155a77
3 changed files with 11 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import webnotes
def execute():
webnotes.reload_doc("Setup", "DocType", "Price List")
webnotes.conn.sql("""update `tabPrice List` set valid_for_all_countries=1""")

View File

@ -29,9 +29,14 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
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);
var item_price = wn.model.get("Item Price", {price_list_name: cur_frm.doc.name});
var show = item_price && item_price.length;
cur_frm.toggle_display("item_prices_section", show);
$(cur_frm.fields_dict.item_prices.wrapper).empty();
if (!cur_frm.doc.__item_price) return;
if (!show) return;
var out = '<table class="table table-striped table-bordered">\
<thead><tr>\
<th>' + wn._("Item Code") + '</th>\
@ -40,7 +45,7 @@ cur_frm.cscript.show_item_prices = function() {
<th>' + wn._("Valid For Buying") + '</th>\
</tr></thead>\
<tbody>'
+ $.map(cur_frm.doc.__item_price.sort(function(a, b) { return a.parent.localeCompare(b.parent); }), function(d) {
+ $.map(item_price.sort(function(a, b) { return a.parent.localeCompare(b.parent); }), function(d) {
return '<tr>'
+ '<td>' + d.parent + '</td>'
+ '<td style="text-align: right;">' + format_currency(d.ref_rate, d.ref_currency) + '</td>'

View File

@ -25,8 +25,8 @@ class DocType:
self.doc, self.doclist = d, dl
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)
self.doclist.extend(webnotes.conn.sql("""select * from `tabItem Price`
where price_list_name=%s""", self.doc.name, as_dict=True, update={"doctype": "Item Price"}))
def validate(self):
if not (cint(self.doc.valid_for_all_countries) or len(self.doclist.get({"parentfield": "valid_for_countries"}))):