-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
[ADD] report_barcode_elaphe: Module to generate barcode with other lib #72
Conversation
Hey @jefmoura, thank you for your Pull Request. It looks like some users haven't signed our Contributor License Agreement, yet.
Appreciation of efforts, |
I have already signed and sent back the Contributor License Agreement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jefmoura - thanks for the submission! I put some comments inline & will create an issue to resolve the Runbot dependency
:param extraopts: Accepted different params per type of barcode. Eg: extraopts='{eclevel:M,version:8}' | ||
""" | ||
try: | ||
width, height, scale, margin = int(width), int(height), float( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should all be declared on independent lines.
:param scale: Accepted positive float values | ||
:param extraopts: Accepted different params per type of barcode. Eg: extraopts='{eclevel:M,version:8}' | ||
""" | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard is too long & not very Pythonic IMO. Please try to isolate what you are guarding for, and leave everything else outside of it. Suggestions are to move the variable declarations and nested try/except out of this try/except
extra_opts = {} | ||
if kw.get('extraopts', False): | ||
for opt in kw['extraopts'].split(','): | ||
key = opt.split(':')[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opt.split
is being called a lot of times on the same object. I recommend you assign it to a variable and use that instead
@@ -0,0 +1,61 @@ | |||
![Licence](https://img.shields.io/badge/licence-AGPL--3-blue.svg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file, only the RST is necessary
@@ -0,0 +1,21 @@ | |||
# -*- coding: utf-8 -*- | |||
############################################################################## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the shorter header & apply to all - https://github.com/OCA/maintainer-tools/blob/master/template/module/__init__.py#L3
|
||
try: | ||
from elaphe import barcode | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always try to be as specific in your guards as possible. except ImportError:
key = opt.split(':')[0] | ||
if opt.split(':')[1] == 'True': | ||
values = True | ||
elif opt.split(':')[1] == 'False': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you should use openerp.tools.safe_eval
instead of this set of conditionals. Will be more flexible & more efficient
|
||
@route() | ||
def report_barcode(self, type, value, width=0, height=0, | ||
humanreadable=0, **kw): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely re-implementing a method is not desirable in a lot of instances, particularly when unknown modules could depend on, or add to via inheritance, implementation on the parent. You can't guarantee module load order, so inconsistent results are common if not calling the superclass.
I would prefer if there were an argument to explicitly use this implementation & send to super if not defined. This will guard against unpredictable behavior while still allowing for the fanciness that this module provides 😄
description='Cannot convert into barcode.') | ||
|
||
return request.make_response(barcode_out.getvalue(), | ||
headers=[('Content-Type', 'image/png')]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline to end of file - https://robots.thoughtbot.com/no-newline-at-end-of-file
|
||
===================== | ||
Report Barcode Elaphe | ||
===================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use OCA ReadMe template (Usage section, newer bug tracker note, etc) - https://raw.githubusercontent.com/OCA/maintainer-tools/master/template/module/README.rst
@jefmoura - Travis dependency you can resolve. Just add a We will also need some tests in order to make sure everything works. Please let me know if you have questions on how to test. What to test should become apparent once Travis passes and Codecov drops a comment in this PR. Also note I did the review here, but I think this module may be better in the |
About Travis, better to add a regular requirements.txt file like Python packages. About the repo, this is not something for dealing with barcodes in the backend, but for "printing" them, so I think this is the right place. |
Thanks for the confirmation @pedrobaeza @jefmoura - Let's perform the QA process here, then we can migrate to the correct repo for merge. Thanks again for the contribution! Drop a message here when you're ready for another review or need help. |
@lasley, I think you haven't read correctly my comment: this is the correct repository. |
Oh whoops - I should stop reading my Github messages until after the morning coffee 😆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @jefmoura
Looking at the code, there's still a few missing spots in coverage. Biggest one is in the controller. I typically just mock out the parent of the controller I'm testing then go from there. You can then just call the methods you need, providing the proper returns from parent when you need it.
There's also some failing lints - https://travis-ci.org/OCA/reporting-engine/jobs/183906326#L461
Realistically I'm also good with pushing the controller tests back to the next migration in order to speed up merge. You're already raising the coverage of the repo quite a bit here. Lints are a blocker though definitely.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this left as the name safe_eval
. Overriding namespaces you don't own isn't good IMO & when I saw it later in the code I had to jump back up to the imports to see if it was being done right. Best to leave it explicit
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
The current barcode generating method in Odoo uses the Reportlab and if I want to generate e.g a Pharmacode I cannot; because, the lib doesn't provide this type nor configurations for it. To provide more options and settings for barcodes, we create this module that uses the elaphe library and overrides the controller that makes barcode. It uses other library to generate barcodes but it will keep the current behavior and add options/settings at the same time.