diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/pos_epson_printer/static/src/js/printers.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/pos_epson_printer/static/src/js/printers.js')
| -rw-r--r-- | addons/pos_epson_printer/static/src/js/printers.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/addons/pos_epson_printer/static/src/js/printers.js b/addons/pos_epson_printer/static/src/js/printers.js new file mode 100644 index 00000000..c396c611 --- /dev/null +++ b/addons/pos_epson_printer/static/src/js/printers.js @@ -0,0 +1,101 @@ + +odoo.define('pos_epson_printer.Printer', function (require) { +"use strict"; + +const { Gui } = require('point_of_sale.Gui'); +var core = require('web.core'); +var PrinterMixin = require('point_of_sale.Printer').PrinterMixin; + +var _t = core._t; + +var EpsonPrinter = core.Class.extend(PrinterMixin, { + init: function (ip, pos) { + PrinterMixin.init.call(this, arguments); + this.pos = pos; + this.ePOSDevice = new epson.ePOSDevice(); + var port = window.location.protocol === 'http:' ? '8008' : '8043'; + this.ePOSDevice.connect(ip, port, this.callback_connect.bind(this), {eposprint: true}); + }, + + callback_connect: function (resultConnect) { + var deviceId = 'local_printer'; + var options = {'crypto' : false, 'buffer' : false}; + if ((resultConnect == 'OK') || (resultConnect == 'SSL_CONNECT_OK')) { + this.ePOSDevice.createDevice(deviceId, this.ePOSDevice.DEVICE_TYPE_PRINTER, options, this.callback_createDevice.bind(this)); + } else { + Gui.showPopup('ErrorPopup', { + 'title': _t('Connection to the printer failed'), + 'body': _t('Please check if the printer is still connected, if the configured IP address is correct and if your printer supports the ePOS protocol.'), + }); + } + }, + + callback_createDevice: function (deviceObj, errorCode) { + if (deviceObj === null) { + Gui.showPopup('ErrorPopup', { + 'title': _t('Connection to the printer failed'), + 'body': _t('Please check if the printer is still connected. Error code: ') + errorCode, + }); + return; + } + this.printer = deviceObj; + this.printer.onreceive = function(response){ + if (!response.success) { + Gui.showPopup('ErrorPopup', { + 'title': _t('Epson ePOS Error'), + 'body': _t('An error happened while sending data to the printer. Error code: ') + response.code, + }); + } + }; + }, + + /** + * Create the print request for webPRNT from a canvas + * + * @override + */ + process_canvas: function (canvas) { + if (this.printer) { + this.printer.addTextAlign(this.printer.ALIGN_CENTER); + this.printer.addImage(canvas.getContext('2d'), 0, 0, canvas.width, canvas.height); + this.printer.addCut(); + } + }, + + /** + * @override + */ + open_cashbox: function () { + if (this.printer) { + this.printer.addPulse(); + this.printer.send(); + } + }, + + /** + * @override + */ + send_printing_job: function () { + if (this.printer) { + this.printer.send(); + return { + result: true + }; + } + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Not applicable to Epson ePOS + * @override + */ + _onIoTActionFail: function () {}, + _onIoTActionResult: function () {}, +}); + +return EpsonPrinter; + +}); |
