Commit 3d909fc9 by Damien Moulard

prevent payment if products at 0 or none

parent aa009959
......@@ -132,6 +132,57 @@ odoo.define("lacagette_custom_pos.screens", function (require) {
}
});
screens.ActionpadWidget.include({
renderElement: function() {
this._super();
this.$('.pay').off('click'); // remove base event to redirect to payment screen
this.$('.pay').click(() => {
// Get order lines
let orderlines = this.pos.get_order().orderlines.models
// Prevent payment if the order is empty
if (orderlines.length == 0) {
this.gui.show_popup("alert", {
'title': _t("Paiement non autorisé"),
'body': _t("Le panier doit contenir au moins 1 article.")
});
return;
}
// Prevent payment if any line in order has a 0 qty
let products_empty_qty = []
for (let orderline of orderlines) {
if (orderline.quantity === 0) {
products_empty_qty.push(orderline);
}
}
if (products_empty_qty.length > 0) {
let msg = products_empty_qty.length > 1 ? "Les articles " : "L'article ";
products_empty_qty.forEach((el) => {
msg += el.product.display_name + ", ";
});
msg = msg.substring(0, msg.length - 2); // Remove last ", "
msg += products_empty_qty.length > 1 ? " ont " : " a ";
msg += "une quantité de zéro";
this.gui.show_popup("alert", {
'title': _t("Paiement non autorisé"),
'body': msg
});
return;
}
// Redirect if all checks passed
this.gui.show_screen('payment');
});
}
});
screens.ScreenWidget.include({
init: function(parent,options){
this._super(parent,options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment