[test-fixes]
This commit is contained in:
parent
06ad308ca1
commit
307978fea9
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user