|
|
/* © 2020 Le Filament (<http://www.le-filament.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('vracoop_balance_ticketing.screens', function (require) { "use strict";
var chrome = require('point_of_sale.chrome'); var gui = require('point_of_sale.gui'); var models = require('point_of_sale.models'); var screens = require('point_of_sale.screens'); var popups = require('point_of_sale.popups'); var container = require('pos_container.container');
var models_and_db = require('pos_container.models_and_db'); var screen_vrac = require('vracoop_pos_free_balance_v2.container_balance');
var core = require('web.core'); var rpc = require('web.rpc'); var utils = require('web.utils'); var QWeb = core.qweb; var _t = core._t;
// Screen confirmation de la pesée
screen_vrac.ConfirmationScreen.include({
show: function(){ this._super(); var self = this;
this.render_change(); this.render_receipt(); this.handle_auto_print(); },
handle_auto_print: function() { if (this.should_auto_print()) { this.print(); this.click_next(); // }
} else { this.lock_screen(false); } },
get_barcode_data: function () { var transaction = this.gui.get_current_screen_param('transaction'); var num_ean13 = this.pos.config.prefix + transaction.ean13.slice(2) return num_ean13; },
should_auto_print: function() { return this.pos.config.is_ticket_print_auto && !this.pos.get_order()._printed; },
lock_screen: function(locked) { this._locked = locked; if (locked) { this.$('.next').removeClass('highlight'); } else { this.$('.next').addClass('highlight'); } }, get_receipt_render_env: function() { var order = this.pos.get_order(); var transaction = this.gui.get_current_screen_param('transaction'); var num_ean13 = this.pos.config.prefix + transaction.ean13.slice(2) var width_pix = (Math.round(this.pos.config.page_width * 3.78)).toString() + "px";
return { widget: this, pos: this.pos, order: order, transaction: transaction, num_ean13: num_ean13, width: width_pix, }; }, print_web: function() { if ($.browser.safari) { document.execCommand('print', false, null); } else { try { window.print(); } catch(err) { if (navigator.userAgent.toLowerCase().indexOf("android") > -1) { this.gui.show_popup('error',{ 'title':_t('Printing is not supported on some android browsers'), 'body': _t('Printing is not supported on some android browsers due to no default printing protocol is available. It is possible to print your tickets by making use of an IoT Box.'), }); } else { throw err; } } } this.pos.get_order()._printed = true; }, print_xml: function() { var receipt = QWeb.render('XmlReceiptBls', this.get_receipt_render_env());
this.pos.proxy.print_receipt(receipt); this.pos.get_order()._printed = true; }, print: function() { var self = this;
if (!this.pos.config.is_ticket_print_via_proxy) { // browser (html) printing
// The problem is that in chrome the print() is asynchronous and doesn't
// execute until all rpc are finished. So it conflicts with the rpc used
// to send the orders to the backend, and the user is able to go to the next
// screen before the printing dialog is opened. The problem is that what's
// printed is whatever is in the page when the dialog is opened and not when it's called,
// and so you end up printing the product list instead of the receipt...
//
// Fixing this would need a re-architecturing
// of the code to postpone sending of orders after printing.
//
// But since the print dialog also blocks the other asynchronous calls, the
// button enabling in the setTimeout() is blocked until the printing dialog is
// closed. But the timeout has to be big enough or else it doesn't work
// 1 seconds is the same as the default timeout for sending orders and so the dialog
// should have appeared before the timeout... so yeah that's not ultra reliable.
this.lock_screen(true);
setTimeout(function(){ self.lock_screen(false); }, 1000);
this.print_web(); } else { // proxy (xml) printing
this.print_xml(); this.lock_screen(false); } }, click_next: function() { this.set_price(0); this.pos.proxy.reset_tare(); this.gui.show_screen('presentation'); }, click_back: function() { // Placeholder method for ReceiptScreen extensions that
// can go back ...
}, renderElement: function() { var self = this; this._super(); this.$('.next').click(function(){ if (!self._locked) { self.click_next(); } }); this.$('.back').click(function(){ if (!self._locked) { self.click_back(); } }); this.$('.button.print').click(function(){ if (!self._locked) { self.print(); } });
}, render_change: function() { var self = this; this.$('.change-value').html(this.format_currency(this.pos.get_order().get_change())); var order = this.pos.get_order(); var order_screen_params = order.get_screen_data('params'); var button_print_invoice = this.$('h2.print_invoice'); if (order_screen_params && order_screen_params.button_print_invoice) { button_print_invoice.show(); } else { button_print_invoice.hide(); } }, render_receipt: function() { this.$('.pos-ticket-container').html(QWeb.render('PosTicketBls', this.get_receipt_render_env())); }, });
});
|