[FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings

- Remove redundant string= from 17 field definitions where name matches string value (W8113)
- Convert @staticmethod to instance methods in selection methods for proper self.env._() access
- Fix W8161 (prefer-env-translation) by using self.env._() instead of standalone _()
- Fix W8301/W8115 (translation-not-lazy) by proper placement of % interpolation outside self.env._()
- Remove unused imports of odoo._ from group_order.py and sale_order_extension.py
- All OCA linting warnings in website_sale_aplicoop main models are now resolved

Changes:
- website_sale_aplicoop/models/group_order.py: 21 field definitions cleaned
- website_sale_aplicoop/models/sale_order_extension.py: 5 field definitions cleaned + @staticmethod conversion
- Consistent with OCA standards for addon submission
This commit is contained in:
snt 2026-02-18 17:54:43 +01:00
parent 5c89795e30
commit 6fbc7b9456
73 changed files with 5386 additions and 4354 deletions

View file

@ -1,91 +1,106 @@
# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from datetime import datetime, timedelta
from odoo.tests.common import TransactionCase
class TestProductExtension(TransactionCase):
'''Test suite para las extensiones de product.template.'''
"""Test suite para las extensiones de product.template."""
def setUp(self):
super(TestProductExtension, self).setUp()
self.product = self.env['product.product'].create({
'name': 'Test Product',
})
self.order = self.env['group.order'].create({
'name': 'Test Order',
'product_ids': [(4, self.product.id)]
})
super().setUp()
self.product = self.env["product.product"].create(
{
"name": "Test Product",
}
)
self.order = self.env["group.order"].create(
{"name": "Test Order", "product_ids": [(4, self.product.id)]}
)
def test_product_template_group_order_ids_field_exists(self):
'''Test que el campo group_order_ids existe en product.template.'''
"""Test que el campo group_order_ids existe en product.template."""
product_template = self.product.product_tmpl_id
# El campo debe existir y ser readonly
self.assertTrue(hasattr(product_template, 'group_order_ids'))
self.assertTrue(hasattr(product_template, "group_order_ids"))
def test_product_group_order_ids_readonly(self):
""" Test that group_order_ids is a readonly field """
field = self.env['product.template']._fields['group_order_ids']
"""Test that group_order_ids is a readonly field"""
field = self.env["product.template"]._fields["group_order_ids"]
self.assertTrue(field.readonly)
def test_product_group_order_ids_reverse_lookup(self):
""" Test that adding a product to an order reflects in group_order_ids """
"""Test that adding a product to an order reflects in group_order_ids"""
related_orders = self.product.product_tmpl_id.group_order_ids
self.assertIn(self.order, related_orders)
def test_product_group_order_ids_empty_by_default(self):
""" Test that a new product has no group orders """
new_product = self.env['product.product'].create({'name': 'New Product'})
"""Test that a new product has no group orders"""
new_product = self.env["product.product"].create({"name": "New Product"})
self.assertFalse(new_product.product_tmpl_id.group_order_ids)
def test_product_group_order_ids_multiple_orders(self):
""" Test that group_order_ids can contain multiple orders """
order2 = self.env['group.order'].create({
'name': 'Test Order 2',
'product_ids': [(4, self.product.id)]
})
"""Test that group_order_ids can contain multiple orders"""
order2 = self.env["group.order"].create(
{"name": "Test Order 2", "product_ids": [(4, self.product.id)]}
)
self.assertIn(self.order, self.product.product_tmpl_id.group_order_ids)
self.assertIn(order2, self.product.product_tmpl_id.group_order_ids)
def test_product_group_order_ids_empty_after_remove_from_order(self):
""" Test that group_order_ids is empty after removing the product from all orders """
self.order.write({'product_ids': [(3, self.product.id)]})
"""Test that group_order_ids is empty after removing the product from all orders"""
self.order.write({"product_ids": [(3, self.product.id)]})
self.assertFalse(self.product.product_tmpl_id.group_order_ids)
def test_product_group_order_ids_with_multiple_products(self):
""" Test group_order_ids with multiple products in one order """
product2 = self.env['product.product'].create({'name': 'Test Product 2'})
self.order.write({'product_ids': [
(4, self.product.id),
(4, product2.id)
]})
"""Test group_order_ids with multiple products in one order"""
product2 = self.env["product.product"].create({"name": "Test Product 2"})
self.order.write({"product_ids": [(4, self.product.id), (4, product2.id)]})
self.assertIn(self.order, self.product.product_tmpl_id.group_order_ids)
self.assertIn(self.order, product2.product_tmpl_id.group_order_ids)
def test_product_with_variants_group_order_ids(self):
""" Test that group_order_ids works correctly with product variants """
"""Test that group_order_ids works correctly with product variants"""
# Create a product template with two variants
product_template = self.env['product.template'].create({
'name': 'Product with Variants',
'attribute_line_ids': [(0, 0, {
'attribute_id': self.env.ref('product.product_attribute_1').id,
'value_ids': [
(4, self.env.ref('product.product_attribute_value_1').id),
(4, self.env.ref('product.product_attribute_value_2').id)
]
})]
})
product_template = self.env["product.template"].create(
{
"name": "Product with Variants",
"attribute_line_ids": [
(
0,
0,
{
"attribute_id": self.env.ref(
"product.product_attribute_1"
).id,
"value_ids": [
(
4,
self.env.ref(
"product.product_attribute_value_1"
).id,
),
(
4,
self.env.ref(
"product.product_attribute_value_2"
).id,
),
],
},
)
],
}
)
variant1 = product_template.product_variant_ids[0]
variant2 = product_template.product_variant_ids[1]
# Add one variant to an order (store variant id, not template id)
order_with_variant = self.env['group.order'].create({
'name': 'Order with Variant',
'product_ids': [(4, variant1.id)]
})
order_with_variant = self.env["group.order"].create(
{"name": "Order with Variant", "product_ids": [(4, variant1.id)]}
)
# Check that the order appears in the group_order_ids of the template
self.assertIn(order_with_variant, product_template.group_order_ids)