Commit da457105 by Yvon

a quick solution to compute meal voucher amount before sending it to tpe if…

a quick solution to compute meal voucher amount before sending it to tpe if pos_payment_terminal can be made dependant on pos_meal_voucher
parent 96d233f9
......@@ -28,7 +28,9 @@
'summary': 'Manage Payment Terminal device from POS front end',
'author': "Aurélien DUMAINE,Akretion,Odoo Community Association (OCA)",
'license': 'AGPL-3',
'depends': ['point_of_sale'],
# We want to make sure that payment_terminal proper code will be called after the amount update by making payment_terminal dependant from meal_voucher
# A cleaner solution may be to create a new module that will depend on pos_payement_terminal and pos_meal_voucher
'depends': ['point_of_sale','pos_meal_voucher'],
'data': [
'pos_payment_terminal_view.xml',
'security/security.xml',
......
......@@ -48,7 +48,7 @@ odoo.define('pos_payment_terminal.pos_payment_terminal', function (require) {
},
get_data_send: function(order, line, currency_iso) {
var data = {
'amount' : order.get_due(line),
'amount' : round_pr(Math.max(0,line.get_amount()), this.pos.currency.rounding),
'currency_iso' : currency_iso,
'payment_mode' : line.cashregister.journal.payment_mode,
'wait_terminal_answer' : this.wait_terminal_answer(),
......
......@@ -314,8 +314,7 @@ odoo.define("pos_meal_voucher.screens", function (require) {
// if user choose card meal voucher
if(order.selected_paymentline.is_meal_voucher() && order.selected_paymentline.is_dematerialized_meal_voucher()){
// update selected (last) payment line & order with meal voucher data
function update_order_meal_voucher_data(issuer = '') {
function compute_order_meal_voucher_amount() {
var total_eligible = order.get_total_meal_voucher_eligible();
var total_received = order.get_total_meal_voucher_received();
var max_amount = self.pos.config.max_meal_voucher_amount;
......@@ -326,14 +325,23 @@ odoo.define("pos_meal_voucher.screens", function (require) {
// Check how much is still possible to pay with meal voucher
// The selected line is "by default" set to the rest to pay of the order
const max_curent_amount = current_max-total_received +order.selected_paymentline.get_amount();
return current_max-total_received +order.selected_paymentline.get_amount();
}
// We can't wait confirm function in this.gui.show_popup to be asynchronously called
// to update paymentline with proper amount because this amount will be sent in the interval
// to payment terminal.
// We ensure payment_terminal proper code is called after the amount update by making
// payment_terminal dependant from meal_voucher
const max_curent_amount = compute_order_meal_voucher_amount();
order.selected_paymentline.set_amount(max_curent_amount);
order.selected_paymentline.set_meal_voucher_issuer(issuer);
// update selected (last) payment line & order with meal voucher data
function update_order_meal_voucher_data(amount,issuer = '') {
order.selected_paymentline.set_meal_voucher_issuer(issuer);
paymentScreen.order_changes();
paymentScreen.render_paymentlines();
paymentScreen.$(".paymentline.selected .edit").text(paymentScreen.format_currency_no_symbol(max_curent_amount));
paymentScreen.$(".paymentline.selected .edit").text(paymentScreen.format_currency_no_symbol(amount));
}
// If required by the config, ask for the meal voucher issuer
......@@ -357,14 +365,14 @@ odoo.define("pos_meal_voucher.screens", function (require) {
'selectData': select_data,
confirm: function(value) {
let issuer = value;
update_order_meal_voucher_data(issuer)
update_order_meal_voucher_data(max_curent_amount,issuer)
},
cancel: function(value) {
self.remove_selected_paymentline(order);
},
});
} else {
update_order_meal_voucher_data();
update_order_meal_voucher_data(max_curent_amount);
}
}
......
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