diff --git a/pos_jsprintmanager/__init__.py b/pos_jsprintmanager/__init__.py index e69de29b..0650744f 100644 --- a/pos_jsprintmanager/__init__.py +++ b/pos_jsprintmanager/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_jsprintmanager/__manifest__.py b/pos_jsprintmanager/__manifest__.py index e76e6b1f..73909436 100644 --- a/pos_jsprintmanager/__manifest__.py +++ b/pos_jsprintmanager/__manifest__.py @@ -13,6 +13,10 @@ ], "data": [ "views/assets.xml", + "views/pos_config_view.xml", + ], + "qweb": [ + 'static/src/xml/pos.xml', ], "installable": True, } diff --git a/pos_jsprintmanager/models/__init__.py b/pos_jsprintmanager/models/__init__.py new file mode 100644 index 00000000..db8634ad --- /dev/null +++ b/pos_jsprintmanager/models/__init__.py @@ -0,0 +1 @@ +from . import pos_config diff --git a/pos_jsprintmanager/models/pos_config.py b/pos_jsprintmanager/models/pos_config.py new file mode 100644 index 00000000..1db4d527 --- /dev/null +++ b/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') diff --git a/pos_jsprintmanager/static/src/js/screen.js b/pos_jsprintmanager/static/src/js/screen.js index 0c41ea5b..a78fb852 100644 --- a/pos_jsprintmanager/static/src/js/screen.js +++ b/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 var cpj = new JSPM.ClientPrintJob(); - cpj.clientPrinter = new JSPM.DefaultPrinter(); + if (default_printer) { + cpj.clientPrinter = new JSPM.InstalledPrinter(default_printer); + } else { + cpj.clientPrinter = new JSPM.DefaultPrinter(); + } + if (outputFormat == 'esc-pos'){ //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); - + //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... + 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; + } else { + return this._super(); } - this.pos.get_order()._printed = true; + }, }) }); diff --git a/pos_jsprintmanager/views/pos_config_view.xml b/pos_jsprintmanager/views/pos_config_view.xml new file mode 100644 index 00000000..4b52f531 --- /dev/null +++ b/pos_jsprintmanager/views/pos_config_view.xml @@ -0,0 +1,41 @@ + + + + + + pos.config.form.jsprintmanager + pos.config + + + + +
+
+ +
+
+
+
+ Default Printer for Receipts +
+ +
+
+
+ Output format +
+ +
+
+
+
+
+
+ +