Browse Source

add esc-pos

pull/474/head
Jordi Ballester Alomar 5 years ago
committed by Adrià Gil Sorribes
parent
commit
94457c23c4
  1. 1
      pos_jsprintmanager/__init__.py
  2. 4
      pos_jsprintmanager/__manifest__.py
  3. 1
      pos_jsprintmanager/models/__init__.py
  4. 18
      pos_jsprintmanager/models/pos_config.py
  5. 62
      pos_jsprintmanager/static/src/js/screen.js
  6. 41
      pos_jsprintmanager/views/pos_config_view.xml

1
pos_jsprintmanager/__init__.py

@ -0,0 +1 @@
from . import models

4
pos_jsprintmanager/__manifest__.py

@ -13,6 +13,10 @@
], ],
"data": [ "data": [
"views/assets.xml", "views/assets.xml",
"views/pos_config_view.xml",
],
"qweb": [
'static/src/xml/pos.xml',
], ],
"installable": True, "installable": True,
} }

1
pos_jsprintmanager/models/__init__.py

@ -0,0 +1 @@
from . import pos_config

18
pos_jsprintmanager/models/pos_config.py

@ -0,0 +1,18 @@
from odoo import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
use_jsprintmanager = fields.Boolean()
jsprintmanager_default_receipt_printer = fields.Char(
string='Default Printer for Receipts',
help='Enter the name of the default printer to be used in receipts')
jsprintmanager_output_format = fields.Selection(
string='Printer output format',
selection=[
('normal', 'Normal'),
('escpos', 'ESC/POS')
],
help='Enter the format used by the printer')

62
pos_jsprintmanager/static/src/js/screen.js

@ -44,28 +44,78 @@ odoo.define("pos_jsprintmanager.screen", function (require) {
} }
}, },
print_web: function() {
if (this.jspmWSStatus) {
//generate an image of HTML content through html2canvas utility
html2canvas(document.getElementsByClassName('pos-sale-ticket')[0], { scale: 5 }).then(function (canvas) {
get_escpos_receipt_cmds: function() {
var order = this.pos.get_order();
var receipt = order.export_for_printing();
var orderlines = order.get_orderlines();
var paymentlines = order.get_paymentlines();
var esc = '\x1B'; //ESC byte in hex notation
var newLine = '\x0A'; //LF byte in hex notation
var cmds = esc + "@"; //Initializes the printer (ESC @)
cmds += esc + '!' + '\x38'; //Emphasized + Double-height + Double-width mode selected (ESC ! (8 + 16 + 32)) 56 dec => 38 hex
cmds += 'BEST DEAL STORES'; //text to print
cmds += newLine + newLine;
cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
cmds += 'COOKIES 5.00';
cmds += newLine;
cmds += 'MILK 65 Fl oz 3.78';
cmds += newLine + newLine;
cmds += 'SUBTOTAL 8.78';
cmds += newLine;
cmds += 'TAX 5% 0.44';
cmds += newLine;
cmds += 'TOTAL 9.22';
cmds += newLine;
cmds += 'CASH TEND 10.00';
cmds += newLine;
cmds += 'CASH DUE 0.78';
cmds += newLine + newLine;
cmds += esc + '!' + '\x18'; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex
cmds += '# ITEMS SOLD 2';
cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
cmds += newLine + newLine;
cmds += '11/03/13 19:53:17';
return cmds
},
print_web: function() {
if (this.jspmWSStatus && this.pos.config.use_jsprintmanager == true) {
var outputFormat = this.pos.config.jsprintmanager_output_format;
var default_printer = this.pos.config.jsprintmanager_default_receipt_printer;
//Create a ClientPrintJob //Create a ClientPrintJob
var cpj = new JSPM.ClientPrintJob(); var cpj = new JSPM.ClientPrintJob();
if (default_printer) {
cpj.clientPrinter = new JSPM.InstalledPrinter(default_printer);
} else {
cpj.clientPrinter = new JSPM.DefaultPrinter(); cpj.clientPrinter = new JSPM.DefaultPrinter();
}
if (outputFormat == 'esc-pos'){
//Set content to print...
//Create ESP/POS commands for sample label
var cmds = this.get_escpos_receipt_cmds()
cpj.printerCommands = cmds;
//Send print job to printer!
cpj.sendToClient();
} else {
//generate an image of HTML content through html2canvas utility
var ticket = document.getElementsByClassName('pos-sale-ticket')[0]
html2canvas(ticket, {scale: 10, width: 900}).then(function (canvas) {
//Set content to print... //Set content to print...
var b64Prefix = "data:image/png;base64,"; var b64Prefix = "data:image/png;base64,";
var imgBase64DataUri = canvas.toDataURL("image/png"); var imgBase64DataUri = canvas.toDataURL("image/png");
var imgBase64Content = imgBase64DataUri.substring(b64Prefix.length, imgBase64DataUri.length); var imgBase64Content = imgBase64DataUri.substring(b64Prefix.length, imgBase64DataUri.length);
var myImageFile = new JSPM.PrintFile(imgBase64Content, JSPM.FileSourceType.Base64, 'myFileToPrint.png', 1); var myImageFile = new JSPM.PrintFile(imgBase64Content, JSPM.FileSourceType.Base64, 'myFileToPrint.png', 1);
//add file to print job //add file to print job
cpj.files.push(myImageFile); cpj.files.push(myImageFile);
//Send print job to printer! //Send print job to printer!
cpj.sendToClient(); cpj.sendToClient();
}); });
} }
this.pos.get_order()._printed = true; this.pos.get_order()._printed = true;
} else {
return this._super();
}
}, },
}) })
}); });

41
pos_jsprintmanager/views/pos_config_view.xml

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_pos_config_view_form_jsprintmanager" model="ir.ui.view">
<field name="name">pos.config.form.jsprintmanager</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="priority" eval="30"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='receipt']" position="inside">
<div class="col-12 col-lg-6 o_setting_box" id="use_jsprintmanager">
<div class="o_setting_left_pane">
<field name="use_jsprintmanager"/>
</div>
<div class="o_setting_right_pane">
<label for="use_jsprintmanager"/>
<div class="text-muted">
Use JS Print Manager to print receipts
</div>
</div>
<div id='jsprintmanager_default_receipt_printer' class="o_setting_right_pane" attrs="{'invisible' : [('use_jsprintmanager', '=', False)]}">
<span class="o_form_label">Default Printer for Receipts</span>
<div class="content-group mt16">
<field name="jsprintmanager_default_receipt_printer" colspan="4"
nolabel="1"/>
</div>
</div>
<div id='jsprintmanager_output_format' class="o_setting_right_pane" attrs="{'invisible' : [('use_jsprintmanager', '=', False)]}">
<span class="o_form_label">Output format</span>
<div class="content-group mt16">
<field name="jsprintmanager_output_format" colspan="4"
nolabel="1"/>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save