From 66198994c944862906acd6882aa39076804479d4 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Thu, 19 Mar 2020 10:19:07 +0100 Subject: [PATCH 1/7] add pos_jsprintmanager --- pos_jsprintmanager/__init__.py | 0 pos_jsprintmanager/__manifest__.py | 18 ++++++ pos_jsprintmanager/readme/CONFIGURE.rst | 11 ++++ pos_jsprintmanager/readme/CONTRIBUTORS.rst | 6 ++ pos_jsprintmanager/readme/DESCRIPTION.rst | 11 ++++ pos_jsprintmanager/readme/USAGE.rst | 3 + pos_jsprintmanager/static/src/js/screen.js | 71 ++++++++++++++++++++++ pos_jsprintmanager/views/assets.xml | 20 ++++++ 8 files changed, 140 insertions(+) create mode 100644 pos_jsprintmanager/__init__.py create mode 100644 pos_jsprintmanager/__manifest__.py create mode 100644 pos_jsprintmanager/readme/CONFIGURE.rst create mode 100644 pos_jsprintmanager/readme/CONTRIBUTORS.rst create mode 100644 pos_jsprintmanager/readme/DESCRIPTION.rst create mode 100644 pos_jsprintmanager/readme/USAGE.rst create mode 100644 pos_jsprintmanager/static/src/js/screen.js create mode 100644 pos_jsprintmanager/views/assets.xml diff --git a/pos_jsprintmanager/__init__.py b/pos_jsprintmanager/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pos_jsprintmanager/__manifest__.py b/pos_jsprintmanager/__manifest__.py new file mode 100644 index 00000000..e76e6b1f --- /dev/null +++ b/pos_jsprintmanager/__manifest__.py @@ -0,0 +1,18 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +{ + "name": "Pos JS Print Manager", + "category": "Point Of Sale", + "version": "12.0.1.0.0", + "author": "ForgeFlow, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "LGPL-3", + "depends": [ + "point_of_sale", + ], + "data": [ + "views/assets.xml", + ], + "installable": True, +} diff --git a/pos_jsprintmanager/readme/CONFIGURE.rst b/pos_jsprintmanager/readme/CONFIGURE.rst new file mode 100644 index 00000000..e08bb247 --- /dev/null +++ b/pos_jsprintmanager/readme/CONFIGURE.rst @@ -0,0 +1,11 @@ +To add a logo to any given company: + +#. Go to *Settings > Users & Companies > Companies* +#. Edit one and add the logo editing the top left corner image. + +To configure receipt web print in the PoS (is the default setting): + +#. Go to *Point of Sale > Configuration > Point of Sale*. +#. Edit the one you want to configure. +#. If the *PosBox* setting is enabled the *Receipt Printer* setting should be + disabled. diff --git a/pos_jsprintmanager/readme/CONTRIBUTORS.rst b/pos_jsprintmanager/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..fdd98c7a --- /dev/null +++ b/pos_jsprintmanager/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Endika Iglesias + +* `Tecnativa `_: + + * Antonio Espinosa + * David Vidal diff --git a/pos_jsprintmanager/readme/DESCRIPTION.rst b/pos_jsprintmanager/readme/DESCRIPTION.rst new file mode 100644 index 00000000..b1b03fd1 --- /dev/null +++ b/pos_jsprintmanager/readme/DESCRIPTION.rst @@ -0,0 +1,11 @@ +A different receipt template is used if the PoS ticket is printed via web or +via proxy. In the case the ticket is printed via web (through the browser) the +company logo isn't printed. This module adds it. + +In other hand, company_logo is loaded using `/web/binary/company_logo` +controller `that returns a 150px wide logo `_: + +but after that logo is resized to 300px width, so a pixelled logo appears even +original logo is 300px wide. +That's why we override how company_logo is loaded. We also resized it to 260px +(not 300px) wide because appears cut in PDF. diff --git a/pos_jsprintmanager/readme/USAGE.rst b/pos_jsprintmanager/readme/USAGE.rst new file mode 100644 index 00000000..8bf546e6 --- /dev/null +++ b/pos_jsprintmanager/readme/USAGE.rst @@ -0,0 +1,3 @@ +#. Open a new PoS session. +#. Make an order and validate it. +#. You should see the company logo in the receipt preview. diff --git a/pos_jsprintmanager/static/src/js/screen.js b/pos_jsprintmanager/static/src/js/screen.js new file mode 100644 index 00000000..e4fbc47d --- /dev/null +++ b/pos_jsprintmanager/static/src/js/screen.js @@ -0,0 +1,71 @@ +/* License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + + +odoo.define("pos_jsprintmanager.screen", function (require) { + "use strict"; + + var core = require('web.core'); + var _t = core._t; + var PosBaseWidget = require('point_of_sale.BaseWidget'); + var screens = require('point_of_sale.screens'); + + screens.ReceiptScreenWidget.include({ + + //Check JSPM WebSocket status + jspmWSStatus: function() { + if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Open) + return true; + else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Closed) { + alert('JSPrintManager (JSPM) is not installed or not running! Download JSPM Client App from https://neodynamic.com/downloads/jspm'); + return false; + } + else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.BlackListed) { + alert('JSPM has blacklisted this website!'); + return false; + } + }, + + init: function(parent,options){ + this._super(parent,options); + JSPM.JSPrintManager.auto_reconnect = true; + JSPM.JSPrintManager.start(); + var jspmWSStatus = this.jspmWSStatus() + JSPM.JSPrintManager.WS.onStatusChanged = function () { + if (jspmWSStatus) { + //get client installed printers + JSPM.JSPrintManager.getPrinters().then(function (myPrinters) { + var options = ''; + for (var i = 0; i < myPrinters.length; i++) { + options += ''; + } + $('#installedPrinterName').html(options); + }) + } + } + }, + + print_web: function() { + if (this.jspmWSStatus) { + //generate an image of HTML content through html2canvas utility + html2canvas(document.getElementsByClassName('pos-receipt-container')[0], { scale: 5 }).then(function (canvas) { + + //Create a ClientPrintJob + var cpj = new JSPM.ClientPrintJob(); + cpj.clientPrinter = new JSPM.DefaultPrinter(); + //Set content to print... + var b64Prefix = "data:image/png;base64,"; + var imgBase64DataUri = canvas.toDataURL("image/png"); + var imgBase64Content = imgBase64DataUri.substring(b64Prefix.length, imgBase64DataUri.length); + + var myImageFile = new JSPM.PrintFile(imgBase64Content, JSPM.FileSourceType.Base64, 'myFileToPrint.png', 1); + //add file to print job + cpj.files.push(myImageFile); + + //Send print job to printer! + cpj.sendToClient(); + }); + } + this.pos.get_order()._printed = true; + }, + }) +}); diff --git a/pos_jsprintmanager/views/assets.xml b/pos_jsprintmanager/views/assets.xml new file mode 100644 index 00000000..f9fd4e60 --- /dev/null +++ b/pos_jsprintmanager/views/assets.xml @@ -0,0 +1,20 @@ + + + + +