[test-fixes]
This commit is contained in:
parent
06ad308ca1
commit
307978fea9
@ -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,7 +120,10 @@ def get_tax_template(posting_date, args):
|
|||||||
conditions = []
|
conditions = []
|
||||||
|
|
||||||
for key, value in args.iteritems():
|
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`
|
matching = frappe.db.sql("""select * from `tabTax Rule`
|
||||||
where {0}""".format(" and ".join(conditions)), as_dict = True)
|
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):
|
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
|
||||||
|
@ -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"):
|
quotation.flags.ignore_permissions = True
|
||||||
frappe.delete_doc("Quotation", quotation.name, ignore_permissions=True)
|
quotation.save()
|
||||||
quotation = _get_cart_quotation()
|
|
||||||
else:
|
|
||||||
quotation.flags.ignore_permissions = True
|
|
||||||
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",
|
||||||
|
@ -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,16 +153,29 @@ 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.update({
|
||||||
settings.enabled = 1
|
"enabled": 1,
|
||||||
else:
|
"company": "_Test Company",
|
||||||
settings.update({
|
"default_customer_group": "_Test Customer Group",
|
||||||
"enabled": 1,
|
"quotation_series": "_T-Quotation-",
|
||||||
"company": "_Test Company",
|
"price_list": "_Test Price List India"
|
||||||
"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()
|
settings.save()
|
||||||
frappe.local.shopping_cart_settings = None
|
frappe.local.shopping_cart_settings = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user