Merge branch 'price_list_country'
Conflicts: home/page/latest_updates/latest_updates.js setup/doctype/price_list/price_list.txt
This commit is contained in:
commit
9d504e4706
@ -4,6 +4,7 @@ erpnext.updates = [
|
||||
"Item: Naming can now be by series or item code",
|
||||
"Naming Series: Set number of digits in series (optionally)",
|
||||
"Login: Disable Signup link in the login page"]],
|
||||
["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"]],
|
||||
|
4
patches/april_2013/p08_price_list_country.py
Normal file
4
patches/april_2013/p08_price_list_country.py
Normal file
@ -0,0 +1,4 @@
|
||||
import webnotes
|
||||
|
||||
def execute():
|
||||
webnotes.conn.sql("""update `tabPrice List` set valid_for_all_countries=1""")
|
@ -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",
|
||||
]
|
@ -14,10 +14,41 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 = '<table class="table table-striped table-bordered">\
|
||||
<thead><tr>\
|
||||
<th>' + wn._("Item Code") + '</th>\
|
||||
<th>' + wn._("Price") + '</th>\
|
||||
<th>' + wn._("Valid For Selling") + '</th>\
|
||||
<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) {
|
||||
return '<tr>'
|
||||
+ '<td>' + d.parent + '</td>'
|
||||
+ '<td style="text-align: right;">' + format_currency(d.ref_rate, d.ref_currency) + '</td>'
|
||||
+ '<td>' + (cint(d.selling) ? '<i class="icon-check"></i>' : "") + '</td>'
|
||||
+ '<td>' + (cint(d.buying) ? '<i class="icon-check"></i>' : "") + '</td>'
|
||||
+ '</tr>'
|
||||
}).join("\n")
|
||||
+ '</tbody>\
|
||||
</table>';
|
||||
$(out).appendTo($(cur_frm.fields_dict.item_prices.wrapper));
|
||||
}
|
||||
|
@ -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("<b>%s</b> items updated" % updated)
|
||||
webnotes.conn.auto_commit_on_many_writes = 0
|
||||
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)
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-01-25 11:35:09",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-05-02 14:44:24",
|
||||
"modified": "2013-05-02 14:45:00",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -61,7 +61,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",
|
||||
|
0
setup/doctype/price_list_country/__init__.py
Normal file
0
setup/doctype/price_list_country/__init__.py
Normal file
8
setup/doctype/price_list_country/price_list_country.py
Normal file
8
setup/doctype/price_list_country/price_list_country.py
Normal file
@ -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
|
36
setup/doctype/price_list_country/price_list_country.txt
Normal file
36
setup/doctype/price_list_country/price_list_country.txt
Normal file
@ -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"
|
||||
}
|
||||
]
|
@ -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"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user