Reverted changes

This commit is contained in:
Kanchan Chauhan 2016-06-22 15:51:42 +05:30
parent c8d47da6bc
commit a756e3f765
4 changed files with 83 additions and 83 deletions

View File

@ -10,25 +10,29 @@ frappe.ready(function() {
$('.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 @@ $.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;
});
},
});

View File

@ -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 = \

View File

@ -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();
});

View File

@ -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>
{% endmacro %}