[fixes] buying/selling price lists, communication and website settings

This commit is contained in:
Anand Doshi 2013-06-12 17:40:36 +05:30
parent 9c901e75cd
commit 060d9248d3
23 changed files with 162 additions and 67 deletions

View File

@ -28,13 +28,13 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
if(this.frm.fields_dict.price_list_name) { if(this.frm.fields_dict.price_list_name) {
this.frm.set_query("price_list_name", function() { this.frm.set_query("price_list_name", function() {
return repl("select distinct price_list_name from `tabItem Price` \ return repl("select name, currency from `tabPrice List` \
where buying = 1 and price_list_name like \"%s%%\""); where buying_or_selling = 'Buying' and name like \"%s%%\"");
}); });
this.frm.set_query("price_list_currency", function() { this.frm.set_query("price_list_currency", function() {
return repl("select distinct ref_currency from `tabItem Price` \ return repl("select distinct ref_currency from `tabItem Price` \
where price_list_name=\"%(price_list_name)s\" and buying = 1 \ where price_list_name=\"%(price_list_name)s\" and buying_or_selling = 'Buying' \
and ref_currency like \"%s%%\"", and ref_currency like \"%s%%\"",
{price_list_name: me.frm.doc.price_list_name}); {price_list_name: me.frm.doc.price_list_name});
}); });

View File

@ -102,7 +102,7 @@ def _get_price_list_rate(args, item_bean, meta):
"parentfield": "ref_rate_details", "parentfield": "ref_rate_details",
"price_list_name": args.price_list_name, "price_list_name": args.price_list_name,
"ref_currency": args.price_list_currency, "ref_currency": args.price_list_currency,
"buying": 1}) "buying_or_selling": "Buying"})
if price_list_rate: if price_list_rate:
out.import_ref_rate = \ out.import_ref_rate = \
flt(price_list_rate[0].ref_rate * args.plc_conversion_rate / args.conversion_rate) flt(price_list_rate[0].ref_rate * args.plc_conversion_rate / args.conversion_rate)

View File

@ -42,7 +42,7 @@ class AccountsController(TransactionBase):
not self.doc.price_list_currency: not self.doc.price_list_currency:
self.doc.fields.update(get_price_list_currency({ self.doc.fields.update(get_price_list_currency({
"price_list_name": self.doc.price_list_name, "price_list_name": self.doc.price_list_name,
"use_for": buying_or_selling "buying_or_selling": buying_or_selling
})) }))
def set_missing_item_details(self, get_item_details): def set_missing_item_details(self, get_item_details):

View File

@ -4,6 +4,6 @@ def execute():
webnotes.reload_doc("stock", "doctype", "item_price") webnotes.reload_doc("stock", "doctype", "item_price")
# check for selling # check for selling
webnotes.conn.sql("""update `tabItem Price` set selling=1 webnotes.conn.sql("""update `tabItem Price` set buying_or_selling = "Selling"
where ifnull(selling, 0)=0 and ifnull(buying, 0)=0""") where ifnull(buying_or_selling, '')=''""")

View File

@ -0,0 +1,14 @@
import webnotes
from webnotes.utils import cint
def execute():
for price_list in webnotes.conn.sql_list("""select name from `tabPrice List`"""):
buying, selling = False, False
for b, s in webnotes.conn.sql("""select distinct buying, selling
from `tabItem Price` where price_list_name=%s""", price_list):
buying = buying or cint(b)
selling = selling or cint(s)
webnotes.conn.set_value("Price List", price_list, "buying_or_selling", ("Selling" if selling else "Buying"))
webnotes.conn.sql("""update `tabItem Price` set buying_or_selling=%s where price_list_name=%s""",
(("Selling" if selling else "Buying"), price_list))

View File

@ -241,7 +241,8 @@ patch_list = [
"patches.june_2013.p01_update_bom_exploded_items", "patches.june_2013.p01_update_bom_exploded_items",
"patches.june_2013.p02_update_project_completed", "patches.june_2013.p02_update_project_completed",
"execute:webnotes.delete_doc('DocType', 'System Console')", "execute:webnotes.delete_doc('DocType', 'System Console')",
"patches.june_2013.p03_buying_selling_for_price_list",
"patches.june_2013.p04_fix_event_for_lead_oppty_project", "patches.june_2013.p04_fix_event_for_lead_oppty_project",
"patches.june_2013.p05_remove_unused_doctypes", "patches.june_2013.p05_remove_unused_doctypes",
"patches.june_2013.p06_drop_unused_tables" "patches.june_2013.p06_drop_unused_tables",
] ]

View File

