From 307978fea956c9bddaf0dc01dc01f0affe7eb71b Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 23 Sep 2015 15:43:09 +0530 Subject: [PATCH] [test-fixes] --- erpnext/accounts/doctype/tax_rule/tax_rule.py | 6 ++- erpnext/accounts/party.py | 2 +- erpnext/shopping_cart/cart.py | 20 +++------- erpnext/shopping_cart/test_shopping_cart.py | 37 ++++++++++++++----- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py index 1e306e9eb7b..bcbd5595d40 100644 --- a/erpnext/accounts/doctype/tax_rule/tax_rule.py +++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.model import default_fields from frappe.model.document import Document from frappe.utils import cstr @@ -121,7 +120,10 @@ def get_tax_template(posting_date, args): conditions = [] for key, value in args.iteritems(): - conditions.append("ifnull({0}, '') in ('', '{1}')".format(key, frappe.db.escape(cstr(value)))) + if key in "use_for_shopping_cart": + conditions.append("use_for_shopping_cart = {0}".format(1 if value else 0)) + else: + conditions.append("ifnull({0}, '') in ('', '{1}')".format(key, frappe.db.escape(cstr(value)))) matching = frappe.db.sql("""select * from `tabTax Rule` where {0}""".format(" and ".join(conditions)), as_dict = True) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 9596b440741..baa237e07d1 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -280,7 +280,7 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup billing_address=None, shipping_address=None, use_for_shopping_cart=None): from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details args = { - party_type: party, + party_type.lower(): party, "customer_group": customer_group, "supplier_type": supplier_type, "company": company diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index b6acf20d4e7..c4f3db03951 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -73,10 +73,6 @@ def update_cart(item_code, qty, with_items=False): qty = flt(qty) if qty == 0: quotation.set("items", quotation.get("items", {"item_code": ["!=", item_code]})) - if not quotation.get("items") and \ - not quotation.get("__islocal"): - quotation.__delete = True - else: quotation_items = quotation.get("items", {"item_code": item_code}) if not quotation_items: @@ -90,16 +86,11 @@ def update_cart(item_code, qty, with_items=False): apply_cart_settings(quotation=quotation) - if hasattr(quotation, "__delete"): - frappe.delete_doc("Quotation", quotation.name, ignore_permissions=True) - quotation = _get_cart_quotation() - else: - quotation.flags.ignore_permissions = True - quotation.save() + quotation.flags.ignore_permissions = True + quotation.save() set_cart_count(quotation) - if with_items: context = get_cart_quotation(quotation) return { @@ -160,11 +151,12 @@ def _get_cart_quotation(party=None): if not party: party = get_customer() - quotation = frappe.db.get_value("Quotation", - {party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0}) + quotation = frappe.get_all("Quotation", fields=["name"], filters= + {party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0}, + order_by="modified desc", limit_page_length=1) if quotation: - qdoc = frappe.get_doc("Quotation", quotation) + qdoc = frappe.get_doc("Quotation", quotation[0].name) else: qdoc = frappe.get_doc({ "doctype": "Quotation", diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py index 61536acc87e..41f7442b7c9 100644 --- a/erpnext/shopping_cart/test_shopping_cart.py +++ b/erpnext/shopping_cart/test_shopping_cart.py @@ -52,11 +52,14 @@ class TestShoppingCart(unittest.TestCase): # add first item update_cart("_Test Item", 1) + quotation = self.test_get_cart_customer() + self.assertEquals(quotation.get("items")[0].item_code, "_Test Item") self.assertEquals(quotation.get("items")[0].qty, 1) self.assertEquals(quotation.get("items")[0].amount, 10) + # add second item update_cart("_Test Item 2", 1) quotation = self.test_get_cart_customer() @@ -86,6 +89,7 @@ class TestShoppingCart(unittest.TestCase): # remove first item update_cart("_Test Item", 0) quotation = self.test_get_cart_customer() + self.assertEquals(quotation.get("items")[0].item_code, "_Test Item 2") self.assertEquals(quotation.get("items")[0].qty, 1) self.assertEquals(quotation.get("items")[0].amount, 20) @@ -149,16 +153,29 @@ class TestShoppingCart(unittest.TestCase): def enable_shopping_cart(self): settings = frappe.get_doc("Shopping Cart Settings", "Shopping Cart Settings") - if settings.get("price_lists"): - settings.enabled = 1 - else: - settings.update({ - "enabled": 1, - "company": "_Test Company", - "default_customer_group": "_Test Customer Group", - "quotation_series": "_T-Quotation-", - "price_list": "_Test Price List India" - }) + settings.update({ + "enabled": 1, + "company": "_Test Company", + "default_customer_group": "_Test Customer Group", + "quotation_series": "_T-Quotation-", + "price_list": "_Test Price List India" + }) + + # insert item price + if not frappe.db.get_value("Item Price", {"price_list": "_Test Price List India", + "item_code": "_Test Item"}): + frappe.get_doc({ + "doctype": "Item Price", + "price_list": "_Test Price List India", + "item_code": "_Test Item", + "price_list_rate": 10 + }).insert() + frappe.get_doc({ + "doctype": "Item Price", + "price_list": "_Test Price List India", + "item_code": "_Test Item 2", + "price_list_rate": 20 + }).insert() settings.save() frappe.local.shopping_cart_settings = None