Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to 8.0, change in description filtering jinja2
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2014 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.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/>. | ||
# | ||
############################################################################## | ||
|
||
from . import helper_barcode | ||
|
||
helper_barcode.patch_helper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2014 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.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': 'Webkit Report Barcode', | ||
'version': '0.1', | ||
'author': "Savoir-faire Linux,Odoo Community Association (OCA)", | ||
'maintainer': 'Savoir-faire Linux', | ||
'website': 'http://www.savoirfairelinux.com', | ||
'license': 'AGPL-3', | ||
'category': 'Reports/Webkit', | ||
'summary': 'Adds a barcode helper to webkit reports', | ||
'description': """ | ||
Add barcodes in webkit reports | ||
============================== | ||
Usage | ||
----- | ||
To embed a barcode image in a webkit report, use ``${helper.barcode(value)}``. | ||
Depending on template filtering, you might need to force not to use any filter | ||
by doing ``${helper.barcode(value) | safe}`` | ||
The function is defined as: | ||
barcode(value, code='Code128', drawOpts=None, htmlAttrs=None) | ||
Parameters | ||
--------- | ||
value | ||
Value for barcode as expected by barcode type. Code128 takes a number or | ||
numeric string | ||
code | ||
barcode type. ReportLab 2.5 has the following codes: Codabar, Code11, | ||
Code128, EAN13, EAN8, Extended39, Extended93, FIM, I2of5, MSI, POSTNET, QR, | ||
Standard39, Standard93, USPS_4State | ||
drawOpts | ||
dictionary of options for reportlab graphic. Depends on barcode type. Use | ||
*format* to specify image format (default png), *width* to specify image | ||
width in pixels (int), *height* to specify image height in pixels (int) | ||
htmlAttrs | ||
dictionary of html attributes | ||
Requirements | ||
------------ | ||
This module depends on reportlab and lxml, which are both part of the odoo | ||
installation. | ||
Contributors | ||
------------ | ||
* Vincent Vinet (vincent.vinet@savoirfairelinux.com) | ||
""", | ||
'depends': [ | ||
'report_webkit', | ||
], | ||
'external_dependencies': { | ||
'python': [], | ||
}, | ||
'data': [ | ||
], | ||
'demo': [], | ||
'test': [], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2014 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.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/>. | ||
# | ||
############################################################################## | ||
|
||
import logging | ||
|
||
from openerp.addons.report_webkit.report_helper import WebKitHelper | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def patch_helper(): | ||
try: | ||
# Reportlab also has createBarcodeDrawingInMemory. Unfortunately, it | ||
# is broken in 2.5, so we'll have to do the same thing it does in 3.0 | ||
from reportlab.graphics.barcode import createBarcodeDrawing | ||
from lxml.etree import tostring as HTML, Element | ||
except ImportError, e: | ||
_logger.warn("Failed to import required dependency: %s", e[0]) | ||
return | ||
|
||
def barcode(self, value, code='Code128', drawOpts=None, htmlAttrs=None): | ||
""" Generate a <img /> tag with embedded barcode | ||
Params: | ||
- value: barcode value, must be valid for barcode type | ||
- code: barcode type, as per reportlab.graphics.barcode.getCodes() | ||
- drawOpts: options for the reportlab barcode | ||
- htmlAttrs: attributes for <img /> tag | ||
""" | ||
drawOpts = (drawOpts or {}) | ||
imgtype = drawOpts.pop('format', 'png') | ||
attrs = (htmlAttrs or {}) | ||
drawOpts['value'] = value | ||
for k in ('width', 'height'): | ||
# Attempt to unify drawing and image sizes to prevent accidental | ||
# scaling, and reduce parameter duplication | ||
if k in drawOpts and k not in attrs: | ||
attrs[k] = "{0}px".format(drawOpts[k]) | ||
elif k in attrs and k not in drawOpts: | ||
# reportlab expects a float | ||
value = str(attrs[k]) | ||
if value.endswith("px"): | ||
value = value[:-2].strip() | ||
try: | ||
value = float(value) | ||
except ValueError: | ||
# Ignore values that we can't handle | ||
pass | ||
else: | ||
drawOpts[k] = value | ||
|
||
data = createBarcodeDrawing(code, **drawOpts).asString(imgtype) | ||
attrs['src'] = "data:image/{1};base64,{0}".format( | ||
data.encode('base64'), imgtype, | ||
) | ||
return HTML(Element('img', attrs)) | ||
|
||
WebKitHelper.barcode = barcode |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.