Merge pull request #16513 from rohitwaghchaure/remove_zero_qty_items_on_click_os_pay

feat: on click of pay button and on focus out of qty field remove the zero qty items from the cart
This commit is contained in:
Nabin Hait 2019-01-29 13:02:56 +05:30 committed by GitHub
commit 1df9a23e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -603,7 +603,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
this.remove_item = [] this.remove_item = []
idx = $(this.wrapper).find(".pos-selected-item-action").attr("data-idx") idx = $(this.wrapper).find(".pos-selected-item-action").attr("data-idx")
this.remove_item.push(idx) this.remove_item.push(idx)
this.remove_zero_qty_item() this.remove_zero_qty_items_from_cart()
this.update_paid_amount_status(false) this.update_paid_amount_status(false)
}, },
@ -1176,20 +1176,27 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
$(this.wrapper).on("change", ".pos-item-qty", function () { $(this.wrapper).on("change", ".pos-item-qty", function () {
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code"); var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
var qty = $(this).val(); var qty = $(this).val();
me.update_qty(item_code, qty) me.update_qty(item_code, qty);
me.update_value() me.update_value();
})
$(this.wrapper).on("focusout", ".pos-item-qty", function () {
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
var qty = $(this).val();
me.update_qty(item_code, qty, true);
me.update_value();
}) })
$(this.wrapper).find("[data-action='increase-qty']").on("click", function () { $(this.wrapper).find("[data-action='increase-qty']").on("click", function () {
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1; var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1;
me.update_qty(item_code, qty) me.update_qty(item_code, qty);
}) })
$(this.wrapper).find("[data-action='decrease-qty']").on("click", function () { $(this.wrapper).find("[data-action='decrease-qty']").on("click", function () {
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1; var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1;
me.update_qty(item_code, qty) me.update_qty(item_code, qty);
}) })
$(this.wrapper).on("change", ".pos-item-disc", function () { $(this.wrapper).on("change", ".pos-item-disc", function () {
@ -1228,11 +1235,11 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
me.bind_delete_event() me.bind_delete_event()
}, },
update_qty: function (item_code, qty) { update_qty: function (item_code, qty, remove_zero_qty_items) {
var me = this; var me = this;
this.items = this.get_items(item_code); this.items = this.get_items(item_code);
this.validate_serial_no() this.validate_serial_no()
this.set_item_details(item_code, "qty", qty); this.set_item_details(item_code, "qty", qty, remove_zero_qty_items);
}, },
update_discount: function(item_code, discount) { update_discount: function(item_code, discount) {
@ -1293,7 +1300,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
}) })
}, },
set_item_details: function (item_code, field, value) { set_item_details: function (item_code, field, value, remove_zero_qty_items) {
var me = this; var me = this;
if (value < 0) { if (value < 0) {
frappe.throw(__("Enter value must be positive")); frappe.throw(__("Enter value must be positive"));
@ -1308,7 +1315,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
d[field] = flt(value); d[field] = flt(value);
d.amount = flt(d.rate) * flt(d.qty); d.amount = flt(d.rate) * flt(d.qty);
if (d.qty == 0) { if (d.qty == 0 && remove_zero_qty_items) {
me.remove_item.push(d.idx) me.remove_item.push(d.idx)
} }
@ -1318,10 +1325,14 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
} }
}); });
if (field == 'qty') {
this.remove_zero_qty_items_from_cart();
}
this.update_paid_amount_status(false) this.update_paid_amount_status(false)
}, },
remove_zero_qty_item: function () { remove_zero_qty_items_from_cart: function () {
var me = this; var me = this;
var idx = 0; var idx = 0;
this.items = [] this.items = []
@ -1847,10 +1858,25 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
validate: function () { validate: function () {
var me = this; var me = this;
this.customer_validate(); this.customer_validate();
this.validate_zero_qty_items();
this.item_validate(); this.item_validate();
this.validate_mode_of_payments(); this.validate_mode_of_payments();
}, },
validate_zero_qty_items: function() {
this.remove_item = [];
this.frm.doc.items.forEach(d => {
if (d.qty == 0) {
this.remove_item.push(d.idx);
}
});
if(this.remove_item) {
this.remove_zero_qty_items_from_cart();
}
},
item_validate: function () { item_validate: function () {
if (this.frm.doc.items.length == 0) { if (this.frm.doc.items.length == 0) {
frappe.throw(__("Select items to save the invoice")) frappe.throw(__("Select items to save the invoice"))