diff --git a/public/js/website_utils.js b/public/js/website_utils.js index 83becc6b0e6..098f8da1887 100644 --- a/public/js/website_utils.js +++ b/public/js/website_utils.js @@ -193,7 +193,8 @@ $.extend(wn.cart, { method: "website.helpers.cart.update_cart", args: { item_code: opts.item_code, - qty: opts.qty + qty: opts.qty, + with_doclist: opts.with_doclist }, btn: opts.btn, callback: function(r) { diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt index 1017221bf67..74a4396aef9 100644 --- a/selling/doctype/quotation/quotation.txt +++ b/selling/doctype/quotation/quotation.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-24 19:29:08", "docstatus": 0, - "modified": "2013-06-05 19:07:51", + "modified": "2013-06-19 15:55:15", "modified_by": "Administrator", "owner": "Administrator" }, @@ -223,7 +223,7 @@ "label": "Order Type", "oldfieldname": "order_type", "oldfieldtype": "Select", - "options": "\nSales\nMaintenance", + "options": "\nSales\nMaintenance\nShopping Cart", "print_hide": 1, "read_only": 0, "reqd": 1, diff --git a/selling/utils.py b/selling/utils.py index 61eab59dfc1..bd04db570e2 100644 --- a/selling/utils.py +++ b/selling/utils.py @@ -134,7 +134,7 @@ def _get_price_list_rate(args, item_bean, meta): base_ref_rate = item_bean.doclist.get({ "parentfield": "ref_rate_details", "price_list_name": args.price_list_name, - "price_list_currency": args.price_list_currency, + "ref_currency": args.price_list_currency, "buying_or_selling": "Selling"}) if not base_ref_rate: diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py index c4feb60a2e1..e6e7b7f61c1 100644 --- a/setup/doctype/price_list/price_list.py +++ b/setup/doctype/price_list/price_list.py @@ -33,6 +33,25 @@ class DocType(DocListController): 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""", diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt index daffecedc30..8115f3d32be 100644 --- a/setup/doctype/price_list/price_list.txt +++ b/setup/doctype/price_list/price_list.txt @@ -2,13 +2,13 @@ { "creation": "2013-01-25 11:35:09", "docstatus": 0, - "modified": "2013-06-14 16:07:25", + "modified": "2013-06-19 15:24:23", "modified_by": "Administrator", "owner": "Administrator" }, { "allow_attach": 0, - "allow_copy": 1, + "allow_copy": 0, "allow_email": 1, "allow_print": 1, "autoname": "field:price_list_name", diff --git a/website/css/website.css b/website/css/website.css index 7efceb2e63e..737d3d0f4ee 100644 --- a/website/css/website.css +++ b/website/css/website.css @@ -117,3 +117,13 @@ a { margin-top: -10px; margin-left: -10px; } + +.hidden-sm-inline { + display: none; +} + +@media (min-width: 768px) { + .hidden-sm-inline { + display: inline; + } +} \ No newline at end of file diff --git a/website/doctype/shopping_cart_settings/__init__.py b/website/doctype/shopping_cart_settings/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.py b/website/doctype/shopping_cart_settings/shopping_cart_settings.py new file mode 100644 index 00000000000..928aa9ff9f2 --- /dev/null +++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.py @@ -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 \ No newline at end of file diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.txt b/website/doctype/shopping_cart_settings/shopping_cart_settings.txt new file mode 100644 index 00000000000..627c1274c6c --- /dev/null +++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.txt @@ -0,0 +1,51 @@ +[ + { + "creation": "2013-06-19 15:57:32", + "docstatus": 0, + "modified": "2013-06-19 16:01:25", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "description": "Default settings for Shopping Cart", + "doctype": "DocType", + "issingle": 1, + "module": "Website", + "name": "__common__" + }, + { + "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 + }, + { + "create": 1, + "doctype": "DocPerm", + "name": "__common__", + "parent": "Shopping Cart Settings", + "parentfield": "permissions", + "parenttype": "DocType", + "permlevel": 0, + "read": 1, + "role": "Website Manager", + "write": 1 + }, + { + "doctype": "DocType", + "name": "Shopping Cart Settings" + }, + { + "doctype": "DocField" + }, + { + "doctype": "DocPerm" + } +] \ No newline at end of file diff --git a/website/helpers/cart.py b/website/helpers/cart.py index b62e0bb7cf8..a24afb57a97 100644 --- a/website/helpers/cart.py +++ b/website/helpers/cart.py @@ -3,16 +3,16 @@ from __future__ import unicode_literals import webnotes -from webnotes import _, msgprint import webnotes.defaults -from webnotes.utils import today, get_fullname +from webnotes.utils import cint, get_fullname, fmt_money class WebsitePriceListMissingError(webnotes.ValidationError): pass @webnotes.whitelist() -def update_cart(item_code, qty): +def update_cart(item_code, qty, with_doclist=0): quotation = _get_cart_quotation() + qty = cint(qty) if qty == 0: quotation.set_doclist(quotation.doclist.get({"item_code": ["!=", item_code]})) else: @@ -30,7 +30,10 @@ def update_cart(item_code, qty): quotation.ignore_permissions = True quotation.save() - return quotation.doc.name + if with_doclist: + return decorate_quotation_doclist(quotation.doclist) + else: + return quotation.doc.name def get_lead_or_customer(): customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, "customer") @@ -45,6 +48,8 @@ def get_lead_or_customer(): "doctype": "Lead", "email_id": webnotes.session.user, "lead_name": get_fullname(webnotes.session.user), + "territory": webnotes.conn.get_value("Shopping Cart Settings", None, "territory") or \ + "All Territories", "status": "Open" # TODO: set something better??? }) lead_bean.ignore_permissions = True @@ -55,8 +60,18 @@ def get_lead_or_customer(): @webnotes.whitelist() def get_cart_quotation(): - return [d.fields for d in _get_cart_quotation(get_lead_or_customer()).doclist] + doclist = _get_cart_quotation(get_lead_or_customer()).doclist + return decorate_quotation_doclist(doclist) +def decorate_quotation_doclist(doclist): + for d in doclist: + if d.item_code: + d.fields.update(webnotes.conn.get_value("Item", d.item_code, + ["website_image", "web_short_description", "page_name"], as_dict=True)) + d.formatted_rate = fmt_money(d.export_rate, currency=doclist[0].currency) + d.formatted_amount = fmt_money(d.export_amount, currency=doclist[0].currency) + + return [d.fields for d in doclist] def _get_cart_quotation(party=None): if not party: @@ -71,7 +86,7 @@ def _get_cart_quotation(party=None): qbean = webnotes.bean({ "doctype": "Quotation", "naming_series": "QTN-CART-", - "quotation_to": "Customer", + "quotation_to": party.doctype, "company": webnotes.defaults.get_user_default("company"), "order_type": "Shopping Cart", "status": "Draft", @@ -97,7 +112,8 @@ def get_price_list_using_geoip(): price_list_name = webnotes.conn.sql("""select parent from `tabPrice List Country` plc where country=%s and exists (select name from `tabPrice List` pl - where use_for_website=1 and pl.name = plc.parent)""", country) + where use_for_website=1 and ifnull(valid_for_all_countries, 0)=0 and + pl.name = plc.parent)""", country) if price_list_name: price_list_name = price_list_name[0][0] diff --git a/website/page/website_home/website_home.js b/website/page/website_home/website_home.js index 71f2f4d2cdf..fb612df11d7 100644 --- a/website/page/website_home/website_home.js +++ b/website/page/website_home/website_home.js @@ -63,6 +63,12 @@ wn.module_page["Website"] = [ "description":wn._("Setup of fonts and background."), doctype:"Style Settings" }, + { + "route":"Form/Shopping Cart Settings", + "label":wn._("Shopping Cart Settings"), + "description":wn._("Setup of Shopping Cart."), + doctype:"Shopping Cart Settings" + }, ] }, { diff --git a/website/templates/html/product_page.html b/website/templates/html/product_page.html index 837b1057021..bf1ecc066b4 100644 --- a/website/templates/html/product_page.html +++ b/website/templates/html/product_page.html @@ -40,12 +40,14 @@
%(web_short_description)s
\ +at %(formatted_rate)s
\ + = %(formatted_amount)s\ +