diff options
| author | Antoine Prieels <anp@odoo.com> | 2019-03-18 10:15:19 +0000 |
|---|---|---|
| committer | Antoine Prieels <anp@odoo.com> | 2019-08-08 11:53:37 +0000 |
| commit | 03b2f7b77dc6189bb485e0b834dba5f6d3d4da2c (patch) | |
| tree | 46df5c8eff19ae44692af874dfd136f6cd1ad519 /addons/pos_restaurant/static/src/js | |
| parent | dd7de1bcb65d339e5865afcc980cbb4d171fbb74 (diff) | |
[REF] pos: Replace hw_escpos by PrinterDriver
ESCPOS printers are now supported as IoT Devices, just like any other
printer. We now transform the receipts to JPGs, transform these JPGs
into ESCPOS commands and send them via Cups, adding support for network
printers. Since we now print images, we can now print special
characters and therefore add support for other languages such as
Arabic.
The JPG is generated in the browser, with the help of html2canvas.
`hw_escpos` is left untouched to allow backward compatibility and
should be removed when v12 is no longer supported.
In the PoS, all the code for printing has been moved from ProxyDevice
to a separated JS file.
TaskID: 1939455
Diffstat (limited to 'addons/pos_restaurant/static/src/js')
| -rw-r--r-- | addons/pos_restaurant/static/src/js/multiprint.js | 51 | ||||
| -rw-r--r-- | addons/pos_restaurant/static/src/js/printbill.js | 2 |
2 files changed, 12 insertions, 41 deletions
diff --git a/addons/pos_restaurant/static/src/js/multiprint.js b/addons/pos_restaurant/static/src/js/multiprint.js index c48ecae1c5d..d1cfbefbe04 100644 --- a/addons/pos_restaurant/static/src/js/multiprint.js +++ b/addons/pos_restaurant/static/src/js/multiprint.js @@ -4,41 +4,20 @@ odoo.define('pos_restaurant.multiprint', function (require) { var models = require('point_of_sale.models'); var screens = require('point_of_sale.screens'); var core = require('web.core'); -var mixins = require('web.mixins'); -var Session = require('web.Session'); +var Printer = require('point_of_sale.Printer').Printer; var QWeb = core.qweb; -var Printer = core.Class.extend(mixins.PropertiesMixin,{ - init: function(parent,options){ - mixins.PropertiesMixin.init.call(this); - this.setParent(parent); - options = options || {}; - var url = options.url || 'http://localhost:8069'; - this.connection = new Session(undefined,url, { use_cors: true}); - this.host = url; - this.receipt_queue = []; - }, - print: function(receipt){ - var self = this; - if(receipt){ - this.receipt_queue.push(receipt); +models.PosModel = models.PosModel.extend({ + create_printer: function (config) { + var url = config.proxy_ip || ''; + if(url.indexOf('//') < 0) { + url = 'http://' + url; } - function send_printing_job(){ - if(self.receipt_queue.length > 0){ - var r = self.receipt_queue.shift(); - var options = {shadow: true, timeout: 5000}; - self.connection.rpc('/hw_proxy/print_xml_receipt', {receipt: r}, options) - .then(function(){ - send_printing_job(); - },function(error, event){ - self.receipt_queue.unshift(r); - console.log('There was an error while trying to print the order:'); - console.log(error); - }); - } + if(url.indexOf(':', url.indexOf('//') + 2) < 0) { + url = url + ':8069'; } - send_printing_job(); + return new Printer(url, this); }, }); @@ -58,14 +37,7 @@ models.load_models({ for(var i = 0; i < printers.length; i++){ if(active_printers[printers[i].id]){ - var url = printers[i].proxy_ip || ''; - if(url.indexOf('//') < 0){ - url = 'http://'+url; - } - if(url.indexOf(':',url.indexOf('//')+2) < 0){ - url = url+':8069'; - } - var printer = new Printer(self,{url:url}); + var printer = self.create_printer(printers[i]); printer.config = printers[i]; self.printers.push(printer); @@ -318,7 +290,7 @@ models.Order = models.Order.extend({ var changes = this.computeChanges(printers[i].config.product_categories_ids); if ( changes['new'].length > 0 || changes['cancelled'].length > 0){ var receipt = QWeb.render('OrderChangeReceipt',{changes:changes, widget:this}); - printers[i].print(receipt); + printers[i].print_receipt(receipt); } } }, @@ -386,7 +358,6 @@ screens.OrderWidget.include({ }); return { - Printer: Printer, SubmitOrderButton: SubmitOrderButton, } diff --git a/addons/pos_restaurant/static/src/js/printbill.js b/addons/pos_restaurant/static/src/js/printbill.js index 39b3d0c7608..ba6c3ada734 100644 --- a/addons/pos_restaurant/static/src/js/printbill.js +++ b/addons/pos_restaurant/static/src/js/printbill.js @@ -34,7 +34,7 @@ var PrintBillButton = screens.ActionButtonWidget.extend({ if(order.get_orderlines().length > 0){ var receipt = order.export_for_printing(); receipt.bill = true; - this.pos.proxy.print_receipt(QWeb.render('BillReceipt',{ + this.pos.proxy.printer.print_receipt(QWeb.render('BillReceipt',{ receipt: receipt, widget: this, pos: this.pos, order: order, })); } |
