Reverted changes
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js
index 6cf255d..f5819a8 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -10,25 +10,29 @@
$('.navbar li[data-label="User"] a')
.html('<i class="icon-fixed-width icon-user"></i> ' + 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 @@
} 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 43390be..6025ef7 100644
--- a/erpnext/stock/doctype/item_price/item_price.py
+++ b/erpnext/stock/doctype/item_price/item_price.py
@@ -13,7 +13,7 @@
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 @@
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 cbb9390..dbb93a9 100644
--- a/erpnext/templates/includes/cart.js
+++ b/erpnext/templates/includes/cart.js
@@ -16,9 +16,9 @@
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 @@
// 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 @@
}
});
-$(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 e56f88b..41be449 100644
--- a/erpnext/templates/includes/order/order_macros.html
+++ b/erpnext/templates/includes/order/order_macros.html
@@ -37,25 +37,4 @@
</div>
</div>
</div>
-{% endmacro %}
-
-<script>
-frappe.ready(function() {
- $(".cart-items-dropdown").on('click', '.number-spinner button', function () {
- var btn = $(this),
- oldValue = btn.closest('.number-spinner').find('input').val().trim(),
- newVal = 0;
-
- if (btn.attr('data-dir') == 'up') {
- newVal = parseInt(oldValue) + 1;
- } else {
- if (oldValue > 1) {
- newVal = parseInt(oldValue) - 1;
- } else {
- newVal = 1;
- }
- }
- btn.closest('.number-spinner').find('input').val(newVal);
-});
-}
-</script>
\ No newline at end of file
+{% endmacro %}
\ No newline at end of file