Commit 99d20d7f by François C.

Merge branch 'story_4617' into pour_mep

parents 96d233f9 d20e549e
......@@ -85,3 +85,5 @@ ENV/
# Rope project settings
.ropeproject
.idea
......@@ -266,4 +266,88 @@ odoo.define("lacagette_custom_pos.screens", function (require) {
}
}
});
screens.PaymentScreenWidget.include({
order_is_valid: function(force_validation) {
var self = this;
var order = this.pos.get_order();
// FIXME: this check is there because the backend is unable to
// process empty orders. This is not the right place to fix it.
if (order.get_orderlines().length === 0) {
this.gui.show_popup('error',{
'title': _t('Empty Order'),
'body': _t('There must be at least one product in your order before it can be validated'),
});
return false;
}
var plines = order.get_paymentlines();
for (var i = 0; i < plines.length; i++) {
if (plines[i].get_type() === 'bank' && plines[i].get_amount() < 0) {
this.gui.show_popup('error',{
'message': _t('Negative Bank Payment'),
'comment': _t('You cannot have a negative amount in a Bank payment. Use a cash payment method to return money to the customer.'),
});
return false;
}
}
if (!order.is_paid() || this.invoicing) {
return false;
}
// The exact amount must be paid if there is no cash payment method defined.
if (Math.abs(order.get_total_with_tax() - order.get_total_paid()) > 0.00001) {
var cash = false;
for (var i = 0; i < this.pos.cashregisters.length; i++) {
cash = cash || (this.pos.cashregisters[i].journal.type === 'cash');
}
if (!cash) {
this.gui.show_popup('error',{
title: _t('Cannot return change without a cash payment method'),
body: _t('There is no cash payment method available in this point of sale to handle the change.\n\n Please pay the exact amount or add a cash payment method in the point of sale configuration'),
});
return false;
}
}
// if the change is too large, it's probably an input error, make the user confirm.
if (!force_validation && order.get_total_with_tax() > 0 && (order.get_total_with_tax() * 1000 < order.get_total_paid())) {
this.gui.show_popup('confirm',{
title: _t('Please Confirm Large Amount'),
body: _t('Are you sure that the customer wants to pay') +
' ' +
this.format_currency(order.get_total_paid()) +
' ' +
_t('for an order of') +
' ' +
this.format_currency(order.get_total_with_tax()) +
' ' +
_t('? Clicking "Confirm" will validate the payment.'),
confirm: function() {
self.validate_order('confirm');
},
});
return false;
}
var totalPaidExceptCash = 0; //block if this amount is more than total with tax
for (i = 0; i < plines.length; i++) {
if (plines[i].get_type() !== 'cash') {
totalPaidExceptCash += plines[i].get_amount();
}
}
if (!force_validation && order.get_total_with_tax() > 0 && ((order.get_total_with_tax() + 0.00001) < totalPaidExceptCash)) {
this.gui.show_popup('error',{
title: _t('Le rendu de monnaie est possible seulement sur les lignes espèces.'),
body: _t('Pour valider le paiement, la somme des montants offerts des lignes (hors espèces) doit donc être inférieure au total dû.'),
});
return false;
}
return true;
},
});
});
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