Skip to content

Commit

Permalink
TA#62879 [IMP] Correct flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Mar 4, 2024
1 parent 24d1c2c commit 82e0ab2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion product_barcode_upc/tests/test_product_barcode_upc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUpClass(cls):
"name": "Product Template",
"barcode": "123456789",
})
ptal = cls.env['product.template.attribute.line'].create({
cls.env['product.template.attribute.line'].create({
'attribute_id': product_attribute.id,
'product_tmpl_id': cls.product_template.id,
'value_ids': [(6, 0, [size_value_l.id])],
Expand Down
25 changes: 15 additions & 10 deletions product_dimension/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,33 @@ def write(self, vals):
"""
vals_copy = vals.copy()
super().write(vals)

updating_weight_in_uom = 'weight_in_uom' in vals_copy or 'specific_weight_uom_id' in vals_copy
updating_weight_in_uom_from_weight = self._context.get('updating_weight_in_uom_from_weight')

updating_weight_in_uom = (
"weight_in_uom" in vals_copy or "specific_weight_uom_id" in vals_copy
)
updating_weight_in_uom_from_weight = self._context.get(
"updating_weight_in_uom_from_weight"
)
updating_weight = 'weight' in vals_copy
updating_weight_from_weight_in_uom = self._context.get('updating_weight_from_weight_in_uom')

updating_weight_from_weight_in_uom = self._context.get(
"updating_weight_from_weight_in_uom"
)
if updating_weight_in_uom and not updating_weight_in_uom_from_weight:
for record in self:
record.update_weight_from_weight_in_uom()

elif updating_weight and not updating_weight_from_weight_in_uom:
for record in self:
record.update_weight_in_uom_from_weight()

return True

def update_weight_from_weight_in_uom(self):
"""Update the weight in kg from the weight in uom."""
uom_kg = self.env.ref('uom.product_uom_kgm')
weight = self.specific_weight_uom_id._compute_quantity(self.weight_in_uom, uom_kg)
self.with_context(updating_weight_from_weight_in_uom=True).write({'weight': weight})
weight = self.specific_weight_uom_id._compute_quantity(
self.weight_in_uom, uom_kg
)
self.with_context(updating_weight_from_weight_in_uom=True).write(
{"weight": weight}
)

def update_weight_in_uom_from_weight(self):
"""Update the weight in uom from the weight in kg."""
Expand Down
26 changes: 17 additions & 9 deletions product_dimension/tests/test_product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUpClass(cls):
cls.volume = 0.3 * 0.4 * 0.5
cls.density = cls.weight / cls.volume

def test_when_creating_product_template_then_dimensions_are_propagated_to_the_variant(self):
def test_create_product_template_with_dimensions_propagated_to_variant(self):
self.template = self.env['product.template'].create({
'name': 'Test Product',
'type': 'product',
Expand All @@ -43,7 +43,7 @@ def test_when_creating_product_template_then_dimensions_are_propagated_to_the_va
self.assertEqual(self.template.product_variant_ids.width, self.width)
self.assertEqual(self.template.product_variant_ids.dimension_uom_id, self.cm)

def test_when_creating_product_template_then_weight_in_uom_is_propagated_to_the_variant(self):
def test_create_product_template_with_weight_uom_propagated_to_variant(self):
self.template = self.env['product.template'].create({
'name': 'Test Product',
'type': 'product',
Expand All @@ -56,11 +56,15 @@ def test_when_creating_product_template_then_weight_in_uom_is_propagated_to_the_
self.assertEqual(self.template.specific_weight_uom_id, self.gram)
self.assertEqual(self.template.weight, self.weight)

self.assertEqual(self.template.product_variant_ids.weight_in_uom, self.weight_in_uom)
self.assertEqual(self.template.product_variant_ids.specific_weight_uom_id, self.gram)
self.assertEqual(
self.template.product_variant_ids.weight_in_uom, self.weight_in_uom
)
self.assertEqual(
self.template.product_variant_ids.specific_weight_uom_id, self.gram
)
self.assertEqual(self.template.product_variant_ids.weight, self.weight)

def test_when_creating_product_template_then_weight_is_propagated_to_the_variant(self):
def test_create_product_template_with_weight_propagated_to_variant(self):
self.template = self.env['product.template'].create({
'name': 'Test Product',
'type': 'product',
Expand All @@ -73,10 +77,12 @@ def test_when_creating_product_template_then_weight_is_propagated_to_the_variant
self.assertEqual(self.template.weight, 1)

self.assertEqual(self.template.product_variant_ids.weight_in_uom, 1)
self.assertEqual(self.template.product_variant_ids.specific_weight_uom_id, self.kg)
self.assertEqual(
self.template.product_variant_ids.specific_weight_uom_id, self.kg
)
self.assertEqual(self.template.product_variant_ids.weight, 1)

def test_when_creating_product_template_then_volume_is_computed_on_the_variant(self):
def test_create_product_template_with_volume_computed_on_variant(self):
self.template = self.env['product.template'].create({
'name': 'Test Product',
'type': 'product',
Expand All @@ -91,7 +97,7 @@ def test_when_creating_product_template_then_volume_is_computed_on_the_variant(s
self.assertAlmostEqual(self.template.volume, self.volume, 2)
self.assertAlmostEqual(self.template.product_variant_ids.volume, self.volume, 2)

def test_when_creating_product_template_then_density_is_computed_on_the_variant(self):
def test_create_product_template_then_density_computed_on_variant(self):
self.template = self.env['product.template'].create({
'name': 'Test Product',
'type': 'product',
Expand All @@ -106,4 +112,6 @@ def test_when_creating_product_template_then_density_is_computed_on_the_variant(
self.template.refresh()

self.assertAlmostEqual(self.template.density, self.density, 2)
self.assertAlmostEqual(self.template.product_variant_ids.density, self.density, 2)
self.assertAlmostEqual(
self.template.product_variant_ids.density, self.density, 2
)
9 changes: 5 additions & 4 deletions product_dimension/tests/test_weight_in_uom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_when_update_weight_then_weight_in_uom_is_updated(self):
self.assertEqual(self.product.weight_in_uom, 10)
self.assertEqual(self.product.specific_weight_uom_id, self.kg)

def test_when_update_weight_if_has_weight_uom_then_specific_weight_uom_id_is_not_changed(self):
def test_update_weight_if_weight_uom_then_not_changed(self):
"""Test that when the weight is set, the current uom on the product is kept."""
self.product.specific_weight_uom_id = self.gram

Expand All @@ -39,7 +39,7 @@ def test_when_update_weight_if_has_weight_uom_then_specific_weight_uom_id_is_not
self.assertEqual(self.product.specific_weight_uom_id, self.gram)

def test_when_update_weight_in_uom_then_weight_is_updated(self):
"""Test that when the weight in uom is set, then the weight in kg is also updated."""
"""Test that when the weight in uom is set, then the weight in kg is updated."""
self.product.write({
'weight_in_uom': 10 * 1000,
'specific_weight_uom_id': self.gram.id,
Expand All @@ -51,7 +51,7 @@ def test_when_update_weight_in_uom_then_weight_is_updated(self):
self.assertEqual(self.product.specific_weight_uom_id, self.gram)

def test_on_write_weight_in_uom_supersedes_weight(self):
"""Test that on write, if weight and weight_in_uom are given, weight_in_uom is kept."""
"""Test on write if weight and weight_in_uom are given weight_in_uom is kept."""
self.product.write({
'weight': 9,
'weight_in_uom': 10 * 1000,
Expand Down Expand Up @@ -91,7 +91,8 @@ def test_on_create_if_weight_in_uom_is_given_then_weight_is_set(self):
self.assertEqual(product.specific_weight_uom_id, self.gram)

def test_on_create_weight_in_uom_supersedes_weight(self):
"""Test that on create, if weight and weight_in_uom are given, weight_in_uom is kept."""
"""Test on create if weight and weight_in_uom are
given weight_in_uom is kept."""
product = self.env['product.product'].create({
'name': 'New Product',
'type': 'product',
Expand Down
3 changes: 2 additions & 1 deletion product_manufacturer_quick_search/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"license": "AGPL-3",
"category": "Product",
"depends": ["product_manufacturer"],
"summary": "Add a quick search for items using their manufacturer name or code, as well as the manufacturer name.",
"summary": """Add a quick search for items using their manufacturer name or code,
as well as the manufacturer name.""",
"data": [
"views/product_template.xml",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import base64
from odoo import api, models
from odoo import models
from odoo.addons.product_pricelist_direct_print_extended.wizards.\
product_pricelist_print import ProductPricelistPrint

Expand All @@ -26,7 +26,7 @@ class ProductPricelistPrintChatter(models.TransientModel):
def generate_report(self, template_id):
report = self.env.ref(
'product_pricelist_direct_print.action_report_product_pricelist')
result, _ = report._render_qweb_pdf([self.id])
result, _ = report._render_qweb_pdf([self.id])
result = base64.b64encode(result)
new_attachment_id = self.env['ir.attachment'].create({
'name': self.pricelist_id.name,
Expand Down
2 changes: 1 addition & 1 deletion product_purchase_order_link/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestProduct(common.SavepointCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
2 changes: 1 addition & 1 deletion stock_barcode_upc/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2022 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import api, models


class ProductProduct(models.Model):
Expand Down

0 comments on commit 82e0ab2

Please sign in to comment.