[usability] item price moved to price list

This commit is contained in:
Akhilesh Darjee
2013-09-11 13:05:24 +05:30
parent 881a47f5c7
commit db59ffb76d
32 changed files with 129 additions and 289 deletions

View File

@@ -23,8 +23,6 @@ $.extend(cur_frm.cscript, {
set_exchange_rate_label: function() {
if(cur_frm.doc.from_currency && cur_frm.doc.to_currency) {
var default_label = wn._(wn.meta.docfield_map[cur_frm.doctype]["exchange_rate"].label);
console.log(default_label +
repl(" (1 %(from_currency)s = [?] %(to_currency)s)", cur_frm.doc));
cur_frm.fields_dict.exchange_rate.set_label(default_label +
repl(" (1 %(from_currency)s = [?] %(to_currency)s)", cur_frm.doc));
}

View File

@@ -0,0 +1 @@
Price of the Item in a particular Price List.

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,11 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# MIT License. See license.txt
# 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

View File

@@ -0,0 +1,53 @@
[
{
"creation": "2013-05-02 16:29:48",
"docstatus": 0,
"modified": "2013-09-11 12:38:24",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"autoname": "RFD/.#####",
"doctype": "DocType",
"in_create": 0,
"istable": 1,
"module": "Setup",
"name": "__common__",
"read_only": 0
},
{
"doctype": "DocField",
"in_filter": 1,
"in_list_view": 1,
"name": "__common__",
"parent": "Item Price",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
"reqd": 1
},
{
"doctype": "DocType",
"name": "Item Price"
},
{
"doctype": "DocField",
"fieldname": "item_code",
"fieldtype": "Link",
"label": "Item Code",
"oldfieldname": "price_list_name",
"oldfieldtype": "Select",
"options": "Item",
"search_index": 1
},
{
"doctype": "DocField",
"fieldname": "ref_rate",
"fieldtype": "Currency",
"label": "Ref Rate",
"oldfieldname": "ref_rate",
"oldfieldtype": "Currency",
"options": "currency",
"search_index": 0
}
]

View File

@@ -3,44 +3,6 @@
$.extend(cur_frm.cscript, {
onload: function() {
cur_frm.cscript.show_item_prices();
erpnext.add_for_territory();
},
refresh: function(doc) {
cur_frm.set_intro("");
if(doc.__islocal) {
cur_frm.toggle_display("item_prices_section", false);
cur_frm.set_intro("Save this list to begin.");
return;
} else {
cur_frm.cscript.show_item_prices();
}
},
show_item_prices: function() {
var item_price = wn.model.get("Item Price", {price_list: 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 (!show) return;
var out = '<table class="table table-striped table-bordered">\
<thead><tr>\
<th>' + wn._("Item Code") + '</th>\
<th>' + wn._("Price") + '</th>\
</tr></thead>\
<tbody>'
+ $.map(item_price.sort(function(a, b) { return a.parent.localeCompare(b.parent); }), function(d) {
return '<tr>'
+ '<td><a href="#Form/Item/' + encodeURIComponent(d.parent) +'">' + d.parent + '</a></td>'
+ '<td style="text-align: right;">' + format_currency(d.ref_rate, d.ref_currency) + '</td>'
+ '</tr>'
}).join("\n")
+ '</tbody>\
</table>';
$(out).appendTo($(cur_frm.fields_dict.item_prices.wrapper));
}
});

View File

@@ -8,11 +8,9 @@ from webnotes.utils import comma_or, cint
from webnotes.model.controller import DocListController
import webnotes.defaults
class PriceListDuplicateItem(Exception): pass
class DocType(DocListController):
def onload(self):
self.doclist.extend(webnotes.conn.sql("""select * from `tabItem Price`
where price_list=%s""", self.doc.name, as_dict=True, update={"doctype": "Item Price"}))
def validate(self):
if self.doc.buying_or_selling not in ["Buying", "Selling"]:
msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
@@ -29,17 +27,24 @@ class DocType(DocListController):
else:
# at least one territory
self.validate_table_has_rows("valid_for_territories")
# check for duplicate items
self.check_duplicate_items()
def on_update(self):
self.set_default_if_missing()
cart_settings = webnotes.get_obj("Shopping Cart Settings")
if cint(cart_settings.doc.enabled):
cart_settings.validate_price_lists()
def check_duplicate_items(self):
item_codes = []
for d in self.doclist.get({"parentfield": "item_prices"}):
if d.item_code not in item_codes:
item_codes.append(d.item_code)
else:
msgprint(_("Duplicate Item ") + ": " + d.item_code, raise_exception=PriceListDuplicateItem)
def on_trash(self):
webnotes.conn.sql("""delete from `tabItem Price` where price_list = %s""",
self.doc.name)
def set_default_if_missing(self):
if self.doc.buying_or_selling=="Selling":
if not webnotes.conn.get_value("Selling Settings", None, "selling_price_list"):
@@ -47,4 +52,5 @@ class DocType(DocListController):
elif self.doc.buying_or_selling=="Buying":
if not webnotes.conn.get_value("Buying Settings", None, "buying_price_list"):
webnotes.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.doc.name)
webnotes.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.doc.name)

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-25 11:35:09",
"docstatus": 0,
"modified": "2013-07-26 11:19:06",
"modified": "2013-09-06 15:03:38",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -94,28 +94,9 @@
{
"doctype": "DocField",
"fieldname": "item_prices",
"fieldtype": "HTML",
"label": "Item Prices"
},
{
"doctype": "DocField",
"fieldname": "column_break_10",
"fieldtype": "Column Break"
},
{
"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",
"label": "How to upload",
"options": "<div class=\"well\">Use the <a href=\"#data-import-tool\">Data Import Tool</a> to upload, update Item Prices in bulk:\n<ol> \n<li>Go to Data Import Tool.\n<li>Select \"Item\"\n<li>Check on \"With Data\"\n<li>Download \"Item Price\" from Child Tables.\n<li>Update the prices required and add new rows if required.\n<li>Check on \"Overwrite\"\n<li>Upload the modified sheet.\n</div>\n"
"fieldtype": "Table",
"label": "Item Prices",
"options": "Item Price"
},
{
"amend": 0,

View File

@@ -1,6 +1,18 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import unittest
import webnotes
from setup.doctype.price_list.price_list import PriceListDuplicateItem
class TestItem(unittest.TestCase):
def test_duplicate_item(self):
price_list = webnotes.bean(copy=test_records[0])
item_price = price_list.doclist.get({"doctype": "Item Price"})[0]
price_list.doclist.append(webnotes.doc(item_price.fields.copy()))
self.assertRaises(PriceListDuplicateItem, price_list.insert)
test_records = [
[
{
@@ -13,6 +25,12 @@ test_records = [
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "All Territories"
},
{
"doctype": "Item Price",
"parentfield": "item_prices",
"item_code": "_Test Item",
"ref_rate": 100
}
],
[