コード例 #1
0
	def test_add_item_variant_without_web_item_to_cart(self):
		"Test adding Variants having no Website Items in cart via Template Web Item."
		from erpnext.controllers.item_variant import create_variant
		from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
		from erpnext.stock.doctype.item.test_item import make_item

		template_item = make_item(
			"Test-Tshirt-Temp",
			{
				"has_variant": 1,
				"variant_based_on": "Item Attribute",
				"attributes": [{"attribute": "Test Size"}, {"attribute": "Test Colour"}],
			},
		)
		variant = create_variant("Test-Tshirt-Temp", {"Test Size": "Small", "Test Colour": "Red"})
		variant.save()
		make_website_item(template_item)  # publish template not variant

		update_cart("Test-Tshirt-Temp-S-R", 1)

		cart = get_cart_quotation()  # test if cart page gets data without errors
		doc = cart.get("doc")

		self.assertEqual(doc.get("items")[0].item_name, "Test-Tshirt-Temp-S-R")

		# test if items are rendered without error
		frappe.render_template("templates/includes/cart/cart_items.html", cart)
コード例 #2
0
	def test_update_cart(self):
		# first, add to cart
		self.test_add_to_cart()

		# update first item
		update_cart("_Test Item", 5)
		quotation = self.test_get_cart_customer()
		self.assertEqual(quotation.get("items")[0].item_code, "_Test Item")
		self.assertEqual(quotation.get("items")[0].qty, 5)
		self.assertEqual(quotation.get("items")[0].amount, 50)
		self.assertEqual(quotation.net_total, 70)
		self.assertEqual(len(quotation.get("items")), 2)
コード例 #3
0
	def test_remove_from_cart(self):
		# first, add to cart
		self.test_add_to_cart()

		# remove first item
		update_cart("_Test Item", 0)
		quotation = self.test_get_cart_customer()

		self.assertEqual(quotation.get("items")[0].item_code, "_Test Item 2")
		self.assertEqual(quotation.get("items")[0].qty, 1)
		self.assertEqual(quotation.get("items")[0].amount, 20)
		self.assertEqual(quotation.net_total, 20)
		self.assertEqual(len(quotation.get("items")), 1)
コード例 #4
0
	def test_cart_without_checkout_and_draft_quotation(self):
		"Test impact of 'save_quotations_as_draft' checkbox."
		frappe.local.shopping_cart_settings = None

		# add item to cart
		update_cart("_Test Item", 1)
		quote_name = request_for_quotation()  # Request for Quote
		quote_doctstatus = cint(frappe.db.get_value("Quotation", quote_name, "docstatus"))

		self.assertEqual(quote_doctstatus, 0)

		frappe.db.set_value("E Commerce Settings", None, "save_quotations_as_draft", 0)
		frappe.local.shopping_cart_settings = None
		update_cart("_Test Item", 1)
		quote_name = request_for_quotation()  # Request for Quote
		quote_doctstatus = cint(frappe.db.get_value("Quotation", quote_name, "docstatus"))

		self.assertEqual(quote_doctstatus, 1)
コード例 #5
0
	def test_add_to_cart(self):
		self.login_as_customer()

		# clear existing quotations
		self.clear_existing_quotations()

		# add first item
		update_cart("_Test Item", 1)

		quotation = self.test_get_cart_customer()

		self.assertEqual(quotation.get("items")[0].item_code, "_Test Item")
		self.assertEqual(quotation.get("items")[0].qty, 1)
		self.assertEqual(quotation.get("items")[0].amount, 10)

		# add second item
		update_cart("_Test Item 2", 1)
		quotation = self.test_get_cart_customer()
		self.assertEqual(quotation.get("items")[1].item_code, "_Test Item 2")
		self.assertEqual(quotation.get("items")[1].qty, 1)
		self.assertEqual(quotation.get("items")[1].amount, 20)

		self.assertEqual(len(quotation.get("items")), 2)