[test-fixes]

This commit is contained in:
Rushabh Mehta 2015-09-23 15:43:09 +05:30
parent 06ad308ca1
commit 307978fea9
4 changed files with 38 additions and 27 deletions

View File

@ -5,7 +5,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
from frappe.model import default_fields
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import cstr from frappe.utils import cstr
@ -121,6 +120,9 @@ def get_tax_template(posting_date, args):
conditions = [] conditions = []
for key, value in args.iteritems(): for key, value in args.iteritems():
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)))) conditions.append("ifnull({0}, '') in ('', '{1}')".format(key, frappe.db.escape(cstr(value))))
matching = frappe.db.sql("""select * from `tabTax Rule` matching = frappe.db.sql("""select * from `tabTax Rule`

View File

@ -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): 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 from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
args = { args = {
party_type: party, party_type.lower(): party,
"customer_group": customer_group, "customer_group": customer_group,
"supplier_type": supplier_type, "supplier_type": supplier_type,
"company": company "company": company

View File

@ -73,10 +73,6 @@ def update_cart(item_code, qty, with_items=False):
qty = flt(qty) qty = flt(qty)
if qty == 0: if qty == 0:
quotation.set("items", quotation.get("items", {"item_code": ["!=", item_code]})) quotation.set("items", quotation.get("items", {"item_code": ["!=", item_code]}))
if not quotation.get("items") and \
not quotation.get("__islocal"):
quotation.__delete = True
else: else:
quotation_items = quotation.get("items", {"item_code": item_code}) quotation_items = quotation.get("items", {"item_code": item_code})
if not quotation_items: if not quotation_items:
@ -90,16 +86,11 @@ def update_cart(item_code, qty, with_items=False):
apply_cart_settings(quotation=quotation) 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.flags.ignore_permissions = True
quotation.save() quotation.save()
set_cart_count(quotation) set_cart_count(quotation)
if with_items: if with_items:
context = get_cart_quotation(quotation) context = get_cart_quotation(quotation)
return { return {
@ -160,11 +151,12 @@ def _get_cart_quotation(party=None):
if not party: if not party:
party = get_customer() party = get_customer()
quotation = frappe.db.get_value("Quotation", quotation = frappe.get_all("Quotation", fields=["name"], filters=
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0}) {party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0},
order_by="modified desc", limit_page_length=1)
if quotation: if quotation:
qdoc = frappe.get_doc("Quotation", quotation) qdoc = frappe.get_doc("Quotation", quotation[0].name)
else: else:
qdoc = frappe.get_doc({ qdoc = frappe.get_doc({
"doctype": "Quotation", "doctype": "Quotation",

View File

@ -52,11 +52,14 @@ class TestShoppingCart(unittest.TestCase):
# add first item # add first item
update_cart("_Test Item", 1) update_cart("_Test Item", 1)
quotation = self.test_get_cart_customer() quotation = self.test_get_cart_customer()
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item") self.assertEquals(quotation.get("items")[0].item_code, "_Test Item")
self.assertEquals(quotation.get("items")[0].qty, 1) self.assertEquals(quotation.get("items")[0].qty, 1)
self.assertEquals(quotation.get("items")[0].amount, 10) self.assertEquals(quotation.get("items")[0].amount, 10)
# add second item # add second item
update_cart("_Test Item 2", 1) update_cart("_Test Item 2", 1)
quotation = self.test_get_cart_customer() quotation = self.test_get_cart_customer()
@ -86,6 +89,7 @@ class TestShoppingCart(unittest.TestCase):
# remove first item # remove first item
update_cart("_Test Item", 0) update_cart("_Test Item", 0)
quotation = self.test_get_cart_customer() quotation = self.test_get_cart_customer()
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item 2") 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].qty, 1)
self.assertEquals(quotation.get("items")[0].amount, 20) self.assertEquals(quotation.get("items")[0].amount, 20)
@ -149,9 +153,6 @@ class TestShoppingCart(unittest.TestCase):
def enable_shopping_cart(self): def enable_shopping_cart(self):
settings = frappe.get_doc("Shopping Cart Settings", "Shopping Cart Settings") settings = frappe.get_doc("Shopping Cart Settings", "Shopping Cart Settings")
if settings.get("price_lists"):
settings.enabled = 1
else:
settings.update({ settings.update({
"enabled": 1, "enabled": 1,
"company": "_Test Company", "company": "_Test Company",
@ -160,6 +161,22 @@ class TestShoppingCart(unittest.TestCase):
"price_list": "_Test Price List India" "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() settings.save()
frappe.local.shopping_cart_settings = None frappe.local.shopping_cart_settings = None