Show qty in Shopping Cart

This commit is contained in:
Kanchan Chauhan 2017-03-21 16:28:03 +05:30
parent 2b9c95a940
commit a844040781
5 changed files with 70 additions and 19 deletions

View File

@ -327,4 +327,3 @@ body[data-route="pos"] .btn-more {
body[data-route="pos"] .collapse-btn {
cursor: pointer;
}

View File

@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
@ -22,6 +23,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Enable Shopping Cart",
@ -49,6 +51,7 @@
"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,
@ -75,6 +78,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Company",
@ -104,6 +108,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Price List",
@ -122,6 +127,35 @@
"set_only_once": 0,
"unique": 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_on_submit": 0,
"bold": 0,
@ -133,6 +167,7 @@
"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,
@ -160,6 +195,7 @@
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Default Customer Group",
@ -188,6 +224,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Quotation Series",
@ -216,6 +253,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Checkout Settings",
@ -244,6 +282,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Enable Checkout",
@ -274,6 +313,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Payment Success Url",
@ -303,6 +343,7 @@
"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,
@ -330,6 +371,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Payment Gateway Account",
@ -349,18 +391,18 @@
"unique": 0
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "fa fa-shopping-cart",
"idx": 1,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2017-01-17 05:30:29.333104",
"modified": "2017-03-21 15:42:08.574497",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Shopping Cart Settings",
@ -376,7 +418,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
"is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@ -391,6 +432,7 @@
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_order": "ASC",
"track_changes": 0,
"track_seen": 0

View File

@ -82,6 +82,9 @@ def get_shopping_cart_settings():
def is_cart_enabled():
return get_shopping_cart_settings().enabled
def show_quantity_in_website():
return get_shopping_cart_settings().show_quantity_in_website
def check_shopping_cart_enabled():
if not get_shopping_cart_settings().enabled:
frappe.throw(_("You need to enable Shopping Cart"), ShoppingCartSetupError)

View File

@ -7,7 +7,7 @@ import frappe
from frappe.utils import cint, fmt_money, flt
from erpnext.shopping_cart.cart import _get_cart_quotation
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings \
import is_cart_enabled, get_shopping_cart_settings
import is_cart_enabled, get_shopping_cart_settings, show_quantity_in_website
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
@frappe.whitelist(allow_guest=True)
@ -19,7 +19,9 @@ def get_product_info(item_code):
qty = 0
cart_quotation = _get_cart_quotation()
template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
in_stock = get_qty_in_stock(item_code, template_item_code)
stock_status = get_qty_in_stock(item_code, template_item_code)
in_stock = stock_status.in_stock
stock_qty = stock_status.stock_qty
price = get_price(item_code, template_item_code, cart_quotation.selling_price_list)
if price:
@ -36,9 +38,11 @@ def get_product_info(item_code):
return {
"price": price,
"stock": in_stock,
"stock_qty": stock_qty,
"in_stock": in_stock,
"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
"qty": qty
"qty": qty,
"show_stock_qty": show_quantity_in_website()
}
def get_qty_in_stock(item_code, template_item_code):
@ -47,15 +51,14 @@ def get_qty_in_stock(item_code, template_item_code):
warehouse = frappe.db.get_value("Item", template_item_code, "website_warehouse")
if warehouse:
in_stock = frappe.db.sql("""select actual_qty from tabBin where
stock_qty = frappe.db.sql("""select actual_qty from tabBin where
item_code=%s and warehouse=%s""", (item_code, warehouse))
if in_stock:
in_stock = in_stock[0][0] > 0 and 1 or 0
if stock_qty:
in_stock = stock_qty[0][0] > 0 and 1 or 0
else:
in_stock = 0
else:
in_stock = 0
return in_stock
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty})
def get_price(item_code, template_item_code, price_list, qty=1):
if price_list:

View File

@ -17,12 +17,16 @@ frappe.ready(function() {
$(".item-price")
.html(r.message.price.formatted_price + " per " + r.message.uom);
if(r.message.stock==0) {
$(".item-stock").html("<div style='color: red'>Not in stock</div>");
if(r.message.in_stock==0) {
$(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> Not in stock</div>");
}
else if(r.message.stock==1) {
else if(r.message.in_stock==1) {
qty_display = "In stock"
if (r.message.show_stock_qty) {
qty_display = "Available ("+r.message.stock_qty+ " in stock)"
}
$(".item-stock").html("<div style='color: green'>\
<i class='fa fa-check'></i> Available (in stock)</div>");
<i class='fa fa-check'></i> "+__(qty_display)+"</div>");
}
if(r.message.qty) {