[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,77 +1,90 @@
# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from datetime import date, timedelta
from odoo.tests.common import TransactionCase, tagged
from datetime import date
from datetime import timedelta
from odoo import _
from odoo.tests.common import TransactionCase
from odoo.tests.common import tagged
@tagged('post_install', '-at_install')
@tagged("post_install", "-at_install")
class TestTemplatesRendering(TransactionCase):
'''Test suite to verify QWeb templates work with day_names context.
"""Test suite to verify QWeb templates work with day_names context.
This test covers the fix for the issue where _() function calls
in QWeb t-value attributes caused TypeError: 'NoneType' object is not callable.
The fix moves day_names definition to Python controller and passes it as context.
'''
"""
def setUp(self):
'''Set up test data: create a test group order.'''
"""Set up test data: create a test group order."""
super().setUp()
# Create a test supplier
self.supplier = self.env['res.partner'].create({
'name': 'Test Supplier',
'is_company': True,
})
self.supplier = self.env["res.partner"].create(
{
"name": "Test Supplier",
"is_company": True,
}
)
# Create test products
self.product = self.env['product.product'].create({
'name': 'Test Product',
'type': 'consu', # consumable (consu), service, or storable
})
self.product = self.env["product.product"].create(
{
"name": "Test Product",
"type": "consu", # consumable (consu), service, or storable
}
)
# Create a test group
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 group order
self.group_order = self.env['group.order'].create({
'name': 'Test Order',
'state': 'open',
'supplier_ids': [(6, 0, [self.supplier.id])],
'product_ids': [(6, 0, [self.product.id])],
'group_ids': [(6, 0, [self.group.id])],
'start_date': date.today(),
'end_date': date.today() + timedelta(days=7),
'pickup_day': '5', # Saturday
'cutoff_day': '3', # Thursday
})
self.group_order = self.env["group.order"].create(
{
"name": "Test Order",
"state": "open",
"supplier_ids": [(6, 0, [self.supplier.id])],
"product_ids": [(6, 0, [self.product.id])],
"group_ids": [(6, 0, [self.group.id])],
"start_date": date.today(),
"end_date": date.today() + timedelta(days=7),
"pickup_day": "5", # Saturday
"cutoff_day": "3", # Thursday
}
)
def test_eskaera_page_template_exists(self):
'''Test that eskaera_page template compiles without errors.'''
template = self.env.ref('website_sale_aplicoop.eskaera_page')
"""Test that eskaera_page template compiles without errors."""
template = self.env.ref("website_sale_aplicoop.eskaera_page")
self.assertIsNotNone(template)
self.assertEqual(template.type, 'qweb')
self.assertEqual(template.type, "qweb")
def test_eskaera_shop_template_exists(self):
'''Test that eskaera_shop template compiles without errors.'''
template = self.env.ref('website_sale_aplicoop.eskaera_shop')
"""Test that eskaera_shop template compiles without errors."""
template = self.env.ref("website_sale_aplicoop.eskaera_shop")
self.assertIsNotNone(template)
self.assertEqual(template.type, 'qweb')
self.assertEqual(template.type, "qweb")
def test_eskaera_checkout_template_exists(self):
'''Test that eskaera_checkout template compiles without errors.'''
template = self.env.ref('website_sale_aplicoop.eskaera_checkout')
"""Test that eskaera_checkout template compiles without errors."""
template = self.env.ref("website_sale_aplicoop.eskaera_checkout")
self.assertIsNotNone(template)
self.assertEqual(template.type, 'qweb')
self.assertEqual(template.type, "qweb")
def test_day_names_context_is_provided(self):
'''Test that day_names context is provided by the controller method.'''
"""Test that day_names context is provided by the controller method."""
# Simulate what the controller does, passing env for test context
from odoo.addons.website_sale_aplicoop.controllers.website_sale import AplicoopWebsiteSale
from odoo.addons.website_sale_aplicoop.controllers.website_sale import (
AplicoopWebsiteSale,
)
controller = AplicoopWebsiteSale()
day_names = controller._get_day_names(env=self.env)
@ -86,45 +99,61 @@ class TestTemplatesRendering(TransactionCase):
self.assertGreater(len(day_name), 0, f"Day at index {i} is empty string")
def test_day_names_not_using_inline_underscore(self):
'''Test that day_names are defined in Python, not in t-value attributes.
"""Test that day_names are defined in Python, not in t-value attributes.
This test ensures the fix has been applied:
- day_names MUST be passed from controller context
- day_names MUST NOT be defined with _() inside t-value attributes
- Templates use day_names[index] from context, not t-set with _()
'''
template = self.env.ref('website_sale_aplicoop.eskaera_page')
"""
template = self.env.ref("website_sale_aplicoop.eskaera_page")
# Read the template source to verify it doesn't have inline _() in t-value
self.assertIn('day_names', template.arch_db,
"Template must reference day_names from context")
self.assertIn(
"day_names",
template.arch_db,
"Template must reference day_names from context",
)
# The fix ensures no <t t-set="day_names" t-value="[_(...)]"/> exists
# which was causing the NoneType error
def test_eskaera_checkout_summary_template_exists(self):
'''Test that eskaera_checkout_summary sub-template exists.'''
template = self.env.ref('website_sale_aplicoop.eskaera_checkout_summary')
"""Test that eskaera_checkout_summary sub-template exists."""
template = self.env.ref("website_sale_aplicoop.eskaera_checkout_summary")
self.assertIsNotNone(template)
self.assertEqual(template.type, 'qweb')
self.assertEqual(template.type, "qweb")
# Verify it has the expected structure
self.assertIn('checkout-summary-table', template.arch_db,
"Template must have checkout-summary-table id")
self.assertIn('Product', template.arch_db,
"Template must have Product label for translation")
self.assertIn('Quantity', template.arch_db,
"Template must have Quantity label for translation")
self.assertIn('Price', template.arch_db,
"Template must have Price label for translation")
self.assertIn('Subtotal', template.arch_db,
"Template must have Subtotal label for translation")
self.assertIn(
"checkout-summary-table",
template.arch_db,
"Template must have checkout-summary-table id",
)
self.assertIn(
"Product",
template.arch_db,
"Template must have Product label for translation",
)
self.assertIn(
"Quantity",
template.arch_db,
"Template must have Quantity label for translation",
)
self.assertIn(
"Price", template.arch_db, "Template must have Price label for translation"
)
self.assertIn(
"Subtotal",
template.arch_db,
"Template must have Subtotal label for translation",
)
def test_eskaera_checkout_summary_renders(self):
'''Test that eskaera_checkout_summary renders without errors.'''
template = self.env.ref('website_sale_aplicoop.eskaera_checkout_summary')
"""Test that eskaera_checkout_summary renders without errors."""
template = self.env.ref("website_sale_aplicoop.eskaera_checkout_summary")
# Render the template with empty context
html = template._render_template(template.xml_id, {})
# Should contain the basic table structure
self.assertIn('<table', html)
self.assertIn('checkout-summary-table', html)
self.assertIn('Product', html)
self.assertIn('Quantity', html)
self.assertIn("<table", html)
self.assertIn("checkout-summary-table", html)
self.assertIn("Product", html)
self.assertIn("Quantity", html)
self.assertIn("This order's cart is empty", html)