@ -90,14 +90,14 @@ erpnext.TransactionController = wn.ui.form.Controller.extend({
this.price_list_currency(); this.price_list_currency();
}, },
price_list_name: function(use_for) { price_list_name: function(buying_or_selling) {
var me = this; var me = this;
if(this.frm.doc.price_list_name) { if(this.frm.doc.price_list_name) {
this.frm.call({ this.frm.call({
method: "setup.utils.get_price_list_currency", method: "setup.utils.get_price_list_currency",
args: {args: { args: {args: {
price_list_name: this.frm.doc.price_list_name, price_list_name: this.frm.doc.price_list_name,
use_for: use_for buying_or_selling: buying_or_selling
}}, }},
callback: function(r) { callback: function(r) {
if(!r.exc) { if(!r.exc) {

View File

@ -102,7 +102,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
price_list_name: function() { price_list_name: function() {
this._super("selling"); this._super("Selling");
}, },
ref_rate: function(doc, cdt, cdn) { ref_rate: function(doc, cdt, cdn) {

View File

@ -135,7 +135,7 @@ def _get_price_list_rate(args, item_bean, meta):
"parentfield": "ref_rate_details", "parentfield": "ref_rate_details",
"price_list_name": args.price_list_name, "price_list_name": args.price_list_name,
"price_list_currency": args.price_list_currency, "price_list_currency": args.price_list_currency,
"selling": 1}) "buying_or_selling": "Selling"})
if not base_ref_rate: if not base_ref_rate:
return {} return {}

View File

@ -21,6 +21,7 @@ cur_frm.cscript.onload = function() {
cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.set_intro(""); cur_frm.set_intro("");
if(doc.__islocal) { if(doc.__islocal) {
cur_frm.toggle_display("item_prices_section", false);
cur_frm.set_intro("Save this list to begin."); cur_frm.set_intro("Save this list to begin.");
return; return;
} else { } else {
@ -41,16 +42,12 @@ cur_frm.cscript.show_item_prices = function() {
<thead><tr>\ <thead><tr>\
<th>' + wn._("Item Code") + '</th>\ <th>' + wn._("Item Code") + '</th>\
<th>' + wn._("Price") + '</th>\ <th>' + wn._("Price") + '</th>\
<th>' + wn._("Valid For Selling") + '</th>\
<th>' + wn._("Valid For Buying") + '</th>\
</tr></thead>\ </tr></thead>\
<tbody>' <tbody>'
+ $.map(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>' return '<tr>'
+ '<td>' + d.parent + '</td>' + '<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>' + '<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>' + '</tr>'
}).join("\n") }).join("\n")
+ '</tbody>\ + '</tbody>\

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes import msgprint, _ from webnotes import msgprint, _
from webnotes.utils import cint from webnotes.utils import cint, comma_or
class DocType: class DocType:
@ -32,6 +32,10 @@ class DocType:
if not (cint(self.doc.valid_for_all_countries) or len(self.doclist.get({"parentfield": "valid_for_countries"}))): 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 \ msgprint(_("""Please check "Valid For All Countries" or \
enter atlease one row in the "Countries" table."""), raise_exception=True) enter atlease one row in the "Countries" table."""), raise_exception=True)
if self.doc.buying_or_selling not in ["Buying", "Selling"]:
msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
comma_or(["Buying", "Selling"]), raise_exception=True)
def on_trash(self): def on_trash(self):
webnotes.conn.sql("""delete from `tabItem Price` where price_list_name = %s""", webnotes.conn.sql("""delete from `tabItem Price` where price_list_name = %s""",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-25 11:35:09", "creation": "2013-01-25 11:35:09",
"docstatus": 0, "docstatus": 0,
"modified": "2013-05-02 14:45:00", "modified": "2013-06-11 20:00:07",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -60,6 +60,26 @@
"options": "Currency", "options": "Currency",
"reqd": 1 "reqd": 1
}, },
{
"default": "Selling",
"doctype": "DocField",
"fieldname": "buying_or_selling",
"fieldtype": "Select",
"label": "Valid for Buying or Selling?",
"options": "Buying\nSelling",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "use_for_website",
"fieldtype": "Check",
"label": "Use for Website"
},
{
"doctype": "DocField",
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{ {
"default": "1", "default": "1",
"doctype": "DocField", "doctype": "DocField",
@ -68,7 +88,7 @@
"label": "Valid for all countries" "label": "Valid for all countries"
}, },
{ {
"description": "A list of Countries, for which, this Price List is valid", "description": "Or specify a list of Countries, for which, this Price List is valid",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "valid_for_countries", "fieldname": "valid_for_countries",
"fieldtype": "Table", "fieldtype": "Table",
@ -79,6 +99,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "item_prices_section", "fieldname": "item_prices_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0,
"label": "Item Prices" "label": "Item Prices"
}, },
{ {
@ -87,6 +108,11 @@
"fieldtype": "HTML", "fieldtype": "HTML",
"label": "Item Prices" "label": "Item Prices"
}, },
{
"doctype": "DocField",
"fieldname": "column_break_10",
"fieldtype": "Column Break"
},
{ {
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"doctype": "DocField", "doctype": "DocField",

View File

@ -34,16 +34,16 @@ def get_price_list_currency(args):
""" """
args = { args = {
"price_list_name": "Something", "price_list_name": "Something",
"use_for": "buying" or "selling" "buying_or_selling": "Buying" or "Selling"
} }
""" """
if isinstance(args, basestring): if isinstance(args, basestring):
args = json.loads(args) args = json.loads(args)
result = webnotes.conn.sql("""select distinct ref_currency from `tabItem Price` result = webnotes.conn.sql("""select distinct ref_currency from `tabItem Price`
where price_list_name=%s and `%s`=1""" % ("%s", args.get("use_for")), where price_list_name=%s and buying_or_selling=%s""" % ("%s", args.get("buying_or_selling")),
(args.get("price_list_name"),)) (args.get("price_list_name"),))
if result and len(result)==1: if result and len(result)==1:
return {"price_list_currency": result[0][0]} return {"price_list_currency": result[0][0]}
else: else:
return {} return {}

View File

@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.add_fetch("price_list_name", "currency", "ref_currency") cur_frm.add_fetch("price_list_name", "currency", "ref_currency");
cur_frm.add_fetch("price_list_name", "buying_or_selling", "buying_or_selling");
cur_frm.cscript.refresh = function(doc) { cur_frm.cscript.refresh = function(doc) {
// make sensitive fields(has_serial_no, is_stock_item, valuation_method) // make sensitive fields(has_serial_no, is_stock_item, valuation_method)

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-04-29 15:18:04", "creation": "2013-05-02 16:29:48",
"docstatus": 0, "docstatus": 0,
"modified": "2013-04-29 19:16:45", "modified": "2013-06-11 18:27:55",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -60,21 +60,18 @@
"oldfieldname": "ref_currency", "oldfieldname": "ref_currency",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "Currency", "options": "Currency",
"reqd": 1, "read_only": 1,
"reqd": 0,
"search_index": 1 "search_index": 1
}, },
{ {
"description": "Allow this price in sales related forms", "default": "Selling",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "selling", "fieldname": "buying_or_selling",
"fieldtype": "Check", "fieldtype": "Select",
"label": "Valid For Selling" "label": "Valid for Buying or Selling?",
}, "options": "Buying\nSelling",
{ "read_only": 1,
"description": "Allow this price in purchase related forms", "reqd": 1
"doctype": "DocField",
"fieldname": "buying",
"fieldtype": "Check",
"label": "Valid For Buying"
} }
] ]

View File

@ -22,6 +22,9 @@ $.extend(cur_frm.cscript, {
cur_frm.footer.help_area.innerHTML = '<p><a href="#Form/Email Settings/Email Settings">Email Settings</a><br>\ cur_frm.footer.help_area.innerHTML = '<p><a href="#Form/Email Settings/Email Settings">Email Settings</a><br>\
<span class="help">Integrate incoming support emails to Support Ticket</span></p>'; <span class="help">Integrate incoming support emails to Support Ticket</span></p>';
} }
if(doc.description)
doc.description = wn.utils.escape_script_and_style(doc.description);
}, },
refresh: function(doc) { refresh: function(doc) {

View File

@ -260,9 +260,7 @@ class TransactionBase(StatusUpdater):
comm_list = webnotes.conn.sql("""select * from tabCommunication comm_list = webnotes.conn.sql("""select * from tabCommunication
where %s=%s order by modified desc limit 20""" \ where %s=%s order by modified desc limit 20""" \
% (self.doc.doctype.replace(" ", "_").lower(), "%s"), % (self.doc.doctype.replace(" ", "_").lower(), "%s"),
self.doc.name, as_dict=1) self.doc.name, as_dict=1, update={"doctype":"Communication"})
[d.update({"doctype":"Communication"}) for d in comm_list]
self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \ self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
for d in comm_list])) for d in comm_list]))

View File

@ -17,29 +17,45 @@
// update parent select // update parent select
$.extend(cur_frm.cscript, { $.extend(cur_frm.cscript, {
onload_post_render: function(doc) { onload_post_render: function(doc) {
// get labels of parent items this.set_parent_label_options();
var get_parent_options = function(table_field) { },
var items = getchildren('Top Bar Item', doc.name, table_field);
var main_items = ['']; label: function(doc, cdt, cdn) {
for(var i in items) { var item = wn.model.get_doc(cdt, cdn);
var d = items[i]; if(item.parentfield === "top_bar_items") {
if(!d.parent_label) { this.set_parent_label_options();
main_items.push(d.label);
}
}
return main_items.join('\n');
} }
},
parent_label: function(doc, cdt, cdn) {
this.label(doc, cdt, cdn);
},
url: function(doc, cdt, cdn) {
this.label(doc, cdt, cdn);
}
set_parent_label_options: function() {
wn.meta.get_docfield("Top Bar Item", "parent_label", cur_frm.docname).options =
this.get_parent_options("top_bar_items");
// bind function to refresh fields if($(cur_frm.fields_dict.top_bar_items.grid.wrapper).find(".grid-row-open")) {
// when "Parent Label" is select, it cur_frm.fields_dict.top_bar_items.grid.refresh();
// should automatically update }
// options },
$(cur_frm.fields_dict['top_bar_items'].grid.get_field('parent_label').wrapper)
.bind('refresh', function() { // get labels of parent items
this.fieldobj.refresh_options(get_parent_options('top_bar_items')); get_parent_options: function(table_field) {
}); var items = getchildren('Top Bar Item', cur_frm.doc.name, table_field);
var main_items = [''];
for(var i in items) {
var d = items[i];
if(!d.parent_label && !d.url && d.label) {
main_items.push(d.label);
}
}
return main_items.join('\n');
} }
}); });

View File

@ -15,12 +15,39 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes
from webnotes import _, msgprint
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
def validate(self): def validate(self):
self.set_home_page() self.set_home_page()
self.validate_top_bar_items()
self.validate_footer_items()
def validate_top_bar_items(self):
"""validate url in top bar items"""
for top_bar_item in self.doclist.get({"parentfield": "top_bar_items"}):
if top_bar_item.parent_label:
parent_label_item = self.doclist.get({"parentfield": "top_bar_items",
"label": top_bar_item.parent_label})
if not parent_label_item:
# invalid item
msgprint(_(self.meta.get_label("parent_label", parentfield="top_bar_items")) +
(" \"%s\": " % top_bar_item.parent_label) + _("does not exist"), raise_exception=True)
elif not parent_label_item[0] or parent_label_item[0].url:
# parent cannot have url
msgprint(_("Top Bar Item") + (" \"%s\": " % top_bar_item.parent_label) +
_("cannot have a URL, because it has child item(s)"), raise_exception=True)
def validate_footer_items(self):
"""clear parent label in footer"""
for footer_item in self.doclist.get({"parentfield": "footer_items"}):
footer_item.parent_label = None
def on_update(self): def on_update(self):
# make js and css # make js and css
@ -32,10 +59,7 @@ class DocType:
clear_cache() clear_cache()
def set_home_page(self): def set_home_page(self):
import webnotes
from webnotes.model.doc import Document from webnotes.model.doc import Document
webnotes.conn.sql("""delete from `tabDefault Home Page` where role='Guest'""") webnotes.conn.sql("""delete from `tabDefault Home Page` where role='Guest'""")
d = Document('Default Home Page') d = Document('Default Home Page')

View File

@ -91,7 +91,7 @@ def get_group_item_count(item_group):
def get_item_for_list_in_html(r): def get_item_for_list_in_html(r):
scrub_item_for_list(r) scrub_item_for_list(r)
r.template = "app/website/templates/html/product_in_list.html" r.template = "app/website/templates/html/product_in_grid.html"
return build_html(r) return build_html(r)
def scrub_item_for_list(r): def scrub_item_for_list(r):

View File

@ -7,7 +7,7 @@
font-size: 18px; font-size: 18px;
line-height: 200%; line-height: 200%;
} }
.item-price { .item-price-info {
margin-top: 20px; margin-top: 20px;
} }
</style> </style>

View File

@ -0,0 +1,14 @@
<div class="col col-lg-3">
<div style="height: 120px; overflow: hidden;">
<a href="{{ page_name }}">
{%- if website_image -%}
<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image }}">
{%- else -%}
{% include 'app/website/templates/html/product_missing_image.html' %}
{%- endif -%}
</a>
</div>
<div style="height: 100px; overflow: hidden; font-size: 80%;">
<h4 style="margin-bottom: 2px;"><a href="{{ page_name }}">{{ item_name }}</a></h4>
</div>
</div>

View File

@ -1 +1 @@
<div class='missing-image'><i class='icon-camera'></i></div> <div class="missing-image"><i class="icon-camera"></i></div>