From e6f7ac961fa3ef1c25d2bf9dc9839a340432e435 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 13 Jul 2015 16:23:42 +0530 Subject: [PATCH] [fix] Add to Cart visibility, Customer's Price List in Shopping Cart and Address creation from Shopping Cart --- erpnext/change_log/current/shopping_cart.md | 3 +++ erpnext/shopping_cart/cart.py | 19 +++++++++++++++++-- .../shopping_cart_settings.py | 4 ---- erpnext/shopping_cart/product.py | 8 ++++---- erpnext/shopping_cart/utils.py | 2 +- erpnext/templates/includes/cart.js | 4 ++-- erpnext/templates/pages/cart.html | 4 ++-- 7 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 erpnext/change_log/current/shopping_cart.md diff --git a/erpnext/change_log/current/shopping_cart.md b/erpnext/change_log/current/shopping_cart.md new file mode 100644 index 0000000000..77a5e5d5fa --- /dev/null +++ b/erpnext/change_log/current/shopping_cart.md @@ -0,0 +1,3 @@ +- Fixed inconsistent visibility of 'Add to Cart' button +- Use Customer's Price List in Shopping Cart if found +- Fixed Address creation from Shopping Cart diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 18bdba60a5..cfba98b4ab 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -7,6 +7,7 @@ from frappe import throw, _ import frappe.defaults from frappe.utils import cint, flt, get_fullname, fmt_money, cstr from erpnext.utilities.doctype.address.address import get_address_display +from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings from frappe.utils.nestedset import get_root_of class WebsitePriceListMissingError(frappe.ValidationError): pass @@ -162,7 +163,7 @@ def _get_cart_quotation(party=None): else: qdoc = frappe.get_doc({ "doctype": "Quotation", - "naming_series": frappe.defaults.get_user_default("shopping_cart_quotation_series") or "QTN-CART-", + "naming_series": get_shopping_cart_settings().quotation_series or "QTN-CART-", "quotation_to": party.doctype, "company": frappe.db.get_value("Shopping Cart Settings", None, "company"), "order_type": "Shopping Cart", @@ -236,7 +237,9 @@ def apply_cart_settings(party=None, quotation=None): def set_price_list_and_rate(quotation, cart_settings, billing_territory): """set price list based on billing territory""" - quotation.selling_price_list = cart_settings.get_price_list(billing_territory) + + _set_price_list(quotation, cart_settings, billing_territory) + # reset values quotation.price_list_currency = quotation.currency = \ quotation.plc_conversion_rate = quotation.conversion_rate = None @@ -249,6 +252,18 @@ def set_price_list_and_rate(quotation, cart_settings, billing_territory): # set it in cookies for using in product page frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list) +def _set_price_list(quotation, cart_settings, billing_territory): + # check if customer price list exists + selling_price_list = None + if quotation.customer: + selling_price_list = frappe.db.get_value("Customer", quotation.customer, "default_price_list") + + # else check for territory based price list + if not selling_price_list: + selling_price_list = cart_settings.get_price_list(billing_territory) + + quotation.selling_price_list = selling_price_list + def set_taxes(quotation, cart_settings, billing_territory): """set taxes based on billing territory""" quotation.taxes_and_charges = cart_settings.get_tax_master(billing_territory) diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py index cdfe0fd8dc..8fbf4a430e 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py @@ -23,10 +23,6 @@ class ShoppingCartSettings(Document): self.validate_tax_masters() self.validate_exchange_rates_exist() - def on_update(self): - frappe.db.set_default("shopping_cart_enabled", self.get("enabled") or 0) - frappe.db.set_default("shopping_cart_quotation_series", self.get("quotation_series")) - def validate_overlapping_territories(self, parentfield, fieldname): # for displaying message doctype = self.meta.get_field(parentfield).options diff --git a/erpnext/shopping_cart/product.py b/erpnext/shopping_cart/product.py index 85faa032ea..d7795d2f97 100644 --- a/erpnext/shopping_cart/product.py +++ b/erpnext/shopping_cart/product.py @@ -4,19 +4,19 @@ from __future__ import unicode_literals import frappe -from frappe.utils import cint, fmt_money, cstr +from frappe.utils import cint, fmt_money from erpnext.shopping_cart.cart import _get_cart_quotation -from urllib import unquote +from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled @frappe.whitelist(allow_guest=True) def get_product_info(item_code): """get product price / stock info""" - if not cint(frappe.db.get_default("shopping_cart_enabled")): + if not is_cart_enabled(): return {} cart_quotation = _get_cart_quotation() - price_list = cstr(unquote(frappe.local.request.cookies.get("selling_price_list"))) + price_list = cart_quotation.selling_price_list warehouse = frappe.db.get_value("Item", item_code, "website_warehouse") if warehouse: diff --git a/erpnext/shopping_cart/utils.py b/erpnext/shopping_cart/utils.py index 09bfa4329a..7794a8fb9f 100644 --- a/erpnext/shopping_cart/utils.py +++ b/erpnext/shopping_cart/utils.py @@ -9,7 +9,7 @@ import frappe.defaults from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled def show_cart_count(): - if (frappe.db.get_default("shopping_cart_enabled") and + if (is_cart_enabled() and frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"): return True diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index b6f36e67a8..d5956f9912 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -32,11 +32,11 @@ $.extend(shopping_cart, { }); $("#cart-add-shipping-address").on("click", function() { - window.location.href = "address?address_fieldname=shipping_address_name"; + window.location.href = "addresses"; }); $("#cart-add-billing-address").on("click", function() { - window.location.href = "address?address_fieldname=customer_address"; + window.location.href = "address"; }); $(".btn-place-order").on("click", function() { diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html index 2ffdd5e68d..e4e4a6a6c1 100644 --- a/erpnext/templates/pages/cart.html +++ b/erpnext/templates/pages/cart.html @@ -35,14 +35,14 @@
+ {{ _("Manage Addresses") }}

Billing Address

+ {{ _("Manage Addresses") }}