Commit e46288b7 by François C.

Merge branch '2245-made-paper-meal-vouhcer-usable-once' into 'dev_cooperatic'

display a popup if the meal voucher was already scan on this order

See merge request !27
parents 2d9688f3 ae3e4f87
......@@ -322,6 +322,25 @@ msgstr "Le montant saisi est supérieur au montant maximum/au maximum éligible
#. module: pos_meal_voucher
#. openerp-web
#: code:addons/pos_meal_voucher/static/src/js/screens.js:
#, python-format
msgid "Meal Voucher already used"
msgstr "Ticket restaurant déjà scanné"
#. module: pos_meal_voucher
#. openerp-web
#: code:addons/pos_meal_voucher/static/src/js/screens.js:
#, python-format
msgid "The paper meal voucher "
msgstr "Le ticket restaurant "
#. module: pos_meal_voucher
#. openerp-web
#: code:addons/pos_meal_voucher/static/src/js/screens.js:
#, python-format
msgid " was already used"
msgstr " a déjà été scanné"
#: code:addons/pos_meal_voucher/static/src/js/screens.js:196
#, python-format
msgid "Meal Voucher ticket"
......@@ -333,3 +352,4 @@ msgstr "Chèque restaurant"
#, python-format
msgid "To add a meal voucher ticket close this window and scan the ticket. If the ticket can't be read please enter the code"
msgstr "Pour ajouter un chèque restaurant merci de fermer cette fenêtre et scanner le chèque. Si le chèque est illisible veuillez rentrer le code à la main."
......@@ -7,7 +7,7 @@ odoo.define("pos_meal_voucher.models", function (require) {
var models = require("point_of_sale.models");
var utils = require("web.utils");
var round_pr = utils.round_precision;
models.load_fields("product.product", ["meal_voucher_ok"]);
......@@ -16,6 +16,14 @@ odoo.define("pos_meal_voucher.models", function (require) {
var OrderSuper = models.Order.prototype;
var Order = models.Order.extend({
paper_meal_vouche_number_already_used: function(meal_voucher_number){
for(const paiementLine of this.get_paymentlines()){
if(paiementLine.statement_note == meal_voucher_number) return true
}
return false;
},
get_total_meal_voucher_eligible: function() {
return round_pr(this.orderlines.reduce((function(sum, orderLine) {
......
......@@ -14,33 +14,46 @@ odoo.define("pos_meal_voucher.screens", function (require) {
screens.ScreenWidget.include({
barcode_meal_voucher_payment_action: function (code) {
// Display the payment screen, if it is not the current one.
if (this.pos.gui.current_screen.template !== "PaymentScreenWidget"){
this.gui.show_screen("payment");
}
var paymentScreen = this.pos.gui.current_screen;
var order = this.pos.get_order();
var amount = code.value;
var cashregister = null;
// find a meal voucher cash register, if exist
for ( var i = 0; i < this.pos.cashregisters.length; i++ ) {
if ( this.pos.cashregisters[i].journal.meal_voucher_type === "paper" ){
cashregister = this.pos.cashregisters[i];
break;
var oder = this.pos.get_order();
if(!oder.paper_meal_vouche_number_already_used(code.code)){
// Display the payment screen, if it is not the current one.
if (this.pos.gui.current_screen.template !== "PaymentScreenWidget"){
this.gui.show_screen("payment");
}
}
if (!cashregister){
return;
var paymentScreen = this.pos.gui.current_screen;
var order = this.pos.get_order();
var amount = code.value;
var cashregister = null;
// find a meal voucher cash register, if exist
for ( var i = 0; i < this.pos.cashregisters.length; i++ ) {
if ( this.pos.cashregisters[i].journal.meal_voucher_type === "paper" ){
cashregister = this.pos.cashregisters[i];
break;
}
}
if (!cashregister){
return;
}
// Add new payment line with the amount found in the barcode
this.pos.get_order().add_paymentline(cashregister);
paymentScreen.reset_input()
order.selected_paymentline.set_amount(amount);
order.selected_paymentline.statement_note = code.code;
paymentScreen.order_changes();
paymentScreen.render_paymentlines();
paymentScreen.$(".paymentline.selected .edit").text(paymentScreen.format_currency_no_symbol(amount));
}else{
this.gui.show_popup("alert", {
'title': _t("Meal Voucher Amount already used"),
'body': _t("The paper meal voucher ") +
code.code + _t(" was already used"),
});
}
// Add new payment line with the amount found in the barcode
this.pos.get_order().add_paymentline(cashregister);
paymentScreen.reset_input()
order.selected_paymentline.set_amount(amount);
order.selected_paymentline.statement_note = code.code;
paymentScreen.order_changes();
paymentScreen.render_paymentlines();
paymentScreen.$(".paymentline.selected .edit").text(paymentScreen.format_currency_no_symbol(amount));
},
// Setup the callback action for the "meal_voucher_payment" barcodes.
......
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