From 72fbf902d7167cba5b3d150cac4ecd8d8acadb30 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 17 Sep 2015 18:29:44 +0530 Subject: [PATCH] [cleanup] added single price list for shopping cart, removed Applicable Territory --- .../sales_taxes_and_charges_template.json | 27 +---- .../sales_taxes_and_charges_template.py | 5 - .../doctype/shipping_rule/shipping_rule.json | 63 ++++++----- .../doctype/shipping_rule/shipping_rule.py | 3 + erpnext/accounts/party.py | 19 +++- erpnext/patches.txt | 2 + .../v6_3}/__init__.py | 0 .../v6_3/convert_applicable_territory.py | 17 +++ .../applicable_territory.json | 50 --------- .../applicable_territory.py | 12 --- erpnext/shopping_cart/cart.py | 71 ++++++------ .../shopping_cart_price_list/__init__.py | 0 .../shopping_cart_price_list.json | 49 --------- .../shopping_cart_price_list.py | 12 --- .../shopping_cart_settings.json | 101 ++---------------- .../shopping_cart_settings.py | 11 +- .../test_shopping_cart_settings.py | 42 ++------ erpnext/shopping_cart/test_shopping_cart.py | 32 +++--- erpnext/templates/includes/cart.js | 4 +- 19 files changed, 149 insertions(+), 371 deletions(-) rename erpnext/{setup/doctype/applicable_territory => patches/v6_3}/__init__.py (100%) create mode 100644 erpnext/patches/v6_3/convert_applicable_territory.py delete mode 100644 erpnext/setup/doctype/applicable_territory/applicable_territory.json delete mode 100644 erpnext/setup/doctype/applicable_territory/applicable_territory.py delete mode 100644 erpnext/shopping_cart/doctype/shopping_cart_price_list/__init__.py delete mode 100644 erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.json delete mode 100644 erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.py diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json index 9a3a4580f5..d01866e447 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json @@ -164,29 +164,6 @@ "search_index": 0, "set_only_once": 0, "unique": 0 - }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "description": "Specify a list of Territories, for which, this Taxes Master is valid", - "fieldname": "territories", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Valid for Territories", - "no_copy": 0, - "options": "Applicable Territory", - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 } ], "hide_heading": 0, @@ -198,7 +175,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-09-11 12:19:46.488710", + "modified": "2015-09-17 07:09:28.797959", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Taxes and Charges Template", @@ -206,7 +183,7 @@ "permissions": [ { "amend": 0, - "apply_user_permissions": 0, + "apply_user_permissions": 1, "cancel": 0, "create": 0, "delete": 0, diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py index b36287b691..886400e5f9 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax -from frappe.utils.nestedset import get_root_of class SalesTaxesandChargesTemplate(Document): def validate(self): @@ -20,10 +19,6 @@ def valdiate_taxes_and_charges_template(doc): where ifnull(is_default,0) = 1 and name != %s and company = %s""".format(doc.doctype), (doc.name, doc.company)) - if doc.meta.get_field("territories"): - if not doc.territories: - doc.append("territories", {"territory": get_root_of("Territory") }) - for tax in doc.get("taxes"): validate_taxes_and_charges(tax) validate_inclusive_tax(tax, doc) diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.json b/erpnext/accounts/doctype/shipping_rule/shipping_rule.json index 62d5cb8e0c..be65baf9de 100644 --- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.json +++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.json @@ -35,14 +35,16 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", + "fieldname": "disabled", + "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, + "label": "Disabled", "no_copy": 0, "permlevel": 0, + "precision": "", "print_hide": 0, "read_only": 0, "report_hide": 0, @@ -78,6 +80,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "eval:!doc.disabled", "fieldname": "rule_conditions_section", "fieldtype": "Section Break", "hidden": 0, @@ -121,12 +124,14 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "eval:!doc.disabled", "fieldname": "section_break_6", "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, + "label": "Valid for Countries", "no_copy": 0, "permlevel": 0, "print_hide": 0, @@ -141,6 +146,29 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "fieldname": "worldwide_shipping", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Worldwide Shipping", + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "depends_on": "eval:!doc.worldwide_shipping", "fieldname": "countries", "fieldtype": "Table", "hidden": 0, @@ -164,8 +192,9 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "column_break_8", - "fieldtype": "Column Break", + "depends_on": "eval:!doc.disabled", + "fieldname": "section_break_10", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, @@ -206,8 +235,8 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "section_break_10", - "fieldtype": "Section Break", + "fieldname": "column_break_12", + "fieldtype": "Column Break", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, @@ -244,26 +273,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "column_break_12", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "no_copy": 0, - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_on_submit": 0, "bold": 0, @@ -296,7 +305,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-09-17 06:44:05.127516", + "modified": "2015-09-17 08:30:57.226342", "modified_by": "Administrator", "module": "Accounts", "name": "Shipping Rule", diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py index dbd121a45e..a2ee820b48 100644 --- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py @@ -22,6 +22,9 @@ class ShippingRule(Document): self.sort_shipping_rule_conditions() self.validate_overlapping_shipping_rule_conditions() + if self.worldwide_shipping: + self.countries = [] + def validate_from_to_values(self): zero_to_values = [] diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 1a6e85bf77..9596b44074 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -103,6 +103,19 @@ def set_other_values(out, party, party_type): if party.get("default_" + f): out[f] = party.get("default_" + f) +def get_default_price_list(party): + """Return default price list for party (Document object)""" + if party.default_price_list: + return party.default_price_list + + if party.doctype == "Customer": + price_list = frappe.db.get_value("Customer Group", + party.customer_group, "default_price_list") + if price_list: + return price_list + + return None + def set_price_list(out, party, party_type, given_price_list): # price list price_list = filter(None, get_user_permissions().get("Price List", [])) @@ -110,11 +123,7 @@ def set_price_list(out, party, party_type, given_price_list): price_list = price_list[0] if len(price_list)==1 else None if not price_list: - price_list = party.default_price_list - - if not price_list and party_type=="Customer": - price_list = frappe.db.get_value("Customer Group", - party.customer_group, "default_price_list") + price_list = get_default_price_list(party) if not price_list: price_list = given_price_list diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e20aab0b2e..51356e5ed9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -209,3 +209,5 @@ erpnext.patches.v6_0.fix_planned_qty erpnext.patches.v6_0.multi_currency erpnext.patches.v6_2.remove_newsletter_duplicates erpnext.patches.v6_2.fix_missing_default_taxes_and_lead +erpnext.patches.v5_8.tax_rule +erpnext.patches.v6_3.convert_applicable_territory diff --git a/erpnext/setup/doctype/applicable_territory/__init__.py b/erpnext/patches/v6_3/__init__.py similarity index 100% rename from erpnext/setup/doctype/applicable_territory/__init__.py rename to erpnext/patches/v6_3/__init__.py diff --git a/erpnext/patches/v6_3/convert_applicable_territory.py b/erpnext/patches/v6_3/convert_applicable_territory.py new file mode 100644 index 0000000000..3054ecc879 --- /dev/null +++ b/erpnext/patches/v6_3/convert_applicable_territory.py @@ -0,0 +1,17 @@ +import frappe + +def execute(): + # for price list + countries = frappe.db.sql_list("select name from tabCountry") + + for doctype in ("Price List", "Shipping Rule"): + for at in frappe.db.sql("""select name, parent, territory from `tabApplicable Territory` where + parenttype = %s """, doctype, as_dict=True): + if at.territory in countries: + parent = frappe.get_doc(doctype, at.parent) + if not parent.countries: + parent.append("countries", {"country": at.territory}) + parent.save() + + + frappe.delete_doc("DocType", "Applicable Territory") diff --git a/erpnext/setup/doctype/applicable_territory/applicable_territory.json b/erpnext/setup/doctype/applicable_territory/applicable_territory.json deleted file mode 100644 index 6fc549faa6..0000000000 --- a/erpnext/setup/doctype/applicable_territory/applicable_territory.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "allow_copy": 0, - "allow_import": 0, - "allow_rename": 0, - "creation": "2013-06-20 12:48:38", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "fields": [ - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "description": "", - "fieldname": "territory", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 1, - "label": "Territory", - "no_copy": 0, - "options": "Territory", - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 1, - "in_create": 0, - "in_dialog": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "modified": "2015-01-01 14:29:58.724652", - "modified_by": "Administrator", - "module": "Setup", - "name": "Applicable Territory", - "owner": "Administrator", - "permissions": [], - "read_only": 0, - "read_only_onload": 0 -} \ No newline at end of file diff --git a/erpnext/setup/doctype/applicable_territory/applicable_territory.py b/erpnext/setup/doctype/applicable_territory/applicable_territory.py deleted file mode 100644 index 5e0ab4092a..0000000000 --- a/erpnext/setup/doctype/applicable_territory/applicable_territory.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# MIT License. See license.txt - -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe - -from frappe.model.document import Document - -class ApplicableTerritory(Document): - pass \ No newline at end of file diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 0d28406f06..74d9e64436 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -131,8 +131,11 @@ def update_cart_address(address_fieldname, address_name): quotation.flags.ignore_permissions = True quotation.save() - return frappe.render_template("templates/includes/cart/cart_address.html", - get_cart_quotation(quotation)) + context = get_cart_quotation(quotation) + return { + "taxes": frappe.render_template("templates/includes/order/order_taxes.html", + context), + } def guess_territory(): territory = None @@ -224,21 +227,19 @@ def apply_cart_settings(party=None, quotation=None): quotation = _get_cart_quotation(party) cart_settings = frappe.get_doc("Shopping Cart Settings") - billing_territory = get_address_territory(quotation.customer_address) or \ - party.territory or get_root_of("Territory") - set_price_list_and_rate(quotation, cart_settings, billing_territory) + set_price_list_and_rate(quotation, cart_settings) quotation.run_method("calculate_taxes_and_totals") - set_taxes(quotation, cart_settings, billing_territory) + set_taxes(quotation, cart_settings) _apply_shipping_rule(party, quotation, cart_settings) -def set_price_list_and_rate(quotation, cart_settings, billing_territory): +def set_price_list_and_rate(quotation, cart_settings): """set price list based on billing territory""" - _set_price_list(quotation, cart_settings, billing_territory) + _set_price_list(quotation, cart_settings) # reset values quotation.price_list_currency = quotation.currency = \ @@ -252,24 +253,29 @@ 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): +def _set_price_list(quotation, cart_settings): + """Set price list based on customer or shopping cart default""" + if quotation.selling_price_list: + return + # 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") + from erpnext.accounts.party import get_default_price_list + selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.customer)) # else check for territory based price list if not selling_price_list: - selling_price_list = cart_settings.get_price_list(billing_territory) + selling_price_list = cart_settings.price_list quotation.selling_price_list = selling_price_list -def set_taxes(quotation, cart_settings, billing_territory): +def set_taxes(quotation, cart_settings): """set taxes based on billing territory""" from erpnext.accounts.party import set_taxes - + customer_group = frappe.db.get_value("Customer", quotation.customer, "customer_group") - + quotation.taxes_and_charges = set_taxes(quotation.customer, "Customer", \ quotation.transaction_date, quotation.company, customer_group, None, \ quotation.customer_address, quotation.shipping_address_name, 1) @@ -331,38 +337,39 @@ def apply_shipping_rule(shipping_rule): return get_cart_quotation(quotation) def _apply_shipping_rule(party=None, quotation=None, cart_settings=None): - shipping_rules = get_shipping_rules(party, quotation, cart_settings) + if not quotation.shipping_rule: + shipping_rules = get_shipping_rules(quotation, cart_settings) - if not shipping_rules: - return + if not shipping_rules: + return - elif quotation.shipping_rule not in shipping_rules: - quotation.shipping_rule = shipping_rules[0] + elif quotation.shipping_rule not in shipping_rules: + quotation.shipping_rule = shipping_rules[0] - quotation.run_method("apply_shipping_rule") - quotation.run_method("calculate_taxes_and_totals") + if quotation.shipping_rule: + quotation.run_method("apply_shipping_rule") + quotation.run_method("calculate_taxes_and_totals") def get_applicable_shipping_rules(party=None, quotation=None): - shipping_rules = get_shipping_rules(party, quotation) + shipping_rules = get_shipping_rules(quotation) if shipping_rules: rule_label_map = frappe.db.get_values("Shipping Rule", shipping_rules, "label") # we need this in sorted order as per the position of the rule in the settings page return [[rule, rule_label_map.get(rule)] for rule in shipping_rules] -def get_shipping_rules(party=None, quotation=None, cart_settings=None): - if not party: - party = get_lead_or_customer() +def get_shipping_rules(quotation=None, cart_settings=None): if not quotation: quotation = _get_cart_quotation() - if not cart_settings: - cart_settings = frappe.get_doc("Shopping Cart Settings") - # set shipping rule based on shipping territory - shipping_territory = get_address_territory(quotation.shipping_address_name) or \ - party.territory - - shipping_rules = cart_settings.get_shipping_rules(shipping_territory) + shipping_rules = [] + if quotation.shipping_address_name: + country = frappe.db.get_value("Address", quotation.shipping_address_name, "country") + if country: + shipping_rules = frappe.db.sql_list("""select distinct sr.name + from `tabShipping Rule Country` src, `tabShipping Rule` sr + where src.country = %s and + sr.disabled != 1 and sr.name = src.parent""", country) return shipping_rules diff --git a/erpnext/shopping_cart/doctype/shopping_cart_price_list/__init__.py b/erpnext/shopping_cart/doctype/shopping_cart_price_list/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.json b/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.json deleted file mode 100644 index e91731e8b3..0000000000 --- a/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "allow_copy": 0, - "allow_import": 0, - "allow_rename": 0, - "creation": "2013-06-20 16:00:18", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "fields": [ - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "selling_price_list", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 1, - "label": "Price List", - "no_copy": 0, - "options": "Price List", - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 1, - "in_create": 0, - "in_dialog": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "modified": "2013-12-20 19:30:47", - "modified_by": "Administrator", - "module": "Shopping Cart", - "name": "Shopping Cart Price List", - "owner": "Administrator", - "permissions": [], - "read_only": 0, - "read_only_onload": 0 -} \ No newline at end of file diff --git a/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.py b/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.py deleted file mode 100644 index 53c38d01a3..0000000000 --- a/erpnext/shopping_cart/doctype/shopping_cart_price_list/shopping_cart_price_list.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe - -from frappe.model.document import Document - -class ShoppingCartPriceList(Document): - pass \ No newline at end of file diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json index 881ff4e377..fbc9ba0220 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json @@ -75,17 +75,17 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "description": "Add / Edit", - "fieldname": "default_territory", + "fieldname": "price_list", "fieldtype": "Link", "hidden": 0, - "ignore_user_permissions": 1, + "ignore_user_permissions": 0, "in_filter": 0, - "in_list_view": 1, - "label": "Default Territory", + "in_list_view": 0, + "label": "Price List", "no_copy": 0, - "options": "Territory", + "options": "Price List", "permlevel": 0, + "precision": "", "print_hide": 0, "read_only": 0, "report_hide": 0, @@ -118,7 +118,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "description": "Add / Edit", + "description": "", "fieldname": "default_customer_group", "fieldtype": "Link", "hidden": 0, @@ -157,91 +157,6 @@ "search_index": 0, "set_only_once": 0, "unique": 0 - }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "section_break_6", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "no_copy": 0, - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "price_lists", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Price Lists", - "no_copy": 0, - "options": "Shopping Cart Price List", - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "column_break_10", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "shipping_rules", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Shipping Rules", - "no_copy": 0, - "options": "Shopping Cart Shipping Rule", - "permlevel": 0, - "print_hide": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 } ], "hide_heading": 0, @@ -253,7 +168,7 @@ "is_submittable": 0, "issingle": 1, "istable": 0, - "modified": "2015-09-11 19:03:54.750937", + "modified": "2015-09-17 07:56:09.176098", "modified_by": "Administrator", "module": "Shopping Cart", "name": "Shopping Cart Settings", 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 a8a4b7653f..4fac3a814d 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 @@ -18,7 +18,6 @@ class ShoppingCartSettings(Document): def validate(self): if self.enabled: - self.validate_tax_masters() self.validate_exchange_rates_exist() def validate_exchange_rates_exist(self): @@ -29,7 +28,7 @@ class ShoppingCartSettings(Document): raise_exception=ShoppingCartSetupError) price_list_currency_map = frappe.db.get_values("Price List", - [d.selling_price_list for d in self.get("price_lists")], + [self.price_list], "currency") # check if all price lists have a currency @@ -52,14 +51,6 @@ class ShoppingCartSettings(Document): msgprint(_("Missing Currency Exchange Rates for {0}").format(comma_and(missing)), raise_exception=ShoppingCartSetupError) - def get_price_list(self, billing_territory): - price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list") - if not (price_list and price_list[0]): - price_list = self.get_name_from_territory(self.default_territory or get_root_of("Territory"), - "price_lists", "selling_price_list") - - return price_list and price_list[0] or None - def validate_tax_rule(self): if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart" : 1}, "name"): frappe.throw(frappe._("Set Tax Rule for shopping cart"), ShoppingCartSetupError) diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py b/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py index b18cece44a..66be927bcc 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py @@ -11,55 +11,29 @@ from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings class TestShoppingCartSettings(unittest.TestCase): def setUp(self): frappe.db.sql("""delete from `tabSingles` where doctype="Shipping Cart Settings" """) - frappe.db.sql("""delete from `tabShopping Cart Price List`""") - frappe.db.sql("""delete from `tabShopping Cart Shipping Rule`""") - + def get_cart_settings(self): return frappe.get_doc({"doctype": "Shopping Cart Settings", "company": "_Test Company"}) - - def test_price_list_territory_overlap(self): - cart_settings = self.get_cart_settings() - - def _add_price_list(price_list): - cart_settings.append("price_lists", { - "doctype": "Shopping Cart Price List", - "selling_price_list": price_list - }) - - for price_list in ("_Test Price List Rest of the World", "_Test Price List India", - "_Test Price List"): - _add_price_list(price_list) - - controller = cart_settings - controller.validate_overlapping_territories("price_lists", "selling_price_list") - - _add_price_list("_Test Price List 2") - - controller = cart_settings - self.assertRaises(ShoppingCartSetupError, controller.validate_overlapping_territories, - "price_lists", "selling_price_list") - - return cart_settings - + def test_exchange_rate_exists(self): frappe.db.sql("""delete from `tabCurrency Exchange`""") - + cart_settings = self.test_price_list_territory_overlap() controller = cart_settings self.assertRaises(ShoppingCartSetupError, controller.validate_exchange_rates_exist) - + from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \ currency_exchange_records frappe.get_doc(currency_exchange_records[0]).insert() controller.validate_exchange_rates_exist() - + def test_tax_rule_validation(self): frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0") frappe.db.commit() - + cart_settings = self.get_cart_settings() - cart_settings.enabled = 1 + cart_settings.enabled = 1 if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart": 1}, "name"): self.assertRaises(ShoppingCartSetupError, cart_settings.validate_tax_rule) - + diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py index bd0b138d45..dc3b4fe2ab 100644 --- a/erpnext/shopping_cart/test_shopping_cart.py +++ b/erpnext/shopping_cart/test_shopping_cart.py @@ -25,7 +25,7 @@ class TestShoppingCart(unittest.TestCase): # test if lead is created and quotation with new lead is fetched quotation = get_quotation() self.assertEquals(quotation.quotation_to, "Lead") - self.assertEquals(frappe.db.get_value("Lead", quotation.lead, "email_id"), + self.assertEquals(frappe.db.get_value("Lead", quotation.lead, "email_id"), "test_cart_user@example.com") self.assertEquals(quotation.customer, None) self.assertEquals(quotation.contact_email, frappe.session.user) @@ -61,7 +61,7 @@ class TestShoppingCart(unittest.TestCase): # remove from cart self.remove_all_items_from_cart() - + # add first item set_item_in_cart("_Test Item", 1) quotation = self.test_get_cart_lead() @@ -109,12 +109,12 @@ class TestShoppingCart(unittest.TestCase): quotation = self.test_get_cart_lead() self.assertEquals(quotation.net_total, 0) self.assertEquals(len(quotation.get("items")), 0) - - - def test_taxe_rule(self): + + + def test_tax_rule(self): self.login_as_customer() quotation = self.create_quotation() - + from erpnext.accounts.party import set_taxes tax_rule_master = set_taxes(quotation.customer, "Customer", \ @@ -123,12 +123,12 @@ class TestShoppingCart(unittest.TestCase): self.assertEquals(quotation.taxes_and_charges, tax_rule_master) self.assertEquals(quotation.total_taxes_and_charges, 1000.0) - + self.remove_test_quotation(quotation) - + def create_quotation(self): quotation = frappe.new_doc("Quotation") - + values = { "doctype": "Quotation", "quotation_to": "Customer", @@ -146,13 +146,13 @@ class TestShoppingCart(unittest.TestCase): "taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1").taxes, "company": "_Test Company" } - + quotation.update(values) - + quotation.insert(ignore_permissions=True) - + return quotation - + def remove_test_quotation(self, quotation): frappe.set_user("Administrator") quotation.delete() @@ -180,7 +180,7 @@ class TestShoppingCart(unittest.TestCase): ]) settings.set("shipping_rules", {"doctype": "Shopping Cart Shipping Rule", "parentfield": "shipping_rules", "shipping_rule": "_Test Shipping Rule - India"}) - + settings.save() frappe.local.shopping_cart_settings = None @@ -239,11 +239,11 @@ class TestShoppingCart(unittest.TestCase): "lead_name": "_Test Website Lead", "phone": "+91 0000000000" }).insert(ignore_permissions=True) - + def remove_all_items_from_cart(self): quotation = get_quotation() quotation.set("items", []) quotation.save(ignore_permissions=True) - + test_dependencies = ["Sales Taxes and Charges Template", "Price List", "Item Price", "Shipping Rule", "Currency Exchange", "Customer Group", "Lead", "Customer", "Contact", "Address", "Item", "Tax Rule"] diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index e6ce25a6a8..cc321579bf 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -33,7 +33,7 @@ $.extend(shopping_cart, { }, callback: function(r) { if(!r.exc) { - $('.cart-addresses').html(r.message); + $(".cart-tax-items").html(r.message.taxes); } } }); @@ -54,12 +54,14 @@ $.extend(shopping_cart, { // bind update button $(".cart-items").on("change", ".cart-qty", function() { var item_code = $(this).attr("data-item-code"); + frappe.freeze(); shopping_cart.update_cart({ item_code: item_code, qty: $(this).val(), with_items: 1, btn: this, callback: function(r) { + frappe.unfreeze(); if(!r.exc) { $(".cart-items").html(r.message.items); $(".cart-tax-items").html(r.message.taxes);