Browse Source

add pos_jsprintmanager

pull/474/head
Jordi Ballester Alomar 5 years ago
committed by Adrià Gil Sorribes
parent
commit
66198994c9
  1. 0
      pos_jsprintmanager/__init__.py
  2. 18
      pos_jsprintmanager/__manifest__.py
  3. 11
      pos_jsprintmanager/readme/CONFIGURE.rst
  4. 6
      pos_jsprintmanager/readme/CONTRIBUTORS.rst
  5. 11
      pos_jsprintmanager/readme/DESCRIPTION.rst
  6. 3
      pos_jsprintmanager/readme/USAGE.rst
  7. 71
      pos_jsprintmanager/static/src/js/screen.js
  8. 20
      pos_jsprintmanager/views/assets.xml

0
pos_jsprintmanager/__init__.py

18
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,
}

11
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.

6
pos_jsprintmanager/readme/CONTRIBUTORS.rst

@ -0,0 +1,6 @@
* Endika Iglesias <endikaig@antiun.com>
* `Tecnativa <https://www.tecnativa.com>`_:
* Antonio Espinosa
* David Vidal

11
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 <https://github.com/odoo/odoo/blob/11.0/addons/point_of_sale/static/src/js/models.js#L481>`_:
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.

3
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.

71
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 += '<option>' + myPrinters[i] + '</option>';
}
$('#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;
},
})
});

20
pos_jsprintmanager/views/assets.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020-Today: ForgeFlow, S.L. (<https://www.forgeflow.com/>)
@author: Jordi Ballester Alomar (https://twitter.com/jordibforgeflow)
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
-->
<odoo>
<template id="assets_frontend" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/deflate.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/zip.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/zip-ext.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/JSPrintManager.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/html2canvas.min.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/lib/jsprintmanager/bluebird.min.js"/>
<script type="text/javascript" src="/pos_jsprintmanager/static/src/js/screen.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save