From d0303b3fb1a371176f257ea97649493563afe23c Mon Sep 17 00:00:00 2001 From: prssanna Date: Tue, 8 Dec 2020 16:38:16 +0530 Subject: [PATCH] fix: allow add to cart for any item if allow_items_not_in_stock is enabled --- FETCH_HEAD | 0 erpnext/portal/product_configurator/utils.py | 7 +++---- .../templates/generators/item/item_configure.js | 15 ++++----------- 3 files changed, 7 insertions(+), 15 deletions(-) create mode 100644 FETCH_HEAD diff --git a/FETCH_HEAD b/FETCH_HEAD new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/portal/product_configurator/utils.py b/erpnext/portal/product_configurator/utils.py index c3fa6d797cb..ea4d4f44109 100644 --- a/erpnext/portal/product_configurator/utils.py +++ b/erpnext/portal/product_configurator/utils.py @@ -249,6 +249,7 @@ def get_next_attribute_and_values(item_code, selected_attributes): optional_attributes = item_cache.get_optional_attributes() exact_match = [] + allow_items_not_in_stock = False # search for exact match if all selected attributes are required attributes if len(selected_attributes.keys()) >= (len(attribute_list) - len(optional_attributes)): item_attribute_value_map = item_cache.get_item_attribute_value_map() @@ -263,10 +264,7 @@ def get_next_attribute_and_values(item_code, selected_attributes): if exact_match: data = get_product_info_for_website(exact_match[0]) product_info = data.product_info - - if product_info: - product_info["allow_items_not_in_stock"] = cint(data.cart_settings.allow_items_not_in_stock) - + allow_items_not_in_stock = cint(data.cart_settings.allow_items_not_in_stock) if not data.cart_settings.show_price: product_info = None else: @@ -278,6 +276,7 @@ def get_next_attribute_and_values(item_code, selected_attributes): 'filtered_items_count': filtered_items_count, 'filtered_items': filtered_items if filtered_items_count < 10 else [], 'exact_match': exact_match, + 'allow_items_not_in_stock': allow_items_not_in_stock, 'product_info': product_info } diff --git a/erpnext/templates/generators/item/item_configure.js b/erpnext/templates/generators/item/item_configure.js index 284eb252186..868437a7dcb 100644 --- a/erpnext/templates/generators/item/item_configure.js +++ b/erpnext/templates/generators/item/item_configure.js @@ -186,7 +186,7 @@ class ItemConfigure { this.dialog.$status_area.empty(); } - get_html_for_item_found({ filtered_items_count, filtered_items, exact_match, product_info }) { + get_html_for_item_found({ filtered_items_count, filtered_items, exact_match, product_info, allow_items_not_in_stock }) { const exact_match_message = __('1 exact match.'); const one_item = exact_match.length === 1 ? exact_match[0] : @@ -194,16 +194,9 @@ class ItemConfigure { filtered_items[0] : ''; // Allow Add to Cart if adding out of stock items enabled in Shopping Cart else check stock. - var in_stock; - var add_to_cart; - var product_action; - if (product_info) { - in_stock = product_info.allow_items_not_in_stock ? 1 : product_info.in_stock; - add_to_cart = `${__('Add to cart')}`; - product_action = in_stock ? add_to_cart : `${__('Not in Stock')}`; - } else { - product_info = ''; - } + const in_stock = allow_items_not_in_stock ? 1 : product_info && product_info.in_stock; + const add_to_cart = `${__('Add to cart')}`; + const product_action = in_stock ? add_to_cart : `${__('Not in Stock')}`; const item_add_to_cart = one_item ? `