From 40dffab79ebcc2e4a761b508b9cc469828beffe8 Mon Sep 17 00:00:00 2001 From: Marica Date: Fri, 24 Jan 2020 15:52:27 +0530 Subject: [PATCH] fix: Product Page non-stock item status (#20383) --- erpnext/shopping_cart/product_info.py | 4 ++-- erpnext/utilities/product.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/shopping_cart/product_info.py b/erpnext/shopping_cart/product_info.py index d69b5e3a21..a7da09cb80 100644 --- a/erpnext/shopping_cart/product_info.py +++ b/erpnext/shopping_cart/product_info.py @@ -7,7 +7,7 @@ import frappe from erpnext.shopping_cart.cart import _get_cart_quotation from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings \ import get_shopping_cart_settings, show_quantity_in_website -from erpnext.utilities.product import get_price, get_qty_in_stock +from erpnext.utilities.product import get_price, get_qty_in_stock, get_non_stock_item_status @frappe.whitelist(allow_guest=True) def get_product_info_for_website(item_code): @@ -31,7 +31,7 @@ def get_product_info_for_website(item_code): product_info = { "price": price, "stock_qty": stock_status.stock_qty, - "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1, + "in_stock": stock_status.in_stock if stock_status.is_stock_item else get_non_stock_item_status(item_code, "website_warehouse"), "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website(), diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py index a2867c8806..1c0d4c38c7 100644 --- a/erpnext/utilities/product.py +++ b/erpnext/utilities/product.py @@ -124,3 +124,11 @@ def get_price(item_code, price_list, customer_group, company, qty=1): price_obj["formatted_price"] = "" return price_obj + +def get_non_stock_item_status(item_code, item_warehouse_field): +#if item belongs to product bundle, check if bundle items are in stock + if frappe.db.exists("Product Bundle", item_code): + items = frappe.get_doc("Product Bundle", item_code).get_all_children() + return all([ get_qty_in_stock(d.item_code, item_warehouse_field).in_stock for d in items ]) + else: + return 1