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

[ADD] report_barcode_elaphe: Module to generate barcode with other lib #72

Closed
wants to merge 4 commits into from
Closed

[ADD] report_barcode_elaphe: Module to generate barcode with other lib #72

wants to merge 4 commits into from

Conversation

jefmoura
Copy link
Member

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.

@oca-clabot
Copy link

Hey @jefmoura, thank you for your Pull Request.

It looks like some users haven't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement here: http://odoo-community.org/page/website.cla
Here is a list of the users:

Appreciation of efforts,
OCA CLAbot

@jefmoura
Copy link
Member Author

jefmoura commented Sep 22, 2016

I have already signed and sent back the Contributor License Agreement.
As you can see the new module needs a external dependency.
I'm waiting for the next steps.

Copy link

@lasley lasley left a 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(
Copy link

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:
Copy link

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]
Copy link

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)
Copy link

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 -*-
##############################################################################
Copy link

Choose a reason for hiding this comment

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


try:
from elaphe import barcode
except Exception:
Copy link

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':
Copy link

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):
Copy link

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')])
Copy link

@lasley lasley Oct 19, 2016

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
=====================
Copy link

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

@lasley
Copy link

lasley commented Oct 19, 2016

@jefmoura - Travis dependency you can resolve. Just add a pip install elaphe in the Travis file install section, after the travis_install_nightly

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 stock-logistics-barcode repo. @pedrobaeza , @OCA/logistics-maintainers - thoughts?

@lasley lasley modified the milestone: 8.0 Oct 19, 2016
@pedrobaeza
Copy link
Member

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.

@lasley
Copy link

lasley commented Oct 20, 2016

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.

@pedrobaeza
Copy link
Member

@lasley, I think you haven't read correctly my comment: this is the correct repository.

@lasley
Copy link

lasley commented Oct 20, 2016

Oh whoops - I should stop reading my Github messages until after the morning coffee 😆

@jefmoura
Copy link
Member Author

jefmoura commented Dec 14, 2016

@lasley I took long to reply but I'm almost done with the changes. I have one question: How to test it? I have created unit test as you can see here 07218a5
Is it enough? Thanks!

Copy link

@lasley lasley left a 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
Copy link

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

@github-actions
Copy link

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.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Oct 24, 2021
@github-actions github-actions bot closed this Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs fixing stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants