Fix and improve shopping cart (#9348)
* Fix and improve shopping cart
* Update shopping_cart.js
* Update shopping_cart.js
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js
index 2c56b02..01a899c 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -6,7 +6,7 @@
var shopping_cart = erpnext.shopping_cart;
frappe.ready(function() {
- var full_name = frappe.session.user_fullname;
+ var full_name = frappe.session && frappe.session.user_fullname;
// update user
if(full_name) {
$('.navbar li[data-label="User"] a')
@@ -35,9 +35,8 @@
});
},
- update_cart: function(opts) {
- var full_name = frappe.session.user_fullname;
- if(!full_name || full_name==="Guest") {
+ update_cart: function(opts) {
+ if(fraappe.session.user==="Guest") {
if(localStorage) {
localStorage.setItem("last_visited", window.location.pathname);
}
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 98404a4..59a36de 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -100,7 +100,7 @@
or name like %(search)s)"""
search = "%" + cstr(search) + "%"
- query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
+ query += """order by weightage desc, item_name, modified desc limit %s, %s""" % (start, limit)
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index e73734e..5c7d825 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -75,9 +75,15 @@
def update_cart(item_code, qty, with_items=False):
quotation = _get_cart_quotation()
+ empty_card = False
qty = flt(qty)
if qty == 0:
- quotation.set("items", quotation.get("items", {"item_code": ["!=", item_code]}))
+ quotation_items = quotation.get("items", {"item_code": ["!=", item_code]})
+ if quotation_items:
+ quotation.set("items", quotation_items)
+ else:
+ empty_card = True
+
else:
quotation_items = quotation.get("items", {"item_code": item_code})
if not quotation_items:
@@ -92,7 +98,11 @@
apply_cart_settings(quotation=quotation)
quotation.flags.ignore_permissions = True
- quotation.save()
+ if not empty_card:
+ quotation.save()
+ else:
+ quotation.delete()
+ quotation = None
set_cart_count(quotation)
diff --git a/erpnext/templates/includes/order/order_taxes.html b/erpnext/templates/includes/order/order_taxes.html
index 24ae088..471576f 100644
--- a/erpnext/templates/includes/order/order_taxes.html
+++ b/erpnext/templates/includes/order/order_taxes.html
@@ -6,11 +6,13 @@
</div>
{% endif %}
{% for d in doc.taxes %}
+{% if d.base_tax_amount > 0 %}
<div class="row tax-row">
<div class="col-xs-8 text-right">{{ d.description }}</div>
<div class="col-xs-4 text-right">
{{ d.get_formatted("base_tax_amount") }}</div>
</div>
+{% endif %}
{% endfor %}
<div class="row tax-grand-total-row">
<div class="col-xs-8 text-right text-uppercase h6 text-muted">{{ _("Grand Total") }}</div>
diff --git a/erpnext/templates/includes/product_list.js b/erpnext/templates/includes/product_list.js
index 7f63c17..2f9d978 100644
--- a/erpnext/templates/includes/product_list.js
+++ b/erpnext/templates/includes/product_list.js
@@ -39,10 +39,10 @@
if(data.length < 10) {
if(!table) {
$(".more-btn")
- .replaceWith("<div class='alert alert-warning'>No products found.</div>");
+ .replaceWith("<div class='alert alert-warning'>{{ _("No products found.") }}</div>");
} else {
$(".more-btn")
- .replaceWith("<div class='text-muted'>Nothing more to show.</div>");
+ .replaceWith("<div class='text-muted'>{{ _("Nothing more to show.") }}</div>");
}
} else {
$(".more-btn").toggle(true)
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index e61ead1..3905959 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -15,18 +15,18 @@
$(".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 + " per " + r.message.uom);
+ .html(r.message.price.formatted_price + " {{ _("per") }} " + r.message.uom);
if(r.message.in_stock==0) {
- $(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> Not in stock</div>");
+ $(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> {{ _("Not in stock") }}</div>");
}
else if(r.message.in_stock==1) {
- var qty_display = "In stock";
+ var qty_display = "{{ _("In stock") }}";
if (r.message.show_stock_qty) {
- qty_display = "Available ("+r.message.stock_qty+ " in stock)";
+ qty_display += " ("+r.message.stock_qty+")";
}
$(".item-stock").html("<div style='color: green'>\
- <i class='fa fa-check'></i> "+__(qty_display)+"</div>");
+ <i class='fa fa-check'></i> "+qty_display+"</div>");
}
if(r.message.qty) {