Browse Source

Changes after the code review in https://github.com/OCA/reporting-engine/pull/72 and improvements

pull/72/head
Jeferson Moura 8 years ago
parent
commit
09d402121b
  1. 61
      report_barcode_elaphe/README.md
  2. 23
      report_barcode_elaphe/__init__.py
  3. 29
      report_barcode_elaphe/__openerp__.py
  4. 22
      report_barcode_elaphe/controllers/__init__.py
  5. 93
      report_barcode_elaphe/controllers/main.py
  6. 5
      report_barcode_elaphe/models/__init__.py
  7. 43
      report_barcode_elaphe/models/report.py
  8. 63
      report_barcode_elaphe/readme.rst

61
report_barcode_elaphe/README.md

@ -1,61 +0,0 @@
![Licence](https://img.shields.io/badge/licence-AGPL--3-blue.svg)
=====================
Report Barcode Elaphe
=====================
__Report barcode elaphe to provide more options of barcodes and settings__
This module has been built to override the method _report_barcode_ of the class _ReportController_ and provide more types and settings of barcode.
The behavior is the same as before, as you can see in the snippet below, but we have added a new query parameter(**extraopts**):
```html
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
```
or
```html
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' %
('QR', o.name, 200, 200)"/>
```
To pass some one of those settings, you need to use the new query parameter **extraopts** and instead you write **option = value**, you need to write **option : value**. Look at this example:
`
extraopts=backgroundcolor:FFFF00,barcolor:00FFFF
`
E.g, HTML img tag:
```html
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;extraopts=%s' %
('CODE128', o.name, 200, 200, 'backgroundcolor:FFFF00,barcolor:00FFFF')"/>
```
The snippet above changes the color of the bars and the background of the barcode.
The new options of setting can be found in the [Barcode Writer in Pure PostScript documentation](https://github.com/bwipp/postscriptbarcode/wiki).
Bug Tracker
===========
Bugs are tracked on [GitHub Issues](<https://github.com/OCA/reporting-engine/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 [here](<https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_barcode_elaphe%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>).
Credits
=======
* Examples taken from https://www.odoo.com/documentation/9.0/reference/reports.html.
Contributors
------------
* Jeferson Moura \<jmoura@bloopark.de\>
Maintainer
----------
![Odoo Community Association](https://odoo-community.org/logo.png)
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.

23
report_barcode_elaphe/__init__.py

@ -1,21 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# 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/>.
#
##############################################################################
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import controllers
from . import models

29
report_barcode_elaphe/__openerp__.py

@ -1,32 +1,15 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# 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/>.
#
##############################################################################
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': "Report Barcode Elaphe",
'summary': """Barcode generation controller using elaphe library.""",
'description': """Overwrite the report barcode controller to use a more powerful python library of barcode generation.""",
'summary': "Barcode generation controller using elaphe library.",
'author': "bloopark systems GmbH & Co. KG",
'website': "http://www.bloopark.de",
'license': 'AGPL-3',
'category': 'Base',
'version': '1.0',
'version': '8.0.1.0.0',
'depends': [
'report',
@ -36,4 +19,4 @@
'python': ['elaphe']
},
}
}

22
report_barcode_elaphe/controllers/__init__.py

@ -1,21 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# 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/>.
#
##############################################################################
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import main

93
report_barcode_elaphe/controllers/main.py

@ -1,36 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# 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/>.
#
##############################################################################
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.report.controllers.main import ReportController
from openerp.addons.web.http import route, request
import cStringIO
import re
from werkzeug import exceptions
try:
from elaphe import barcode
except Exception:
pass
class ReportBarcodeController(ReportController):
@ -41,56 +16,32 @@ class ReportBarcodeController(ReportController):
humanreadable=0, **kw):
"""Contoller able to render barcode images thanks to elaphe.
Samples:
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' %
('QR', o.name, 200, 200)"/>
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;scale=%s&amp;extraopts=%s' %
('code128', o.name, 4.0, 'backgroundcolor:FFFF00,barcolor:00FFFF')"/>
:param type: Accepted types: 'auspost', 'azteccode', 'codabar',
'code11', 'code128', 'code25', 'code39', 'code93', 'datamatrix', 'ean',
'i2of5', 'japanpost', 'kix', 'maxicode', 'msi', 'onecode', 'pdf417',
'pharmacode', 'plessey', 'postnet', 'qrcode', 'royalmail', 'rss14',
'symbol', 'upc'
:param barmargin: Accepted positive integer values
:param width: Accepted positive integer values
:param height: Accepted positive integer values
:param scale: Accepted positive float values
:param extraopts: Accepted different params per type of barcode. Eg: extraopts='{eclevel:M,version:8}'
:param humanreadable: Used in the default method
:param kw: Accepted values: 'elaphe' is 0 or 1, 'scale' and barmargin
are float, and 'extraopts' is barcode settings(check elaphe doc)
"""
try:
width, height, scale, margin = int(width), int(height), float(
kw.get('scale', 2.0)), int(kw.get('barmargin', 0))
opts = {}
if not int(kw.get('elaphe', 0)):
return super(ReportBarcodeController, self).report_barcode(
type, value, width, height, humanreadable
)
else:
try:
extra_opts = {}
if kw.get('extraopts', False):
for opt in kw['extraopts'].split(','):
key = opt.split(':')[0]
if opt.split(':')[1] == 'True':
values = True
elif opt.split(':')[1] == 'False':
values = False
elif opt.split(':')[1].isdigit():
values = int(opt.split(':')[1])
elif re.match("^\d+?\.\d+?$", opt.split(':')[1]):
values = float(opt.split(':')[1])
else:
values = opt.split(':')[1]
extra_opts[key] = values
opts.update(extra_opts)
except IndexError:
pass
barcode_out = cStringIO.StringIO()
barcode_img = barcode(type, str(value), opts, scale=scale,
margin=margin)
if width and height:
barcode_img = barcode_img.resize((width, height))
barcode_img.save(barcode_out, "png", resolution=100.0)
except (ValueError, AttributeError):
raise exceptions.HTTPException(
description='Cannot convert into barcode.')
return request.make_response(barcode_out.getvalue(),
headers=[('Content-Type', 'image/png')])
barcode = request.env['report'].generate_barcode(
type, value, kw, width, height
)
except (ValueError, AttributeError):
raise exceptions.HTTPException(
description='Cannot convert into barcode.')
return request.make_response(barcode, headers=[
('Content-Type', 'image/png')])

5
report_barcode_elaphe/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import report

43
report_barcode_elaphe/models/report.py

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright 2015 bloopark systems (<http://bloopark.de>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models
from openerp.tools.safe_eval import safe_eval as eval
import cStringIO
import re
try:
from elaphe import barcode
except ImportError:
pass
class Report(models.Model):
_inherit = 'report'
def generate_barcode(self, type, value, kw, width=0, height=0):
width = int(width)
height = int(height)
scale = float(kw.get('scale', 2.0))
margin = float(kw.get('barmargin', 0))
extra_opts = {}
barcode_out = cStringIO.StringIO()
if kw.get('extraopts', False):
for opt in kw['extraopts'].split(','):
key = opt.split(':')[0]
values = opt.split(':')[1]
if re.search(r'^(?:[0-9a-fA-F]{3}){1,2}$', values) is None:
values = eval(values)
extra_opts[key] = values
try:
barcode_img = barcode(type, str(value), extra_opts, scale=scale,
margin=margin)
if width and height:
barcode_img = barcode_img.resize((width, height))
barcode_img.save(barcode_out, "png", resolution=100.0)
except (ValueError, AttributeError):
raise ValueError('Cannot convert into barcode.')
return barcode_out.getvalue()

63
report_barcode_elaphe/readme.rst

@ -1,53 +1,69 @@
.. 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
=====================
Report Barcode Elaphe
=====================
.. Report barcode elaphe to provide more options of barcodes and settings
This module extends the functionality of the method _report_barcode_ of the class _ReportController_ to support more types and settings of barcode.
and to allow you to ...
Installation
============
To install this module, you need to:
* Go to `GitHub OCA/reporting-engine <https://github.com/OCA/reporting-engine>`_ and download the module.
* Move the module to your addons folder
* Go to Odoo and install the module, you can see it on the Addon's list
This module has been built to override the method _report_barcode_ of the class _ReportController_ and provide more types and settings of barcode.
The behavior is the same as before, as you can see in the snippet below, but we have added a new query parameter(**extraopts**). html::
Usage
=====
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
The behavior is the same as before, you can see it with the snippet below.
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
or html::
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', o.name, 200, 200)"/>
But we have added four new query parameters and they are:
**elaphe**, **scale**, **barmargin** and **extraopts**. You need to pass the parameter **elaphe** to indicate you want to use the new function with elaphe lib,
otherwise the old method will be used. You can see how to use them in the snippets below:
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;elaphe=%s&amp;scale=%s&amp;barmargin=%s' %
('CODE128', o.name, 1, 4.0, 1)"/>
To pass some one of those settings, you need to use the new query parameter **extraopts** and instead you write **option = value**, you need to write **option : value**. Look at this example:
``extraopts=backgroundcolor:FFFF00,barcolor:00FFFF``
To pass some barcode settings, you need to use the query parameter **extraopts** and instead you write **option = value**, you need to write **option : value**. Look at this example:
extraopts=backgroundcolor:FFFF00,barcolor:00FFFF
E.g, img tag in HTML::
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;extraopts=%s' % ('CODE128', o.name, 200, 200, 'backgroundcolor:FFFF00,barcolor:00FFFF')"/>
E.g, HTML img tag:
<img t-att-src="'/report/barcode?type=%s&amp;value=%s&amp;elaphe=%s&amp;scale=%s&amp;extraopts=%s' %
('code128', o.name, 1, 4.0, 'backgroundcolor:FFFF00,barcolor:00FFFF')"/>
The snippet above changes the color of the bars and the background of the barcode.
The new options of setting can be found in the [Barcode Writer in Pure PostScript documentation](https://github.com/bwipp/postscriptbarcode/wiki).
The new options of setting can be found in the `Barcode Writer in Pure PostScript documentation <https://github.com/bwipp/postscriptbarcode/wiki>`_.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/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
`here <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_barcode_elaphe%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/reporting-engine/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.
Credits
=======
* Examples taken from https://www.odoo.com/documentation/9.0/reference/reports.html.
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* bloopark system
* Jeferson Moura <jmoura@bloopark.de>
Maintainer
@ -59,7 +75,8 @@ Maintainer
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.
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.
Loading…
Cancel
Save