Browse Source
Changes after the code review in https://github.com/OCA/reporting-engine/pull/72 and improvements
pull/72/head
Changes after the code review in https://github.com/OCA/reporting-engine/pull/72 and improvements
pull/72/head
Jeferson Moura
8 years ago
8 changed files with 123 additions and 216 deletions
-
61report_barcode_elaphe/README.md
-
23report_barcode_elaphe/__init__.py
-
29report_barcode_elaphe/__openerp__.py
-
22report_barcode_elaphe/controllers/__init__.py
-
93report_barcode_elaphe/controllers/main.py
-
5report_barcode_elaphe/models/__init__.py
-
43report_barcode_elaphe/models/report.py
-
63report_barcode_elaphe/readme.rst
@ -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&value=%s&width=%s&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&value=%s&width=%s&height=%s&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. |
@ -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 |
@ -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 |
@ -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 |
@ -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() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue