From a756e3f76528db60f437bf22cdd7ecc311872521 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Wed, 22 Jun 2016 15:51:42 +0530 Subject: [PATCH] Reverted changes --- erpnext/public/js/shopping_cart.js | 80 +++++++++++++++---- .../stock/doctype/item_price/item_price.py | 16 ++-- erpnext/templates/includes/cart.js | 47 +++-------- .../includes/order/order_macros.html | 23 +----- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index 6cf255d294..f5819a8fb1 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -10,25 +10,29 @@ frappe.ready(function() { $('.navbar li[data-label="User"] a') .html(' ' + full_name); } - // update login - shopping_cart.set_cart_count(); - $(".shopping-cart").on('shown.bs.dropdown', function() { - if (!$('.shopping-cart-menu .cart-container').length) { - return frappe.call({ - method: 'erpnext.shopping_cart.cart.get_shopping_cart_menu', - callback: function(r) { - if (r.message) { - $('.shopping-cart-menu').html(r.message); - $('#cart-overlay').addClass('show'); - } - } - }); - } - }); + // update login + shopping_cart.show_shoppingcart_dropdown(); + shopping_cart.set_cart_count(); + shopping_cart.bind_dropdown_cart_buttons(); }); $.extend(shopping_cart, { + show_shoppingcart_dropdown: function() { + $(".shopping-cart").on('shown.bs.dropdown', function() { + if (!$('.shopping-cart-menu .cart-container').length) { + return frappe.call({ + method: 'erpnext.shopping_cart.cart.get_shopping_cart_menu', + callback: function(r) { + if (r.message) { + $('.shopping-cart-menu').html(r.message); + } + } + }); + } + }); + }, + update_cart: function(opts) { if(!full_name || full_name==="Guest") { if(localStorage) { @@ -83,5 +87,49 @@ $.extend(shopping_cart, { } else { $badge.remove(); } - } + }, + + shopping_cart_update: function(item_code, newVal, cart_dropdown) { + frappe.freeze(); + shopping_cart.update_cart({ + item_code: item_code, + qty: newVal, + with_items: 1, + btn: this, + callback: function(r) { + frappe.unfreeze(); + if(!r.exc) { + $(".cart-items").html(r.message.items); + $(".cart-tax-items").html(r.message.taxes); + if (cart_dropdown != true) { + $(".cart-icon").hide(); + } + } + }, + }); + }, + + + bind_dropdown_cart_buttons: function() { + $(".cart-icon").on('click', '.number-spinner button', function () { + var btn = $(this), + input = btn.closest('.number-spinner').find('input'), + oldValue = input.val().trim(), + newVal = 0; + + if (btn.attr('data-dir') == 'up') { + newVal = parseInt(oldValue) + 1; + } else { + if (oldValue > 1) { + newVal = parseInt(oldValue) - 1; + } + } + input.val(newVal); + var item_code = input.attr("data-item-code"); + shopping_cart.shopping_cart_update(item_code, newVal, true); + return false; + }); + + }, + }); diff --git a/erpnext/stock/doctype/item_price/item_price.py b/erpnext/stock/doctype/item_price/item_price.py index 43390bea9c..6025ef7f9b 100644 --- a/erpnext/stock/doctype/item_price/item_price.py +++ b/erpnext/stock/doctype/item_price/item_price.py @@ -13,7 +13,7 @@ class ItemPrice(Document): def validate(self): self.validate_item() self.validate_price_list() - # self.check_duplicate_item() + self.check_duplicate_item() self.update_price_list_details() self.update_item_details() @@ -25,13 +25,13 @@ class ItemPrice(Document): enabled = frappe.db.get_value("Price List", self.price_list, "enabled") if not enabled: throw(_("Price List {0} is disabled").format(self.price_list)) - # - # def check_duplicate_item(self): - # if frappe.db.sql("""select name from `tabItem Price` - # where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)): - # - # frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list), - # ItemPriceDuplicateItem) + + def check_duplicate_item(self): + if frappe.db.sql("""select name from `tabItem Price` + where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)): + + frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list), + ItemPriceDuplicateItem) def update_price_list_details(self): self.buying, self.selling, self.currency = \ diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index cbb9390e7d..dbb93a94b1 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -16,9 +16,9 @@ $.extend(shopping_cart, { shopping_cart.bind_address_select(); shopping_cart.bind_place_order(); shopping_cart.bind_change_qty(); - + shopping_cart.bind_dropdown_cart_buttons(); }, - + bind_address_select: function() { $(".cart-addresses").find('input[data-address-name]').on("click", function() { if($(this).prop("checked")) { @@ -54,53 +54,26 @@ $.extend(shopping_cart, { // bind update button $(".cart-items").on("change", ".cart-qty", function() { var item_code = $(this).attr("data-item-code"); - frappe.freeze(); - shopping_cart.update_cart({ - item_code: item_code, - qty: $(this).val(), - with_items: 1, - btn: this, - callback: function(r) { - frappe.unfreeze(); - if(!r.exc) { - $(".cart-items").html(r.message.items); - $(".cart-tax-items").html(r.message.taxes); - $(".cart-icon").hide(); - } - }, - }); + var newVal = $(this).val(); + shopping_cart.shopping_cart_update(item_code, newVal); }); $(".cart-items").on('click', '.number-spinner button', function () { var btn = $(this), - oldValue = btn.closest('.number-spinner').find('input').val().trim(), + input = btn.closest('.number-spinner').find('input'), + oldValue = input.val().trim(), newVal = 0; if (btn.attr('data-dir') == 'up') { - console.log(oldValue); newVal = parseInt(oldValue) + 1; } else { if (oldValue > 1) { newVal = parseInt(oldValue) - 1; } } - btn.closest('.number-spinner').find('input').val(newVal); - var item_code = btn.closest('.number-spinner').find('input').attr("data-item-code"); - frappe.freeze(); - shopping_cart.update_cart({ - item_code: item_code, - qty: newVal, - with_items: 1, - btn: this, - callback: function(r) { - frappe.unfreeze(); - if(!r.exc) { - $(".cart-items").html(r.message.items); - $(".cart-tax-items").html(r.message.taxes); - $(".cart-icon").hide(); - } - }, - }); + input.val(newVal); + var item_code = input.attr("data-item-code"); + shopping_cart.shopping_cart_update(item_code, newVal); }); }, @@ -175,7 +148,7 @@ $.extend(shopping_cart, { } }); -$(document).ready(function() { +frappe.ready(function() { $(".cart-icon").hide(); shopping_cart.bind_events(); }); diff --git a/erpnext/templates/includes/order/order_macros.html b/erpnext/templates/includes/order/order_macros.html index e56f88bb5f..41be449a2a 100644 --- a/erpnext/templates/includes/order/order_macros.html +++ b/erpnext/templates/includes/order/order_macros.html @@ -37,25 +37,4 @@ -{% endmacro %} - - \ No newline at end of file +{% endmacro %} \ No newline at end of file