Commit ae3e4f87 by François C.

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

# Conflicts:
#   lacagette_addons/pos_meal_voucher/i18n/fr.po
#   lacagette_addons/pos_meal_voucher/static/src/js/screens.js
parents 5db467b0 2d9688f3
......@@ -312,6 +312,9 @@ msgstr "Attention, le montant éligible au paiement par titre restaurant( "
#, python-format
msgid " ) is under the amount input ( "
msgstr " ) est inférieur à la valeur du/des ticket(s)( "
#. module: pos_meal_voucher
#. openerp-web
#: code:addons/pos_meal_voucher/static/src/js/screens.js:110
#, python-format
msgid "Warning, the input amount of meal voucher is above the maximum amount of "
......@@ -336,4 +339,17 @@ msgstr "Le ticket restaurant "
#: code:addons/pos_meal_voucher/static/src/js/screens.js:
#, python-format
msgid " was already used"
msgstr " a déjà été scanné"
\ No newline at end of file
msgstr " a déjà été scanné"
#: code:addons/pos_meal_voucher/static/src/js/screens.js:196
#, python-format
msgid "Meal Voucher ticket"
msgstr "Chèque restaurant"
#. module: pos_meal_voucher
#. openerp-web
#: code:addons/pos_meal_voucher/static/src/js/screens.js:197
#, 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."
......@@ -203,6 +203,10 @@ odoo.define("pos_meal_voucher.models", function (require) {
return (
this.cashregister.journal.meal_voucher_type == "dematerialized") ;
},
is_paper_meal_voucher: function() {
return (
this.cashregister.journal.meal_voucher_type == "paper") ;
},
});
......
......@@ -7,6 +7,7 @@ odoo.define("pos_meal_voucher.screens", function (require) {
var screens = require("point_of_sale.screens");
var core = require('web.core');
var formats = require('web.formats');
var _t = core._t;
var QWeb = core.qweb;
......@@ -79,6 +80,129 @@ odoo.define("pos_meal_voucher.screens", function (require) {
screens.PaymentScreenWidget.include({
// odoo/addons/point_of_sale/static/src/js/screens.js
// We need to change the default behaviour of locking input with
// popup bcause of the papar meal voucher
init: function(parent, options) {
var self = this;
this._super(parent, options);
// This is a keydown handler that prevents backspace from
// doing a back navigation. It also makes sure that keys that
// do not generate a keypress in Chrom{e,ium} (eg. delete,
// backspace, ...) get passed to the keypress handler.
this.keyboard_keydown_handler = function(event){
// We overight the expected behaviour if a popup is open
if (self.gui.has_popup()) {
}
else if (event.keyCode === 8 || event.keyCode === 46) { // Backspace and Delete
event.preventDefault();
console.log('keyboard_keydown_handler')
// These do not generate keypress events in
// Chrom{e,ium}. Even if they did, we just called
// preventDefault which will cancel any keypress that
// would normally follow. So we call keyboard_handler
// explicitly with this keydown event.
self.keyboard_handler(event);
}
};
// This keyboard handler listens for keypress events. It is
// also called explicitly to handle some keydown events that
// do not generate keypress events.
this.keyboard_handler = function(event){
var key = '';
// We overight the expected behaviour if a popup is open
if (self.gui.has_popup()) {
}
else{
if (event.type === "keypress") {
if (event.keyCode === 13) { // Enter
self.validate_order();
} else if ( event.keyCode === 190 || // Dot
event.keyCode === 110 || // Decimal point (numpad)
event.keyCode === 188 || // Comma
event.keyCode === 46 ) { // Numpad dot
key = self.decimal_point;
} else if (event.keyCode >= 48 && event.keyCode <= 57) { // Numbers
key = '' + (event.keyCode - 48);
} else if (event.keyCode === 45) { // Minus
key = '-';
} else if (event.keyCode === 43) { // Plus
key = '+';
}
} else { // keyup/keydown
if (event.keyCode === 46) { // Delete
key = 'CLEAR';
} else if (event.keyCode === 8) { // Backspace
key = 'BACKSPACE';
}
}
self.payment_input(key);
event.preventDefault();
}
};
},
payment_input: function(input) {
var newbuf = this.gui.numpad_input(this.inputbuffer, input, {'firstinput': this.firstinput});
this.firstinput = (newbuf.length === 0);
if (newbuf !== this.inputbuffer) {
this.inputbuffer = newbuf;
var order = this.pos.get_order();
// We choose to unactivated the editing of the amount for the paper meal voucher
if (order.selected_paymentline && !order.selected_paymentline.is_paper_meal_voucher()) {
var amount = this.inputbuffer;
if (this.inputbuffer !== "-") {
amount = formats.parse_value(this.inputbuffer, {type: "float"}, 0.0);
}
order.selected_paymentline.set_amount(amount);
this.order_changes();
this.render_paymentlines();
this.$('.paymentline.selected .edit').text(this.format_currency_no_symbol(amount));
}
}
var order = this.pos.get_order();
if(order.selected_paymentline && order.selected_paymentline.is_dematerialized_meal_voucher()){
var total_eligible = order.get_total_meal_voucher_eligible();
var total_received = order.get_total_meal_voucher_received();
var max_amount = this.pos.config.max_meal_voucher_amount;
var current_max = total_eligible;
if (max_amount) {
current_max = Math.min(total_eligible, max_amount);
}
if (total_received > current_max){
this.gui.show_popup("alert", {
'title': _t("Meal Voucher Amount incorrect"),
'body': _t("Warning, the input amount of meal voucher is above the maximum amount of ") +
this.format_currency(current_max),
});
const max_curent_amount = current_max-total_received+order.selected_paymentline.get_amount() ;
order.selected_paymentline.set_amount(max_curent_amount);
this.order_changes();
this.render_paymentlines();
this.$('.paymentline.selected .edit').text(this.format_currency_no_symbol(max_curent_amount));
this.inputbuffer = "";
}
}
},
click_paymentmethods_meal_voucher_mixed: function(id) {
var cashregister = null;
for ( var i = 0; i < this.pos.cashregisters.length; i++ ) {
......@@ -110,7 +234,9 @@ odoo.define("pos_meal_voucher.screens", function (require) {
var paymentScreen = this.pos.gui.current_screen;
var order = this.pos.get_order();
if(order.selected_paymentline.is_dematerialized_meal_voucher()){
if(order.selected_paymentline.is_meal_voucher() && order.selected_paymentline.is_dematerialized_meal_voucher()){
var total_eligible = order.get_total_meal_voucher_eligible();
var total_received = order.get_total_meal_voucher_received();
var max_amount = this.pos.config.max_meal_voucher_amount;
......@@ -128,40 +254,40 @@ odoo.define("pos_meal_voucher.screens", function (require) {
paymentScreen.render_paymentlines();
paymentScreen.$(".paymentline.selected .edit").text(paymentScreen.format_currency_no_symbol(max_curent_amount));
}
},
payment_input: function() {
var self = this;
// If user choose paper meal voucher
// Open a popup asking for the number of the meal voucher
if(order.selected_paymentline.is_meal_voucher() && order.selected_paymentline.is_paper_meal_voucher()){
this.gui.show_popup("textinput", {
'title': _t("Meal Voucher ticket"),
'body': _t("To add a meal voucher ticket close this window and scan the ticket. If the ticket can't be read please enter the code"),
confirm: function(value) {
this.pos.get_order().remove_paymentline(order.selected_paymentline);
var paymentScreen = this.pos.gui.current_screen;
paymentScreen.reset_input();
paymentScreen.render_paymentlines();
var core = '';
odoo.define('coreservice', function(require){core=require('web.core');})
core.bus.trigger('barcode_scanned', value)
this._super.apply(this, arguments);
var order = this.pos.get_order();
if(order.selected_paymentline.is_meal_voucher()){
var total_eligible = order.get_total_meal_voucher_eligible();
var total_received = order.get_total_meal_voucher_received();
var max_amount = this.pos.config.max_meal_voucher_amount;
var current_max = total_eligible;
if (max_amount) {
current_max = Math.min(total_eligible, max_amount);
}
if (total_received > current_max){
this.gui.show_popup("alert", {
'title': _t("Meal Voucher Amount incorrect"),
'body': _t("Warning, the input amount of meal voucher is above the maximum amount of ") +
this.format_currency(current_max),
},
cancel: function(vaue) {
this.pos.get_order().remove_paymentline(order.selected_paymentline);
var paymentScreen = this.pos.gui.current_screen;
paymentScreen.reset_input();
paymentScreen.render_paymentlines();
});
const max_curent_amount = current_max-total_received+order.selected_paymentline.get_amount() ;
order.selected_paymentline.set_amount(max_curent_amount);
this.order_changes();
this.render_paymentlines();
this.$('.paymentline.selected .edit').text(this.format_currency_no_symbol(max_curent_amount));
this.inputbuffer = "";
}
},
});
}
},
render_paymentlines: function() {
var self = this;
......
......@@ -78,5 +78,10 @@
</t>
</t>
</t>
<t t-extend="TextInputPopupWidget">
<t t-jquery="p.title" t-operation="after">
<p class="body"><t t-esc=" widget.options.body || '' "/></p>
</t>
</t>
</templates>
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