Ejemplo n.º 1
0
	def test_website_item_price_for_guest_user(self):
		"Check if price details are fetched correctly for guest user."
		item_code = "Test Mobile Phone"

		# show price for guest user in e commerce settings
		setup_e_commerce_settings({"show_price": 1, "hide_price_for_guest": 0})

		# price and pricing rule added via setUp

		# switch to guest user
		frappe.set_user("Guest")

		# price should be fetched
		frappe.local.shopping_cart_settings = None
		data = get_product_info_for_website(item_code, skip_quotation_creation=True)
		self.assertTrue(bool(data.product_info["price"]))

		price_object = data.product_info["price"]
		self.assertEqual(price_object.get("discount_percent"), 10)
		self.assertEqual(price_object.get("price_list_rate"), 900)

		# hide price for guest user
		frappe.set_user("Administrator")
		setup_e_commerce_settings({"hide_price_for_guest": 1})
		frappe.set_user("Guest")

		# price should not be fetched
		frappe.local.shopping_cart_settings = None
		data = get_product_info_for_website(item_code, skip_quotation_creation=True)
		self.assertFalse(bool(data.product_info["price"]))

		# tear down
		frappe.set_user("Administrator")
Ejemplo n.º 2
0
    def test_website_item_price_for_logged_in_user(self):
        "Check if price details are fetched correctly while logged in."
        item_code = "Test Mobile Phone"

        # show price in e commerce settings
        setup_e_commerce_settings({"show_price": 1})

        # price and pricing rule added via setUp

        # check if price and slashed price is fetched correctly
        frappe.local.shopping_cart_settings = None
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)
        self.assertTrue(bool(data.product_info["price"]))

        price_object = data.product_info["price"]
        self.assertEqual(price_object.get("discount_percent"), 10)
        self.assertEqual(price_object.get("price_list_rate"), 900)
        self.assertEqual(price_object.get("formatted_mrp"), "₹ 1,000.00")
        self.assertEqual(price_object.get("formatted_price"), "₹ 900.00")
        self.assertEqual(price_object.get("formatted_discount_percent"), "10%")

        # disable show price
        setup_e_commerce_settings({"show_price": 0})

        # price should not be fetched
        frappe.local.shopping_cart_settings = None
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)
        self.assertFalse(bool(data.product_info["price"]))

        # tear down
        frappe.set_user("Administrator")
Ejemplo n.º 3
0
    def test_website_item_stock_when_in_stock(self):
        """
		Check if stock details are fetched correctly for available inventory when:
		1) Showing stock availability enabled:
		        - Warehouse set
		        - Warehouse unset
		2) Showing stock availability disabled
		"""
        from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry

        item_code = "Test Mobile Phone"
        create_regular_web_item()
        setup_e_commerce_settings({"show_stock_availability": 1})
        frappe.local.shopping_cart_settings = None

        # set warehouse
        frappe.db.set_value("Website Item", {"item_code": item_code},
                            "website_warehouse", "_Test Warehouse - _TC")

        # stock up item
        stock_entry = make_stock_entry(item_code=item_code,
                                       target="_Test Warehouse - _TC",
                                       qty=2,
                                       rate=100)

        # check if stock details are fetched and item is in stock with warehouse set
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)
        self.assertTrue(bool(data.product_info["in_stock"]))
        self.assertEqual(data.product_info["stock_qty"][0][0], 2)

        # unset warehouse
        frappe.db.set_value("Website Item", {"item_code": item_code},
                            "website_warehouse", "")

        # check if stock details are fetched and item not in stock without warehouse set
        # (even though it has stock in some warehouse)
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)
        self.assertFalse(bool(data.product_info["in_stock"]))
        self.assertFalse(bool(data.product_info["stock_qty"]))

        # disable show stock availability
        setup_e_commerce_settings({"show_stock_availability": 0})
        frappe.local.shopping_cart_settings = None
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)

        # check if stock detail attributes are not fetched if stock availability is hidden
        self.assertIsNone(data.product_info.get("in_stock"))
        self.assertIsNone(data.product_info.get("stock_qty"))
        self.assertIsNone(data.product_info.get("show_stock_qty"))

        # tear down
        stock_entry.cancel()
        frappe.get_cached_doc("Website Item", {
            "item_code": "Test Mobile Phone"
        }).delete()
Ejemplo n.º 4
0
    def add_display_details(self, result, discount_list, cart_items):
        """Add price and availability details in result."""
        for item in result:
            product_info = get_product_info_for_website(
                item.item_code,
                skip_quotation_creation=True).get("product_info")

            if product_info and product_info["price"]:
                # update/mutate item and discount_list objects
                self.get_price_discount_info(item, product_info["price"],
                                             discount_list)

            if self.settings.show_stock_availability:
                self.get_stock_availability(item)

            item.in_cart = item.item_code in cart_items

            item.wished = False
            if frappe.db.exists("Wishlist Item", {
                    "item_code": item.item_code,
                    "parent": frappe.session.user
            }):
                item.wished = True

        return result, discount_list
Ejemplo n.º 5
0
    def test_website_item_stock_when_out_of_stock(self):
        """
		Check if stock details are fetched correctly for empty inventory when:
		1) Showing stock availability enabled:
		        - Warehouse unset
		        - Warehouse set
		2) Showing stock availability disabled
		"""
        item_code = "Test Mobile Phone"
        create_regular_web_item()
        setup_e_commerce_settings({"show_stock_availability": 1})

        frappe.local.shopping_cart_settings = None
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)

        # check if stock details are fetched and item not in stock without warehouse set
        self.assertFalse(bool(data.product_info["in_stock"]))
        self.assertFalse(bool(data.product_info["stock_qty"]))

        # set warehouse
        frappe.db.set_value("Website Item", {"item_code": item_code},
                            "website_warehouse", "_Test Warehouse - _TC")

        # check if stock details are fetched and item not in stock with warehouse set
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)
        self.assertFalse(bool(data.product_info["in_stock"]))
        self.assertEqual(data.product_info["stock_qty"][0][0], 0)

        # disable show stock availability
        setup_e_commerce_settings({"show_stock_availability": 0})
        frappe.local.shopping_cart_settings = None
        data = get_product_info_for_website(item_code,
                                            skip_quotation_creation=True)

        # check if stock detail attributes are not fetched if stock availability is hidden
        self.assertIsNone(data.product_info.get("in_stock"))
        self.assertIsNone(data.product_info.get("stock_qty"))
        self.assertIsNone(data.product_info.get("show_stock_qty"))

        # tear down
        frappe.get_cached_doc("Website Item", {
            "item_code": "Test Mobile Phone"
        }).delete()
Ejemplo n.º 6
0
 def set_shopping_cart_data(self, context):
     from erpnext.e_commerce.shopping_cart.product_info import get_product_info_for_website
     context.shopping_cart = get_product_info_for_website(
         self.item_code, skip_quotation_creation=True)