mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-01 12:38:27 +00:00
[webshop] territories in price list, taxes, updates in shopping cart settings
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-06-20 16:00:18",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-06-20 16:01:34",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"istable": 1,
|
||||
"module": "Website",
|
||||
"name": "__common__"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "price_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Price List",
|
||||
"name": "__common__",
|
||||
"options": "Price List",
|
||||
"parent": "Shopping Cart Price List",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"name": "Shopping Cart Price List"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField"
|
||||
}
|
||||
]
|
||||
@@ -2,7 +2,73 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _, msgprint
|
||||
from webnotes.utils import comma_and
|
||||
from webnotes.model.controller import DocListController
|
||||
|
||||
class DocType:
|
||||
class ShoppingCartSetupError(webnotes.ValidationError): pass
|
||||
|
||||
class DocType(DocListController):
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
def validate(self):
|
||||
if self.doc.enabled:
|
||||
self.validate_overlapping_territories("shopping_cart_price_lists", "price_list")
|
||||
self.validate_overlapping_territories("shopping_cart_taxes_and_charges_masters",
|
||||
"sales_taxes_and_charges_master")
|
||||
self.validate_shipping_rules()
|
||||
self.validate_exchange_rates_exist()
|
||||
|
||||
def validate_overlapping_territories(self, parentfield, fieldname):
|
||||
names = [doc.fields(fieldname) for doc in self.doclist.get({"parentfield": parentfield})]
|
||||
doctype = self.meta.get_field(parentfield).options
|
||||
parenttype = self.meta.get_field(fieldname, parentfield=parentfield).options
|
||||
|
||||
if not names:
|
||||
msgprint(_("Please specify at least one") + " " + _(doctype),
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
territory_name = webnotes.conn.sql("""select territory, parent from `tabFor Territory`
|
||||
where parenttype=%s and parent in (%s)""" % ("%s", ", ".join(["%s"]*names)),
|
||||
tuple([parenttype] + names))
|
||||
|
||||
territory_name_map = {}
|
||||
for territory, name in territory_name:
|
||||
territory_name_map.setdefault(territory, []).append(name)
|
||||
|
||||
for territory, names in territory_name_map.items():
|
||||
if len(names) > 1:
|
||||
msgprint(_("Error for") + " " + _(doctype) + ": " + comma_and(names) +
|
||||
" " + _("have a common territory") + ": " + territory,
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
def validate_shipping_rules(self):
|
||||
pass
|
||||
|
||||
def validate_exchange_rates_exist(self):
|
||||
"""check if exchange rates exist for all Price List currencies (to company's currency)"""
|
||||
company_currency = webnotes.conn.get_value("Company", self.doc.company, "default_currency")
|
||||
if not company_currency:
|
||||
msgprint(_("Please specify currency in Company") + ": " + self.doc.company,
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
price_list_currency_map = webnotes.conn.get_values("Price List",
|
||||
[d.price_list for d in self.doclist.get({"parentfield": "shopping_cart_price_lists"})],
|
||||
"currency")
|
||||
|
||||
expected_to_exist = [currency + "-" + company_currency
|
||||
for currency in price_list_currency_map.values()
|
||||
if currency != company_currency]
|
||||
|
||||
exists = webnotes.conn.sql_list("""select name from `tabCurrency Exchange`
|
||||
where name in (%s)""" % (", ".join(["%s"]*len(expected_to_exist)),),
|
||||
tuple(expected_to_exist))
|
||||
|
||||
missing = list(set(expected_to_exist).difference(exists))
|
||||
|
||||
if missing:
|
||||
msgprint(_("Missing Currency Exchange Rates for" + ": " + comma_and(missing)),
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-06-19 15:57:32",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-06-19 16:01:25",
|
||||
"modified": "2013-06-21 12:59:30",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -15,16 +15,11 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Territory",
|
||||
"name": "__common__",
|
||||
"options": "Territory",
|
||||
"parent": "Shopping Cart Settings",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"reqd": 1
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
@@ -43,7 +38,42 @@
|
||||
"name": "Shopping Cart Settings"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField"
|
||||
"doctype": "DocField",
|
||||
"fieldname": "enabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable Shopping Cart"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "default_territory",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Territory",
|
||||
"options": "Territory",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "shopping_cart_price_lists",
|
||||
"fieldtype": "Table",
|
||||
"label": "Shopping Cart Price Lists",
|
||||
"options": "Shopping Cart Price List",
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "shopping_cart_taxes_and_charges_masters",
|
||||
"fieldtype": "Table",
|
||||
"label": "Shopping Cart Taxes and Charges Masters",
|
||||
"options": "Shopping Cart Taxes and Charges Master",
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"label": "Company",
|
||||
"options": "Company",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm"
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-06-20 16:57:03",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-06-20 16:57:03",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"istable": 1,
|
||||
"module": "Website",
|
||||
"name": "__common__"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "sales_taxes_and_charges_master",
|
||||
"fieldtype": "Link",
|
||||
"label": "Tax Master",
|
||||
"name": "__common__",
|
||||
"options": "Sales Taxes and Charges Master",
|
||||
"parent": "Shopping Cart Taxes and Charges Master",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"name": "Shopping Cart Taxes and Charges Master"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user