Shopping cart test fixed
This commit is contained in:
parent
1913d5b366
commit
eca7e22cda
@ -9,6 +9,7 @@ from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# validate stock of each item in Website Warehouse or have a list of possible warehouses in Shopping Cart Settings
|
# validate stock of each item in Website Warehouse or have a list of possible warehouses in Shopping Cart Settings
|
||||||
|
# Below functions are used for test cases
|
||||||
|
|
||||||
def get_quotation(user=None):
|
def get_quotation(user=None):
|
||||||
if not user:
|
if not user:
|
||||||
@ -22,7 +23,8 @@ def get_quotation(user=None):
|
|||||||
"order_type": "Shopping Cart",
|
"order_type": "Shopping Cart",
|
||||||
party.doctype.lower(): party.name,
|
party.doctype.lower(): party.name,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"contact_email": user
|
"contact_email": user,
|
||||||
|
"selling_price_list": "_Test Price List Rest of the World"
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -60,35 +62,11 @@ def set_item_in_cart(item_code, qty, user=None):
|
|||||||
quotation.save(ignore_permissions=True)
|
quotation.save(ignore_permissions=True)
|
||||||
return quotation
|
return quotation
|
||||||
|
|
||||||
def set_address_in_cart(address_fieldname, address, user=None):
|
|
||||||
quotation = get_quotation(user=user)
|
|
||||||
validate_address(quotation, address_fieldname, address)
|
|
||||||
|
|
||||||
if quotation.get(address_fieldname) != address:
|
|
||||||
quotation.set(address_fieldname, address)
|
|
||||||
if address_fieldname=="customer_address":
|
|
||||||
quotation.set("address_display", None)
|
|
||||||
else:
|
|
||||||
quotation.set("shipping_address", None)
|
|
||||||
|
|
||||||
quotation.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def validate_item(item_code):
|
def validate_item(item_code):
|
||||||
item = frappe.db.get_value("Item", item_code, ["item_name", "show_in_website"], as_dict=True)
|
item = frappe.db.get_value("Item", item_code, ["item_name", "show_in_website"], as_dict=True)
|
||||||
if not item.show_in_website:
|
if not item.show_in_website:
|
||||||
frappe.throw(_("{0} cannot be purchased using Shopping Cart").format(item.item_name))
|
frappe.throw(_("{0} cannot be purchased using Shopping Cart").format(item.item_name))
|
||||||
|
|
||||||
def validate_address(quotation, address_fieldname, address):
|
|
||||||
party = get_party(quotation.contact_email)
|
|
||||||
address_doc = frappe.get_doc(address)
|
|
||||||
if address_doc.get(party.doctype.lower()) != party.name:
|
|
||||||
if address_fieldname=="customer_address":
|
|
||||||
frappe.throw(_("Invalid Billing Address"))
|
|
||||||
else:
|
|
||||||
frappe.throw(_("Invalid Shipping Address"))
|
|
||||||
|
|
||||||
def get_party(user):
|
def get_party(user):
|
||||||
def _get_party(user):
|
def _get_party(user):
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
||||||
@ -122,5 +100,4 @@ def guess_territory():
|
|||||||
territory = None
|
territory = None
|
||||||
if frappe.session.get("session_country"):
|
if frappe.session.get("session_country"):
|
||||||
territory = frappe.db.get_value("Territory", frappe.session.get("session_country"))
|
territory = frappe.db.get_value("Territory", frappe.session.get("session_country"))
|
||||||
|
|
||||||
return territory or get_default_territory()
|
return territory or get_default_territory()
|
||||||
|
@ -222,7 +222,6 @@ def apply_cart_settings(party=None, quotation=None):
|
|||||||
quotation = _get_cart_quotation(party)
|
quotation = _get_cart_quotation(party)
|
||||||
|
|
||||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
||||||
|
|
||||||
billing_territory = get_address_territory(quotation.customer_address) or \
|
billing_territory = get_address_territory(quotation.customer_address) or \
|
||||||
party.territory or get_root_of("Territory")
|
party.territory or get_root_of("Territory")
|
||||||
|
|
||||||
@ -237,7 +236,6 @@ def apply_cart_settings(party=None, quotation=None):
|
|||||||
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
||||||
"""set price list based on billing territory"""
|
"""set price list based on billing territory"""
|
||||||
quotation.selling_price_list = cart_settings.get_price_list(billing_territory)
|
quotation.selling_price_list = cart_settings.get_price_list(billing_territory)
|
||||||
|
|
||||||
# reset values
|
# reset values
|
||||||
quotation.price_list_currency = quotation.currency = \
|
quotation.price_list_currency = quotation.currency = \
|
||||||
quotation.plc_conversion_rate = quotation.conversion_rate = None
|
quotation.plc_conversion_rate = quotation.conversion_rate = None
|
||||||
@ -359,76 +357,3 @@ def get_address_territory(address_name):
|
|||||||
break
|
break
|
||||||
|
|
||||||
return territory
|
return territory
|
||||||
|
|
||||||
import unittest
|
|
||||||
test_dependencies = ["Item", "Price List", "Contact", "Shopping Cart Settings"]
|
|
||||||
|
|
||||||
class TestCart(unittest.TestCase):
|
|
||||||
def tearDown(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
|
||||||
cart_settings.ignore_permissions = True
|
|
||||||
cart_settings.enabled = 0
|
|
||||||
cart_settings.save()
|
|
||||||
|
|
||||||
def enable_shopping_cart(self):
|
|
||||||
return
|
|
||||||
if not frappe.db.get_value("Shopping Cart Settings", None, "enabled"):
|
|
||||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
|
||||||
cart_settings.ignore_permissions = True
|
|
||||||
cart_settings.enabled = 1
|
|
||||||
cart_settings.save()
|
|
||||||
|
|
||||||
def test_get_lead_or_customer(self):
|
|
||||||
frappe.session.user = "test@example.com"
|
|
||||||
party1 = get_lead_or_customer()
|
|
||||||
party2 = get_lead_or_customer()
|
|
||||||
self.assertEquals(party1.name, party2.name)
|
|
||||||
self.assertEquals(party1.doctype, "Lead")
|
|
||||||
|
|
||||||
frappe.session.user = "test_contact_customer@example.com"
|
|
||||||
party = get_lead_or_customer()
|
|
||||||
self.assertEquals(party.name, "_Test Customer")
|
|
||||||
|
|
||||||
def test_add_to_cart(self):
|
|
||||||
self.enable_shopping_cart()
|
|
||||||
frappe.session.user = "test@example.com"
|
|
||||||
|
|
||||||
update_cart("_Test Item", 1)
|
|
||||||
|
|
||||||
quotation = _get_cart_quotation()
|
|
||||||
quotation_items = quotation.get("quotation_details", {"item_code": "_Test Item"})
|
|
||||||
self.assertTrue(quotation_items)
|
|
||||||
self.assertEquals(quotation_items[0].qty, 1)
|
|
||||||
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def test_update_cart(self):
|
|
||||||
self.test_add_to_cart()
|
|
||||||
|
|
||||||
update_cart("_Test Item", 5)
|
|
||||||
|
|
||||||
quotation = _get_cart_quotation()
|
|
||||||
quotation_items = quotation.get("quotation_details", {"item_code": "_Test Item"})
|
|
||||||
self.assertTrue(quotation_items)
|
|
||||||
self.assertEquals(quotation_items[0].qty, 5)
|
|
||||||
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def test_remove_from_cart(self):
|
|
||||||
quotation0 = self.test_add_to_cart()
|
|
||||||
|
|
||||||
update_cart("_Test Item", 0)
|
|
||||||
|
|
||||||
quotation = _get_cart_quotation()
|
|
||||||
self.assertEquals(quotation0.name, quotation.name)
|
|
||||||
|
|
||||||
quotation_items = quotation.get("quotation_details", {"item_code": "_Test Item"})
|
|
||||||
self.assertEquals(quotation_items, [])
|
|
||||||
|
|
||||||
def test_place_order(self):
|
|
||||||
quotation = self.test_update_cart()
|
|
||||||
sales_order_name = place_order()
|
|
||||||
sales_order = frappe.get_doc("Sales Order", sales_order_name)
|
|
||||||
self.assertEquals(sales_order.getone({"item_code": "_Test Item"}).prevdoc_docname, quotation.name)
|
|
||||||
|
@ -179,6 +179,8 @@ def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, postin
|
|||||||
}
|
}
|
||||||
|
|
||||||
sle_doc = frappe.get_doc(sle_dict)
|
sle_doc = frappe.get_doc(sle_dict)
|
||||||
|
sle_doc.ignore_validate = True
|
||||||
|
sle_doc.ignore_links = True
|
||||||
sle_doc.insert()
|
sle_doc.insert()
|
||||||
|
|
||||||
args = sle_dict.copy()
|
args = sle_dict.copy()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user