addons-cm/website_sale_aplicoop/tests/test_templates_rendering.py
snt 89c008441e [FIX] Resolver 3 fallos de tests en website_sale_aplicoop
- Fix: delivery product price now includes VAT (homepage/checkout)
  * Added _get_delivery_product_display_price() helper to use same pricing pipeline as regular products
  * Uses pricelist + tax calculations instead of bare list_price
  * Fallback chain: pricelist → bare list_price → default 5.74
  * Updated context in eskaera_shop() and eskaera_checkout()

- Test: test_constraint_cutoff_before_pickup_invalid
  * Constraint removed: now allows any combination of cutoff_day and pickup_day
  * Updated test to reflect this change (no ValidationError expected)

- Test: test_day_names_not_using_inline_underscore
  * Fixed to check sub-template eskaera_order_card_meta where day_names is actually used
  * eskaera_page calls this sub-template so day_names context is inherited

Results: 128 tests - 0 failed, 0 errors (100% pass rate)
2026-03-30 16:21:57 +02:00

159 lines
6.2 KiB
Python

# Copyright 2025 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from datetime import date
from datetime import timedelta
from odoo.tests.common import TransactionCase
from odoo.tests.common import tagged
@tagged("post_install", "-at_install")
class TestTemplatesRendering(TransactionCase):
"""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."""
super().setUp()
# Create a test supplier
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
}
)
# Create a test group
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
}
)
def test_eskaera_page_template_exists(self):
"""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")
def test_eskaera_shop_template_exists(self):
"""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")
def test_eskaera_checkout_template_exists(self):
"""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")
def test_day_names_context_is_provided(self):
"""Test that day_names context is provided by the controller method."""
# Simulate what the controller does, passing env for test context
from ..controllers.website_sale import AplicoopWebsiteSale
controller = AplicoopWebsiteSale()
day_names = controller._get_day_names(env=self.env)
# Verify we have exactly 7 days
self.assertEqual(len(day_names), 7)
# Verify all are strings and not None
for i, day_name in enumerate(day_names):
self.assertIsNotNone(day_name, f"Day at index {i} is None")
self.assertIsInstance(day_name, str, f"Day at index {i} is not a string")
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.
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 _()
Note: day_names can be used in called sub-templates (t-call), not just the main template.
We verify the sub-template that actually uses day_names (eskaera_order_card_meta).
"""
# Verify that the sub-template that uses day_names is properly structured
template = self.env.ref("website_sale_aplicoop.eskaera_order_card_meta")
self.assertIn(
"day_names",
template.arch_db,
"Sub-template eskaera_order_card_meta 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")
self.assertIsNotNone(template)
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",
)
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")
# 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("This order's cart is empty", html)