From 565bf203e5d21f39f55fb78cb93b3a3c0240c464 Mon Sep 17 00:00:00 2001 From: Sushant Nadkar Date: Tue, 5 Jun 2018 10:43:11 +0530 Subject: [PATCH] [Improvement] Added display settings for item price, availibility and stock levels (#14308) * display item price on website even when cart is disabled * added display settings for item price, availibility and stock levels * Update shopping_cart_settings.json --- .../shopping_cart_settings.json | 205 ++++++++++++++---- .../shopping_cart_settings.py | 4 +- .../test_shopping_cart_settings.js | 23 ++ erpnext/shopping_cart/product_info.py | 7 +- erpnext/templates/generators/item.html | 4 +- erpnext/templates/includes/product_page.js | 50 +++-- 6 files changed, 227 insertions(+), 66 deletions(-) create mode 100644 erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.js diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json index ed782ad1cf..724c1e9ba2 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json @@ -14,6 +14,7 @@ "fields": [ { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -27,7 +28,7 @@ "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, - "label": "Enable Shopping Cart", + "label": "Enable purchase of items via the website", "length": 0, "no_copy": 0, "permlevel": 0, @@ -39,16 +40,19 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", + "description": "", + "fieldname": "display_settings", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -56,6 +60,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "Display Settings", "length": 0, "no_copy": 0, "permlevel": 0, @@ -68,15 +73,17 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, "columns": 0, - "description": "Attachments can be shown without enabling the shopping cart", + "description": "", "fieldname": "show_attachments", "fieldtype": "Check", "hidden": 0, @@ -99,10 +106,142 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "eval:doc.enabled==0", + "description": "", + "fieldname": "show_price", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Show Price", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_5", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "show_stock_availability", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Show Stock Availability", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "show_stock_availability", + "fieldname": "show_quantity_in_website", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Show Stock Quantity", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -127,10 +266,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -157,10 +298,12 @@ "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -189,40 +332,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "show_quantity_in_website", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Show Quantity in Website", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -247,10 +362,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -278,10 +395,12 @@ "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -307,10 +426,12 @@ "reqd": 1, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 1, @@ -338,10 +459,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -368,10 +491,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -401,10 +526,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -430,10 +557,12 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -461,6 +590,7 @@ "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, "unique": 0 } ], @@ -475,15 +605,14 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2017-05-19 09:31:38.078110", - "modified_by": "Administrator", + "modified": "2018-05-31 03:11:58.911732", + "modified_by": "sushant@digithinkit.com", "module": "Shopping Cart", "name": "Shopping Cart Settings", "owner": "Administrator", "permissions": [ { "amend": 0, - "apply_user_permissions": 0, "cancel": 0, "create": 1, "delete": 0, @@ -509,4 +638,4 @@ "sort_order": "ASC", "track_changes": 0, "track_seen": 0 -} \ No newline at end of file +} diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py index aa4f16360d..5c240704a1 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py @@ -90,6 +90,4 @@ def check_shopping_cart_enabled(): frappe.throw(_("You need to enable Shopping Cart"), ShoppingCartSetupError) def show_attachments(): - return get_shopping_cart_settings().show_attachments - - + return get_shopping_cart_settings().show_attachments diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.js b/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.js new file mode 100644 index 0000000000..c8485e73fa --- /dev/null +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +// rename this file from _test_[name] to test_[name] to activate +// and remove above this line + +QUnit.test("test: Shopping Cart Settings", function (assert) { + let done = assert.async(); + + // number of asserts + assert.expect(1); + + frappe.run_serially([ + // insert a new Shopping Cart Settings + () => frappe.tests.make('Shopping Cart Settings', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +}); diff --git a/erpnext/shopping_cart/product_info.py b/erpnext/shopping_cart/product_info.py index e62d633a67..b5f129b4aa 100644 --- a/erpnext/shopping_cart/product_info.py +++ b/erpnext/shopping_cart/product_info.py @@ -12,8 +12,6 @@ from erpnext.utilities.product import get_price, get_qty_in_stock @frappe.whitelist(allow_guest=True) def get_product_info_for_website(item_code): """get product price / stock info for website""" - if not is_cart_enabled(): - return {} cart_quotation = _get_cart_quotation() cart_settings = get_shopping_cart_settings() @@ -43,7 +41,10 @@ def get_product_info_for_website(item_code): if item: product_info["qty"] = item[0].qty - return product_info + return { + "product_info": product_info, + "cart_settings": cart_settings + } def set_product_info_for_website(item): """set product price uom for website""" diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html index 6fec94e99c..0e09f587e3 100644 --- a/erpnext/templates/generators/item.html +++ b/erpnext/templates/generators/item.html @@ -53,8 +53,8 @@
-

-
+

+
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js index e96263fb80..798a6cff55 100644 --- a/erpnext/templates/includes/product_page.js +++ b/erpnext/templates/includes/product_page.js @@ -12,29 +12,39 @@ frappe.ready(function() { item_code: get_item_code() }, callback: function(r) { - $(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.in_stock)); - if(r.message && r.message.price) { - $(".item-price") - .html(r.message.price.formatted_price_sales_uom + "
\ - (" + r.message.price.formatted_price + " / " + r.message.uom + ")
"); - - if(r.message.in_stock==0) { - $(".item-stock").html("
{{ _("Not in stock") }}
"); + if(r.message) { + if(r.message.cart_settings.enabled) { + $(".item-cart, .item-price, .item-stock").toggleClass("hide", (!!!r.message.product_info.price || !!!r.message.product_info.in_stock)); } - else if(r.message.in_stock==1) { - var qty_display = "{{ _("In stock") }}"; - if (r.message.show_stock_qty) { - qty_display += " ("+r.message.stock_qty+")"; + if(r.message.cart_settings.show_price) { + $(".item-price").toggleClass("hide", false); + } + if(r.message.cart_settings.show_stock_availability) { + $(".item-stock").toggleClass("hide", false); + } + if(r.message.product_info.price) { + $(".item-price") + .html(r.message.product_info.price.formatted_price_sales_uom + "
\ + (" + r.message.product_info.price.formatted_price + " / " + r.message.product_info.uom + ")
"); + + if(r.message.product_info.in_stock==0) { + $(".item-stock").html("
{{ _("Not in stock") }}
"); + } + else if(r.message.product_info.in_stock==1) { + var qty_display = "{{ _("In stock") }}"; + if (r.message.product_info.show_stock_qty) { + qty_display += " ("+r.message.product_info.stock_qty+")"; + } + $(".item-stock").html("
\ + "+qty_display+"
"); } - $(".item-stock").html("
\ - "+qty_display+"
"); - } - if(r.message.qty) { - qty = r.message.qty; - toggle_update_cart(r.message.qty); - } else { - toggle_update_cart(0); + if(r.message.product_info.qty) { + qty = r.message.product_info.qty; + toggle_update_cart(r.message.product_info.qty); + } else { + toggle_update_cart(0); + } } } }