[webshop] shopping cart settings, update price list, taxes and shipping rule on change of address, apply defaults on creation of fresh quotation

This commit is contained in:
Anand Doshi
2013-07-04 17:13:53 +05:30
parent 259e0b978c
commit 99100a4135
40 changed files with 1225 additions and 474 deletions

View File

@@ -0,0 +1,39 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
$.extend(cur_frm.cscript, {
refresh: function() {
cur_frm.cscript.set_exchange_rate_label();
},
from_currency: function() {
cur_frm.cscript.set_exchange_rate_label();
},
to_currency: function() {
cur_frm.cscript.set_exchange_rate_label();
},
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

@@ -2,7 +2,7 @@
{
"creation": "2013-06-20 15:40:29",
"docstatus": 0,
"modified": "2013-06-20 15:40:29",
"modified": "2013-07-03 17:11:40",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -23,6 +23,16 @@
"permlevel": 0,
"reqd": 1
},
{
"doctype": "DocPerm",
"name": "__common__",
"parent": "Currency Exchange",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1
},
{
"doctype": "DocType",
"name": "Currency Exchange"
@@ -46,5 +56,24 @@
"fieldname": "exchange_rate",
"fieldtype": "Float",
"label": "Exchange Rate"
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"role": "Accounts Manager",
"write": 1
},
{
"doctype": "DocPerm",
"role": "Accounts User"
},
{
"doctype": "DocPerm",
"role": "Sales User"
},
{
"doctype": "DocPerm",
"role": "Purchase User"
}
]

View File

@@ -0,0 +1,14 @@
test_records = [
[{
"doctype": "Currency Exchange",
"from_currency": "USD",
"to_currency": "INR",
"exchange_rate": 1
}],
[{
"doctype": "Currency Exchange",
"from_currency": "USD",
"to_currency": "EUR",
"exchange_rate": 0.773
}]
]

View File

@@ -17,7 +17,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, _
from webnotes.utils import comma_or
from webnotes.utils import comma_or, cint
from webnotes.model.controller import DocListController
class DocType(DocListController):
@@ -30,6 +30,14 @@ class DocType(DocListController):
msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
comma_or(["Buying", "Selling"]), raise_exception=True)
# at least one territory
self.validate_table_has_rows("valid_for_territories")
def on_update(self):
cart_settings = webnotes.get_obj("Shopping Cart Settings")
if cint(cart_settings.doc.enabled):
cart_settings.validate_price_lists()
def on_trash(self):
webnotes.conn.sql("""delete from `tabItem Price` where price_list_name = %s""",
self.doc.name)

View File

@@ -1,8 +1,59 @@
test_records = [
[{
"doctype": "Price List",
"price_list_name": "_Test Price List",
"currency": "INR",
"buying_or_selling": "Selling"
}]
[
{
"doctype": "Price List",
"price_list_name": "_Test Price List",
"currency": "INR",
"buying_or_selling": "Selling"
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "All Territories"
}
],
[
{
"doctype": "Price List",
"price_list_name": "_Test Price List 2",
"currency": "INR",
"buying_or_selling": "Selling"
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "_Test Territory Rest of the World"
}
],
[
{
"doctype": "Price List",
"price_list_name": "_Test Price List India",
"currency": "INR",
"buying_or_selling": "Selling"
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "_Test Territory India"
}
],
[
{
"doctype": "Price List",
"price_list_name": "_Test Price List Rest of the World",
"currency": "USD",
"buying_or_selling": "Selling"
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "_Test Territory Rest of the World"
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "_Test Territory United States"
}
],
]

View File

@@ -4,5 +4,29 @@ test_records = [
"territory_name": "_Test Territory",
"parent_territory": "All Territories",
"is_group": "No",
}]
}],
[{
"doctype": "Territory",
"territory_name": "_Test Territory India",
"parent_territory": "All Territories",
"is_group": "Yes",
}],
[{
"doctype": "Territory",
"territory_name": "_Test Territory Maharashtra",
"parent_territory": "_Test Territory India",
"is_group": "No",
}],
[{
"doctype": "Territory",
"territory_name": "_Test Territory Rest of the World",
"parent_territory": "All Territories",
"is_group": "No",
}],
[{
"doctype": "Territory",
"territory_name": "_Test Territory United States",
"parent_territory": "All Territories",
"is_group": "No",
}],
]

View File

@@ -91,6 +91,8 @@ items = [
},
{ "doctype": "Sales Taxes and Charges Master" },
{ "doctype": "Purchase Taxes and Charges Master" },
{ "doctype": "Shipping Rule" },
{ "doctype": "Currency Exchange" },
{
"type": "Section",
"title": "Opening Accounts and Stock",

View File

@@ -39,8 +39,8 @@ def get_ancestors_of(doctype, name):
"""Get ancestor elements of a DocType with a tree structure"""
lft, rgt = webnotes.conn.get_value(doctype, name, ["lft", "rgt"])
result = webnotes.conn.sql_list("""select name from `tab%s`
where lft<%s and rgt>%s""" % (doctype, "%s", "%s"), (lft, rgt))
return result or None
where lft<%s and rgt>%s order by lft desc""" % (doctype, "%s", "%s"), (lft, rgt))
return result or []
@webnotes.whitelist()
def get_price_list_currency(args):