Antonio Espinosa
10 years ago
committed by
Pierrick Brun
8 changed files with 229 additions and 0 deletions
-
50pos_ticket_logo/README.rst
-
24pos_ticket_logo/__init__.py
-
43pos_ticket_logo/__openerp__.py
-
BINpos_ticket_logo/static/description/icon.png
-
73pos_ticket_logo/static/src/js/main.js
-
10pos_ticket_logo/static/src/xml/pos.xml
-
12pos_ticket_logo/views/pos_template.xml
-
17pos_ticket_logo/views/pos_ticket_logo_report_receipt_report.xml
@ -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 <antonioea@antiun.com> |
||||
|
* Endika Iglesias <endikaig@antiun.com> |
||||
|
|
||||
|
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. |
@ -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 <endikaig@antiun.com> |
||||
|
# Antonio Espinosa <antonioea@antiun.com> |
||||
|
# |
||||
|
# 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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
@ -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 <endikaig@antiun.com> |
||||
|
# Antonio Espinosa <antonioea@antiun.com> |
||||
|
# |
||||
|
# 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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
'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, |
||||
|
} |
After Width: 128 | Height: 128 | Size: 9.3 KiB |
@ -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 <endikaig@antiun.com> |
||||
|
* # Antonio Espinosa <antonioea@antiun.com> |
||||
|
* # |
||||
|
* # 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 <http://www.gnu.org/licenses/>.
|
||||
|
* # |
||||
|
* ############################################################################## |
||||
|
*/ |
||||
|
|
||||
|
// 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); |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<templates id="template" xml:space="preserve"> |
||||
|
<t t-extend="PosTicket"> |
||||
|
<t t-jquery="[t-esc='widget.pos.company.name']" t-operation="before"> |
||||
|
<div class="pos-center-align"> |
||||
|
<img t-att-src="widget.pos.company_logo_base64"/><br /> |
||||
|
</div> |
||||
|
</t> |
||||
|
</t> |
||||
|
</templates> |
@ -0,0 +1,12 @@ |
|||||
|
<openerp> |
||||
|
<data> |
||||
|
<template id="pos_ticket_logo_assets_backend" |
||||
|
name="pos_ticket_logo_assets_backend" |
||||
|
inherit_id="point_of_sale.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script src="/pos_ticket_logo/static/src/js/main.js" |
||||
|
type="text/javascript"></script> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<template id="pos_ticket_logo_report_receipt_report" |
||||
|
inherit_id="point_of_sale.report_receipt"> |
||||
|
|
||||
|
<xpath expr="//div[@class='col-xs-12 text-center']/h2" position="after"> |
||||
|
<img src="/web/binary/company_logo" /><br /> |
||||
|
</xpath> |
||||
|
|
||||
|
<xpath expr="//div[@class='col-xs-12 text-center']/h2" position="attributes"> |
||||
|
<attribute name="style">display:none;</attribute> |
||||
|
</xpath> |
||||
|
|
||||
|
</template> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue