Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate report_webkit_barcode to 8.0 #29

Merged
merged 5 commits into from May 4, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
95 changes: 95 additions & 0 deletions report_webkit_barcode/README.rst
@@ -0,0 +1,95 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=====================
Webkit Report Barcode
=====================

This module 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
---------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line should have the same length as the title

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.

#. Go to ...

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}

.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example

Known issues / Roadmap
======================

* ...

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{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
<https://github.com/OCA/
{project_repo}/issues/new?body=module:%20
{module_name}%0Aversion:%20
{branch}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Vincent Vinet <vincent.vinet@savoirfairelinux.com>
* Cristian Salamea <ovnicraft@gmail.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.
7 changes: 7 additions & 0 deletions report_webkit_barcode/__init__.py
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © 2014 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import helper_barcode

helper_barcode.patch_helper()
17 changes: 17 additions & 0 deletions report_webkit_barcode/__openerp__.py
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# © 2014 Savoir-faire Linux
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Webkit Report Barcode',
'version': '0.1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8.0.1.0.0

'author': "Savoir-faire Linux,Odoo Community Association (OCA)",
'maintainer': 'Savoir-faire Linux',
'website': 'http://www.savoirfairelinux.com',
'license': 'AGPL-3',
'category': 'Reports/Webkit',
'depends': [
'report_webkit',
],
'installable': True,
}
78 changes: 78 additions & 0 deletions report_webkit_barcode/helper_barcode.py
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its like template

# -*- coding: utf-8 -*-
# © <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I don't see this template here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, its done

##############################################################################
#
# 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
Binary file added report_webkit_barcode/static/src/img/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.