[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

@ -17,7 +17,8 @@ Coverage:
- Ordering and deduplication
"""
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta
from odoo.tests.common import TransactionCase
@ -27,81 +28,105 @@ class TestProductDiscoveryUnion(TransactionCase):
def setUp(self):
super().setUp()
self.group = self.env['res.partner'].create({
'name': 'Test Group',
'is_company': True,
})
self.group = self.env["res.partner"].create(
{
"name": "Test Group",
"is_company": True,
}
)
# Create a supplier
self.supplier = self.env['res.partner'].create({
'name': 'Test Supplier',
'is_supplier': True,
})
self.supplier = self.env["res.partner"].create(
{
"name": "Test Supplier",
"is_supplier": True,
}
)
# Create categories
self.category1 = self.env['product.category'].create({
'name': 'Category 1',
})
self.category1 = self.env["product.category"].create(
{
"name": "Category 1",
}
)
self.category2 = self.env['product.category'].create({
'name': 'Category 2',
})
self.category2 = self.env["product.category"].create(
{
"name": "Category 2",
}
)
# Create products
# Direct product
self.direct_product = self.env['product.product'].create({
'name': 'Direct Product',
'type': 'consu',
'list_price': 10.0,
'is_published': True,
'sale_ok': True,
})
self.direct_product = self.env["product.product"].create(
{
"name": "Direct Product",
"type": "consu",
"list_price": 10.0,
"is_published": True,
"sale_ok": True,
}
)
# Category 1 product
self.cat1_product = self.env['product.product'].create({
'name': 'Category 1 Product',
'type': 'consu',
'list_price': 20.0,
'categ_id': self.category1.id,
'is_published': True,
'sale_ok': True,
})
self.cat1_product = self.env["product.product"].create(
{
"name": "Category 1 Product",
"type": "consu",
"list_price": 20.0,
"categ_id": self.category1.id,
"is_published": True,
"sale_ok": True,
}
)
# Category 2 product
self.cat2_product = self.env['product.product'].create({
'name': 'Category 2 Product',
'type': 'consu',
'list_price': 30.0,
'categ_id': self.category2.id,
'is_published': True,
'sale_ok': True,
})
self.cat2_product = self.env["product.product"].create(
{
"name": "Category 2 Product",
"type": "consu",
"list_price": 30.0,
"categ_id": self.category2.id,
"is_published": True,
"sale_ok": True,
}
)
# Supplier product
self.supplier_product = self.env['product.product'].create({
'name': 'Supplier Product',
'type': 'consu',
'list_price': 40.0,
'categ_id': self.category1.id, # Also in category
'seller_ids': [(0, 0, {
'partner_id': self.supplier.id,
'product_name': 'Supplier Product',
})],
'is_published': True,
'sale_ok': True,
})
self.supplier_product = self.env["product.product"].create(
{
"name": "Supplier Product",
"type": "consu",
"list_price": 40.0,
"categ_id": self.category1.id, # Also in category
"seller_ids": [
(
0,
0,
{
"partner_id": self.supplier.id,
"product_name": "Supplier Product",
},
)
],
"is_published": True,
"sale_ok": True,
}
)
start_date = datetime.now().date()
self.group_order = self.env['group.order'].create({
'name': 'Test Order',
'group_ids': [(6, 0, [self.group.id])],
'type': 'regular',
'start_date': start_date,
'end_date': start_date + timedelta(days=7),
'period': 'weekly',
'pickup_day': '3',
'cutoff_day': '0',
})
self.group_order = self.env["group.order"].create(
{
"name": "Test Order",
"group_ids": [(6, 0, [self.group.id])],
"type": "regular",
"start_date": start_date,
"end_date": start_date + timedelta(days=7),
"period": "weekly",
"pickup_day": "3",
"cutoff_day": "0",
}
)
def test_discovery_from_direct_products(self):
"""Test discovery returns directly linked products."""
@ -145,14 +170,16 @@ class TestProductDiscoveryUnion(TransactionCase):
def test_discovery_filters_unpublished(self):
"""Test that unpublished products are excluded from discovery."""
unpublished = self.env['product.product'].create({
'name': 'Unpublished Product',
'type': 'consu',
'list_price': 50.0,
'categ_id': self.category1.id,
'is_published': False,
'sale_ok': True,
})
unpublished = self.env["product.product"].create(
{
"name": "Unpublished Product",
"type": "consu",
"list_price": 50.0,
"categ_id": self.category1.id,
"is_published": False,
"sale_ok": True,
}
)
self.group_order.category_ids = [(4, self.category1.id)]
discovered = self.group_order.product_ids
@ -162,14 +189,16 @@ class TestProductDiscoveryUnion(TransactionCase):
def test_discovery_filters_not_for_sale(self):
"""Test that non-sellable products are excluded."""
not_for_sale = self.env['product.product'].create({
'name': 'Not For Sale',
'type': 'consu',
'list_price': 60.0,
'categ_id': self.category1.id,
'is_published': True,
'sale_ok': False,
})
not_for_sale = self.env["product.product"].create(
{
"name": "Not For Sale",
"type": "consu",
"list_price": 60.0,
"categ_id": self.category1.id,
"is_published": True,
"sale_ok": False,
}
)
self.group_order.category_ids = [(4, self.category1.id)]
discovered = self.group_order.product_ids
@ -183,76 +212,96 @@ class TestDeepCategoryHierarchies(TransactionCase):
def setUp(self):
super().setUp()
self.group = self.env['res.partner'].create({
'name': 'Test Group',
'is_company': True,
})
self.group = self.env["res.partner"].create(
{
"name": "Test Group",
"is_company": True,
}
)
# Create nested category structure:
# Root -> L1 -> L2 -> L3 -> L4
self.cat_l1 = self.env['product.category'].create({
'name': 'Level 1',
})
self.cat_l1 = self.env["product.category"].create(
{
"name": "Level 1",
}
)
self.cat_l2 = self.env['product.category'].create({
'name': 'Level 2',
'parent_id': self.cat_l1.id,
})
self.cat_l2 = self.env["product.category"].create(
{
"name": "Level 2",
"parent_id": self.cat_l1.id,
}
)
self.cat_l3 = self.env['product.category'].create({
'name': 'Level 3',
'parent_id': self.cat_l2.id,
})
self.cat_l3 = self.env["product.category"].create(
{
"name": "Level 3",
"parent_id": self.cat_l2.id,
}
)
self.cat_l4 = self.env['product.category'].create({
'name': 'Level 4',
'parent_id': self.cat_l3.id,
})
self.cat_l4 = self.env["product.category"].create(
{
"name": "Level 4",
"parent_id": self.cat_l3.id,
}
)
self.cat_l5 = self.env['product.category'].create({
'name': 'Level 5',
'parent_id': self.cat_l4.id,
})
self.cat_l5 = self.env["product.category"].create(
{
"name": "Level 5",
"parent_id": self.cat_l4.id,
}
)
# Create products at each level
self.product_l2 = self.env['product.product'].create({
'name': 'Product L2',
'type': 'consu',
'list_price': 10.0,
'categ_id': self.cat_l2.id,
'is_published': True,
'sale_ok': True,
})
self.product_l2 = self.env["product.product"].create(
{
"name": "Product L2",
"type": "consu",
"list_price": 10.0,
"categ_id": self.cat_l2.id,
"is_published": True,
"sale_ok": True,
}
)
self.product_l4 = self.env['product.product'].create({
'name': 'Product L4',
'type': 'consu',
'list_price': 20.0,
'categ_id': self.cat_l4.id,
'is_published': True,
'sale_ok': True,
})
self.product_l4 = self.env["product.product"].create(
{
"name": "Product L4",
"type": "consu",
"list_price": 20.0,
"categ_id": self.cat_l4.id,
"is_published": True,
"sale_ok": True,
}
)
self.product_l5 = self.env['product.product'].create({
'name': 'Product L5',
'type': 'consu',
'list_price': 30.0,
'categ_id': self.cat_l5.id,
'is_published': True,
'sale_ok': True,
})
self.product_l5 = self.env["product.product"].create(
{
"name": "Product L5",
"type": "consu",
"list_price": 30.0,
"categ_id": self.cat_l5.id,
"is_published": True,
"sale_ok": True,
}
)
start_date = datetime.now().date()
self.group_order = self.env['group.order'].create({
'name': 'Test Order',
'group_ids': [(6, 0, [self.group.id])],
'type': 'regular',
'start_date': start_date,
'end_date': start_date + timedelta(days=7),
'period': 'weekly',
'pickup_day': '3',
'cutoff_day': '0',
})
self.group_order = self.env["group.order"].create(
{
"name": "Test Order",
"group_ids": [(6, 0, [self.group.id])],
"type": "regular",
"start_date": start_date,
"end_date": start_date + timedelta(days=7),
"period": "weekly",
"pickup_day": "3",
"cutoff_day": "0",
}
)
def test_discovery_root_category_includes_all_descendants(self):
"""Test that linking root category discovers all nested products."""
@ -307,33 +356,41 @@ class TestEmptySourcesDiscovery(TransactionCase):
def setUp(self):
super().setUp()
self.group = self.env['res.partner'].create({
'name': 'Test Group',
'is_company': True,
})
self.group = self.env["res.partner"].create(
{
"name": "Test Group",
"is_company": True,
}
)
self.category = self.env['product.category'].create({
'name': 'Empty Category',
})
self.category = self.env["product.category"].create(
{
"name": "Empty Category",
}
)
# No products in this category
self.supplier = self.env['res.partner'].create({
'name': 'Supplier No Products',
'is_supplier': True,
})
self.supplier = self.env["res.partner"].create(
{
"name": "Supplier No Products",
"is_supplier": True,
}
)
# No products from this supplier
start_date = datetime.now().date()
self.group_order = self.env['group.order'].create({
'name': 'Test Order',
'group_ids': [(6, 0, [self.group.id])],
'type': 'regular',
'start_date': start_date,
'end_date': start_date + timedelta(days=7),
'period': 'weekly',
'pickup_day': '3',
'cutoff_day': '0',
})
self.group_order = self.env["group.order"].create(
{
"name": "Test Order",
"group_ids": [(6, 0, [self.group.id])],
"type": "regular",
"start_date": start_date,
"end_date": start_date + timedelta(days=7),
"period": "weekly",
"pickup_day": "3",
"cutoff_day": "0",
}
)
def test_discovery_empty_category(self):
"""Test discovery from empty category."""
@ -371,39 +428,47 @@ class TestProductDiscoveryOrdering(TransactionCase):
def setUp(self):
super().setUp()
self.group = self.env['res.partner'].create({
'name': 'Test Group',
'is_company': True,
})
self.group = self.env["res.partner"].create(
{
"name": "Test Group",
"is_company": True,
}
)
self.category = self.env['product.category'].create({
'name': 'Test Category',
})
self.category = self.env["product.category"].create(
{
"name": "Test Category",
}
)
# Create products with specific names
self.products = []
for i in range(5):
product = self.env['product.product'].create({
'name': f'Product {chr(65 + i)}', # A, B, C, D, E
'type': 'consu',
'list_price': (i + 1) * 10.0,
'categ_id': self.category.id,
'is_published': True,
'sale_ok': True,
})
product = self.env["product.product"].create(
{
"name": f"Product {chr(65 + i)}", # A, B, C, D, E
"type": "consu",
"list_price": (i + 1) * 10.0,
"categ_id": self.category.id,
"is_published": True,
"sale_ok": True,
}
)
self.products.append(product)
start_date = datetime.now().date()
self.group_order = self.env['group.order'].create({
'name': 'Test Order',
'group_ids': [(6, 0, [self.group.id])],
'type': 'regular',
'start_date': start_date,
'end_date': start_date + timedelta(days=7),
'period': 'weekly',
'pickup_day': '3',
'cutoff_day': '0',
})
self.group_order = self.env["group.order"].create(
{
"name": "Test Order",
"group_ids": [(6, 0, [self.group.id])],
"type": "regular",
"start_date": start_date,
"end_date": start_date + timedelta(days=7),
"period": "weekly",
"pickup_day": "3",
"cutoff_day": "0",
}
)
def test_discovery_consistent_ordering(self):
"""Test that repeated calls return same order."""
@ -413,10 +478,7 @@ class TestProductDiscoveryOrdering(TransactionCase):
discovered2 = list(self.group_order.product_ids)
# Order should be consistent
self.assertEqual(
[p.id for p in discovered1],
[p.id for p in discovered2]
)
self.assertEqual([p.id for p in discovered1], [p.id for p in discovered2])
def test_discovery_alphabetical_or_price_order(self):
"""Test that products are ordered predictably."""
@ -427,6 +489,6 @@ class TestProductDiscoveryOrdering(TransactionCase):
# Should be in some consistent order (name, price, ID, etc)
# Verify they're the same products, regardless of order
self.assertEqual(len(discovered), 5)
discovered_ids = set(p.id for p in discovered)
expected_ids = set(p.id for p in self.products)
discovered_ids = {p.id for p in discovered}
expected_ids = {p.id for p in self.products}
self.assertEqual(discovered_ids, expected_ids)