diff --git a/pos_ticket_logo/README.rst b/pos_ticket_logo/README.rst new file mode 100644 index 00000000..366150d4 --- /dev/null +++ b/pos_ticket_logo/README.rst @@ -0,0 +1,50 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: AGPLv3 License + +POS Ticket logo +=============== + +Add company logo in POS ticket + + +Motivation +========== + +```XmlReceipt``` Qweb report is used when ```iface_print_via_proxy``` config is **True**: +https://github.com/odoo/odoo/blob/8.0/addons/point_of_sale/static/src/js/screens.js#L1341 + +But in the case ```iface_print_via_proxy``` config is **False**, ```PosTicket``` +Qweb report is used, and company_logo is not used: +https://github.com/odoo/odoo/blob/8.0/addons/point_of_sale/static/src/js/screens.js#L984 + +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/8.0/addons/point_of_sale/static/src/js/models.js#L371 +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: + + +Credits +======= + +Contributors +------------ + +* Antonio Espinosa +* Endika Iglesias + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/pos_ticket_logo/__init__.py b/pos_ticket_logo/__init__.py new file mode 100644 index 00000000..f3ebd3ec --- /dev/null +++ b/pos_ticket_logo/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Python source code encoding : https://www.python.org/dev/peps/pep-0263/ +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright : +# (c) 2014 Antiun Ingenieria, SL (Madrid, Spain, http://www.antiun.com) +# Endika Iglesias +# Antonio Espinosa +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/pos_ticket_logo/__openerp__.py b/pos_ticket_logo/__openerp__.py new file mode 100644 index 00000000..e035b6ee --- /dev/null +++ b/pos_ticket_logo/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Python source code encoding : https://www.python.org/dev/peps/pep-0263/ +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright : +# (c) 2014 Antiun Ingenieria, SL (Madrid, Spain, http://www.antiun.com) +# Endika Iglesias +# Antonio Espinosa +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Pos ticket logo', + 'category': 'Point Of Sale', + 'version': '1.0', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'views/pos_ticket_logo_report_receipt_report.xml', + 'views/pos_template.xml', + ], + 'qweb': [ + 'static/src/xml/pos.xml', + ], + 'author': 'Antiun IngenierĂ­a S.L.', + 'website': 'http://www.antiun.com', + 'license': 'AGPL-3', + 'installable': True, +} diff --git a/pos_ticket_logo/static/description/icon.png b/pos_ticket_logo/static/description/icon.png new file mode 100644 index 00000000..e060fb4a Binary files /dev/null and b/pos_ticket_logo/static/description/icon.png differ diff --git a/pos_ticket_logo/static/src/js/main.js b/pos_ticket_logo/static/src/js/main.js new file mode 100644 index 00000000..90903f5b --- /dev/null +++ b/pos_ticket_logo/static/src/js/main.js @@ -0,0 +1,73 @@ +/** + * # -*- coding: utf-8 -*- + * ############################################################################## + * # + * # OpenERP, Open Source Management Solution + * # This module copyright : + * # (c) 2014 Antiun Ingenieria, SL (Madrid, Spain, http://www.antiun.com) + * # Endika Iglesias + * # Antonio Espinosa + * # + * # This program is free software: you can redistribute it and/or modify + * # it under the terms of the GNU Affero General Public License as + * # published by the Free Software Foundation, either version 3 of the + * # License, or (at your option) any later version. + * # + * # This program is distributed in the hope that it will be useful, + * # but WITHOUT ANY WARRANTY; without even the implied warranty of + * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * # GNU Affero General Public License for more details. + * # + * # You should have received a copy of the GNU Affero General Public License + * # along with this program. If not, see . + * # + * ############################################################################## + */ + +// Check jQuery available +if (typeof jQuery === 'undefined') { throw new Error('POS Ticket Logo Addon requires jQuery'); } + ++function ($) { + 'use strict'; + + openerp.pos_ticket_logo = function (instance, module) { + var _t = instance.web._t, + _lt = instance.web._lt; + var QWeb = instance.web.qweb; + + var PosModelParent = instance.point_of_sale.PosModel; + instance.point_of_sale.PosModel = instance.point_of_sale.PosModel.extend({ + load_server_data: function(){ + var self = this; + var loaded = PosModelParent.prototype.load_server_data.apply(this, arguments); + $.when(loaded).then(function(){ + self.company_logo.onload = function(){ + var img = self.company_logo; + var ratio = 1; + var targetwidth = 260; + var maxheight = 120; + if( img.width !== targetwidth ){ + ratio = targetwidth / img.width; + } + if( img.height * ratio > maxheight ){ + ratio = maxheight / img.height; + } + var width = Math.floor(img.width * ratio); + var height = Math.floor(img.height * ratio); + var c = document.createElement('canvas'); + c.width = width; + c.height = height; + var ctx = c.getContext('2d'); + ctx.drawImage(self.company_logo,0,0, width, height); + + self.company_logo_base64 = c.toDataURL(); + loaded.resolve(); + }; + self.company_logo.src = '/web/binary/image?model=res.company&id=' + self.company.id + '&field=logo'; + }); + return loaded; + } + }); + }; + +}(jQuery); diff --git a/pos_ticket_logo/static/src/xml/pos.xml b/pos_ticket_logo/static/src/xml/pos.xml new file mode 100644 index 00000000..80262d61 --- /dev/null +++ b/pos_ticket_logo/static/src/xml/pos.xml @@ -0,0 +1,10 @@ + + + + +
+
+
+
+
+
diff --git a/pos_ticket_logo/views/pos_template.xml b/pos_ticket_logo/views/pos_template.xml new file mode 100644 index 00000000..eb29caab --- /dev/null +++ b/pos_ticket_logo/views/pos_template.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/pos_ticket_logo/views/pos_ticket_logo_report_receipt_report.xml b/pos_ticket_logo/views/pos_ticket_logo_report_receipt_report.xml new file mode 100644 index 00000000..8f8f34e6 --- /dev/null +++ b/pos_ticket_logo/views/pos_ticket_logo_report_receipt_report.xml @@ -0,0 +1,17 @@ + + + + + +