Browse files

Merge pull request #29 from ovnicraft/8.0

Migrate report_webkit_barcode to 8.0
  • Loading branch information...
gurneyalex committed May 4, 2016
2 parents 969e263 + 2af4a2e commit 4f83804ce5b1cd689f8086aea11a88d10044fe3a
@@ -0,0 +1,95 @@
.. image::
:alt: License: AGPL-3
Webkit Report Barcode
This module Add barcodes in webkit reports
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)
Value for barcode as expected by barcode type. Code128 takes a number or
numeric string
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
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)
dictionary of html attributes
This module depends on reportlab and lxml, which are both part of the odoo
#. Go to ...
.. image::
:alt: Try me on Runbot
.. repo_id is available in
.. branch is "8.0" for example
Known issues / Roadmap
* ...
Bug Tracker
Bugs are tracked on `GitHub Issues
<{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
* Odoo Community Association: `Icon <>`_.
* Vincent Vinet <>
* Cristian Salamea <>
.. image::
:alt: Odoo Community Association
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
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © 2014 Savoir-faire Linux
# License AGPL-3.0 or later (
from . import helper_barcode
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# © 2014 Savoir-faire Linux
# License AGPL-3.0 or later (
'name': 'Webkit Report Barcode',
'version': '',
'author': "Savoir-faire Linux,Odoo Community Association (OCA)",
'maintainer': 'Savoir-faire Linux',
'website': '',
'license': 'AGPL-3',
'category': 'Reports/Webkit',
'depends': [
'installable': True,
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# © 2014 Savoir-faire Linux
# License AGPL-3.0 or later (
import logging
from openerp.addons.report_webkit.report_helper import WebKitHelper
_logger = logging.getLogger(__name__)
def patch_helper():
# 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 import createBarcodeDrawing
from lxml.etree import tostring as HTML, Element
except ImportError, e:
_logger.warn("Failed to import required dependency: %s", e[0])
def barcode(self, value, code='Code128', drawOpts=None, htmlAttrs=None):
""" Generate a <img /> tag with embedded barcode
- value: barcode value, must be valid for barcode type
- code: barcode type, as per
- 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()
value = float(value)
except ValueError:
# Ignore values that we can't handle
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
Binary file not shown.

0 comments on commit 4f83804

Please sign in to comment.