OCA / pylint-odoo

Odoo plugin for Pylint
http://www.pylint.org
143 stars 168 forks source link

W8301 fires all the time #493

Closed pe-chile closed 2 months ago

pe-chile commented 2 months ago

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.

pedrobaeza commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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.