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

W8301 fires all the time #493

Closed
pe-chile opened this issue Aug 2, 2024 · 3 comments
Closed

W8301 fires all the time #493

pe-chile opened this issue Aug 2, 2024 · 3 comments
Labels

Comments

@pe-chile
Copy link

pe-chile commented Aug 2, 2024

I have this code:

def _validation_cost(self):
    product = self.env['product.product'].search([('id', '=', self.product_id.id)])
    if product and product.qty_available == 0:
        message = _("The cost must be greater than zero for [%(code)s] %(name)s.") % {
            'code': product.default_code,
            'name': product.name
        }
        raise ValidationError(message)

vscode always reports the warning W8301

Describe the bug

I don't know another way of writing the code that doesn't trigger the warning. I also don't want to disable the warning.

@pe-chile pe-chile added the bug label Aug 2, 2024
@pedrobaeza
Copy link
Member

Which is the error W8301?

Apart from that, I see this code weird:

product = self.env['product.product'].search([('id', '=', self.product_id.id)])

Do

product = self.env['product.product'].browse(self.product_id.id)

but even better just do product = self.product_id, as you have already the recordset there (unless you need a rebrowse by any reason).

@pe-chile
Copy link
Author

pe-chile commented Aug 2, 2024

The warning I get is: Use lazy % formatting in odoo._ functionsPylintW8301:translation-not-lazy

Really odd. Still get the warning after testing both of your suggestions:

image

I work through docker containers. I wonder if I am missing a pip package?? I base my image from the odoo/docker

Upgrade pip wheel and install pip packages

RUN pip3 install --upgrade pip
&& pip3 install --upgrade wheel
&& pip3 install cryptography==3.3.2
paramiko==2.10.1
pysftp==0.2.8
ipython
pydevd-odoo
pylint_odoo
html5lib==1.1
pandas==1.3.5
numpy==1.21.5
odoo-test-helper==2.1.1
importlib-metadata

If I go to other modules from the app store, the warning gets fired too. I see that others are formatting similarly to how it's been written.

The vscode settings is set like this:

"pylint.importStrategy": "useBundled",
"pylint.interpreter": [
  "/usr/bin/python3"
],
"pylint.args": [
  "--load-plugins",
  "pylint_odoo"
],

@pedrobaeza
Copy link
Member

Just include the dictionary in the _ call:

        message = _(
            "The cost must be greater than zero for [%(code)s] %(name)s.",
            {
                'code': product.default_code,
                'name': product.name
            }
        )

and it's better to use product.display_name to get the same, and also the attribute values if it's a variant with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants