[webshop] territories in price list, taxes, updates in shopping cart settings

This commit is contained in:
Anand Doshi
2013-06-21 17:55:31 +05:30
parent d52b03a8cc
commit 61a2f68bc6
33 changed files with 462 additions and 137 deletions

View File

@@ -19,4 +19,4 @@ import webnotes
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
self.doc, self.doclist = d, dl

View File

@@ -0,0 +1,19 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import webnotes
from webnotes import _, msgprint
from webnotes.model.controller import DocListController
class DocType(DocListController):
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
def autoname(self):
self.doc.name = self.doc.from_currency + "-" + self.doc.to_currency
def validate(self):
self.validate_value("exchange_rate", ">", 0)
if self.doc.from_currency == self.doc.to_currency:
msgprint(_("From Currency and To Currency cannot be same"), raise_exception=True)

View File

@@ -0,0 +1,50 @@
[
{
"creation": "2013-06-20 15:40:29",
"docstatus": 0,
"modified": "2013-06-20 15:40:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"allow_import": 1,
"description": "Specify Exchange Rate to convert one currency into another",
"doctype": "DocType",
"document_type": "Master",
"module": "Setup",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Currency Exchange",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
"reqd": 1
},
{
"doctype": "DocType",
"name": "Currency Exchange"
},
{
"doctype": "DocField",
"fieldname": "from_currency",
"fieldtype": "Link",
"label": "From Currency",
"options": "Currency"
},
{
"doctype": "DocField",
"fieldname": "to_currency",
"fieldtype": "Link",
"label": "To Currency",
"options": "Currency"
},
{
"doctype": "DocField",
"fieldname": "exchange_rate",
"fieldtype": "Float",
"label": "Exchange Rate"
}
]

View File

View File

@@ -1,13 +1,12 @@
[
{
"creation": "2013-04-29 18:24:32",
"creation": "2013-06-20 12:48:38",
"docstatus": 0,
"modified": "2013-04-29 18:24:32",
"modified": "2013-06-20 12:48:38",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"autoname": "PLCNTRY-.#####",
"doctype": "DocType",
"istable": 1,
"module": "Setup",
@@ -15,12 +14,12 @@
},
{
"doctype": "DocField",
"fieldname": "country",
"fieldname": "territory",
"fieldtype": "Link",
"label": "Country",
"label": "Territory",
"name": "__common__",
"options": "Country",
"parent": "Price List Country",
"options": "Territory",
"parent": "For Territory",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
@@ -28,7 +27,7 @@
},
{
"doctype": "DocType",
"name": "Price List Country"
"name": "For Territory"
},
{
"doctype": "DocField"

View File

@@ -17,7 +17,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, _
from webnotes.utils import cint, comma_or
from webnotes.utils import comma_or
from webnotes.model.controller import DocListController
class DocType(DocListController):
@@ -26,33 +26,10 @@ class DocType(DocListController):
where price_list_name=%s""", self.doc.name, as_dict=True, update={"doctype": "Item Price"}))
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)
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)
self.validate_use_for_website()
def validate_use_for_website(self):
if self.doc.use_for_website:
if self.doc.valid_for_all_countries:
if webnotes.conn.sql("""select name from `tabPrice List` where use_for_website=1
and valid_for_all_countries=1 and name!=%s""", self.doc.name):
webnotes.msgprint(_("Error: Another Price List already exists that is used for website and is valid for all countries."),
raise_exception=True)
elif self.doclist.get({"parentfield": "valid_for_countries"}):
for d in self.doclist.get({"parentfield": "valid_for_countries"}):
if webnotes.conn.sql("""select country from `tabPrice List Country` plc, `tabPrice List` pl
where plc.parent=pl.name and pl.use_for_website=1 and
ifnull(valid_for_all_countries, 0)=0 and country=%s and pl.name!=%s""",
(d.country, self.doc.name)):
webnotes.msgprint(_("Error: Another Price List already exists that is used for website and is valid for country")
+ ": " + d.country, raise_exception=True)
def on_trash(self):
webnotes.conn.sql("""delete from `tabItem Price` where price_list_name = %s""",
self.doc.name)

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-25 11:35:09",
"docstatus": 0,
"modified": "2013-06-19 15:24:23",
"modified": "2013-06-20 12:53:10",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -60,13 +60,6 @@
"options": "Currency",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "conversion_rate",
"fieldtype": "Float",
"label": "Conversion Rate",
"reqd": 1
},
{
"default": "Selling",
"doctype": "DocField",
@@ -76,31 +69,19 @@
"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",
"description": "Specify a list of Territories, for which, this Price List is valid",
"doctype": "DocField",
"fieldname": "valid_for_all_countries",
"fieldtype": "Check",
"label": "Valid for all countries"
},
{
"description": "Or specify a list of Countries, for which, this Price List is valid",
"doctype": "DocField",
"fieldname": "valid_for_countries",
"fieldname": "valid_for_territories",
"fieldtype": "Table",
"label": "Valid for the following countries",
"options": "Price List Country"
"label": "Valid for Territories",
"options": "For Territory",
"reqd": 1
},
{
"doctype": "DocField",

View File

@@ -5,7 +5,6 @@ test_records = [
"currency": "INR",
"valid_for_all_countries": 1,
"buying_or_selling": "Selling",
"use_for_website": 1,
"conversion_rate": 1.0
}]
]

View File

@@ -1 +0,0 @@
Countries where parent Price List is valid.

View File

@@ -64,7 +64,6 @@ class DocType:
# enable default currency
webnotes.conn.set_value("Currency", args.get("currency"), "enabled", 1)
def_args = {
'current_fiscal_year':curr_fiscal_year,
@@ -91,6 +90,8 @@ class DocType:
cp_args[k] = args[k]
self.set_cp_defaults(**cp_args)
create_territories()
self.create_feed_and_todo()
@@ -102,9 +103,10 @@ class DocType:
import webnotes.utils
user_fullname = (args.get('first_name') or '') + (args.get('last_name')
and (" " + args.get('last_name')) or '')
webnotes.conn.commit()
return {'sys_defaults': webnotes.utils.get_defaults(), 'user_fullname': user_fullname}
def create_feed_and_todo(self):
"""update activty feed and create todo for creation of item, customer, vendor"""
import home
@@ -245,4 +247,19 @@ def add_all_roles_to(name):
if role[0] not in ["Administrator", "Guest", "All", "Customer", "Supplier", "Partner"]:
d = profile.addchild("userroles", "UserRole")
d.role = role[0]
d.insert()
d.insert()
def create_territories():
"""create two default territories, one for home country and one named Rest of the World"""
from setup.utils import get_root_of
country = webnotes.conn.get_value("Control Panel", None, "country")
root_territory = get_root_of("Territory")
for name in (country, "Rest Of The World"):
if not webnotes.conn.exists("Territory", name):
webnotes.bean({
"doctype": "Territory",
"territory_name": name,
"parent_territory": root_territory,
"is_group": "No"
}).insert()

View File

@@ -29,6 +29,19 @@ def get_company_currency(company):
return currency
def get_root_of(doctype):
"""Get root element of a DocType with a tree structure"""
result = webnotes.conn.sql_list("""select name from `tab%s`
where lft=1 and rgt=(select max(rgt) from `tab%s`)""" % (doctype, doctype))
return result[0] if result else None
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
@webnotes.whitelist()
def get_price_list_currency(args):
"""