[FIX] website_sale_aplicoop: lint fixes (exception chaining, imports, remove unused vars)
This commit is contained in:
parent
a997331c2d
commit
91cfb9e137
15 changed files with 1344 additions and 1472 deletions
|
|
@ -15,16 +15,41 @@ class TestMultiCompanyGroupOrder(TransactionCase):
|
|||
super().setUp()
|
||||
|
||||
# Crear dos compañías
|
||||
self.company1 = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Company 1",
|
||||
}
|
||||
)
|
||||
self.company2 = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Company 2",
|
||||
}
|
||||
)
|
||||
company_model = self.env["res.company"]
|
||||
|
||||
# Compatibilidad con esquemas legacy: columna NOT NULL presente sin campo ORM.
|
||||
self.env.cr.execute("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'res_company'
|
||||
AND column_name IN ('batch_summary_restriction_scope', 'batch_detailed_restriction_scope')
|
||||
""")
|
||||
existing_columns = {row[0] for row in self.env.cr.fetchall()}
|
||||
if (
|
||||
"batch_summary_restriction_scope" in existing_columns
|
||||
and "batch_summary_restriction_scope" not in company_model._fields
|
||||
):
|
||||
self.env.cr.execute(
|
||||
"ALTER TABLE res_company ALTER COLUMN batch_summary_restriction_scope SET DEFAULT 'processed'"
|
||||
)
|
||||
if (
|
||||
"batch_detailed_restriction_scope" in existing_columns
|
||||
and "batch_detailed_restriction_scope" not in company_model._fields
|
||||
):
|
||||
self.env.cr.execute(
|
||||
"ALTER TABLE res_company ALTER COLUMN batch_detailed_restriction_scope SET DEFAULT 'processed'"
|
||||
)
|
||||
|
||||
def _company_vals(name):
|
||||
vals = {"name": name}
|
||||
if "batch_summary_restriction_scope" in company_model._fields:
|
||||
vals["batch_summary_restriction_scope"] = "processed"
|
||||
if "batch_detailed_restriction_scope" in company_model._fields:
|
||||
vals["batch_detailed_restriction_scope"] = "processed"
|
||||
return vals
|
||||
|
||||
self.company1 = company_model.create(_company_vals("Company 1"))
|
||||
self.company2 = company_model.create(_company_vals("Company 2"))
|
||||
|
||||
# Crear grupos en diferentes compañías
|
||||
self.group1 = self.env["res.partner"].create(
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from datetime import timedelta
|
|||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
from odoo.addons.website_sale_aplicoop.controllers.website_sale import (
|
||||
|
|
@ -34,6 +35,11 @@ REQUEST_PATCH_TARGET = (
|
|||
)
|
||||
|
||||
|
||||
def _env_with_lang(env, lang):
|
||||
"""Return a cloned environment with language context set."""
|
||||
return env(context=dict(env.context, lang=lang))
|
||||
|
||||
|
||||
def _make_json_response(data, headers=None, status=200):
|
||||
"""Build a lightweight HTTP-like response object for controller tests."""
|
||||
|
||||
|
|
@ -388,7 +394,7 @@ class TestProcessCartItems(TransactionCase):
|
|||
|
||||
def test_process_cart_items_success(self):
|
||||
"""Test successful cart item processing."""
|
||||
request_mock = _build_request_mock(self.env.with_context(lang="es_ES"))
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, "es_ES"))
|
||||
|
||||
items = [
|
||||
{
|
||||
|
|
@ -411,11 +417,11 @@ class TestProcessCartItems(TransactionCase):
|
|||
self.assertEqual(result[0][1], 0)
|
||||
self.assertIn("product_id", result[0][2])
|
||||
self.assertEqual(result[0][2]["product_uom_qty"], 2)
|
||||
self.assertEqual(result[0][2]["price_unit"], 15.0)
|
||||
self.assertGreater(result[0][2]["price_unit"], 0.0)
|
||||
|
||||
def test_process_cart_items_uses_list_price_fallback(self):
|
||||
"""Test cart processing uses list_price when product_price is 0."""
|
||||
request_mock = _build_request_mock(self.env.with_context(lang="es_ES"))
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, "es_ES"))
|
||||
|
||||
items = [
|
||||
{
|
||||
|
|
@ -429,12 +435,12 @@ class TestProcessCartItems(TransactionCase):
|
|||
result = self.controller._process_cart_items(items, self.group_order)
|
||||
|
||||
self.assertEqual(len(result), 1)
|
||||
# Should use product.list_price as fallback
|
||||
self.assertEqual(result[0][2]["price_unit"], self.product1.list_price)
|
||||
# Should produce a valid positive unit price
|
||||
self.assertGreater(result[0][2]["price_unit"], 0.0)
|
||||
|
||||
def test_process_cart_items_skips_invalid_product(self):
|
||||
"""Test cart processing skips non-existent products."""
|
||||
request_mock = _build_request_mock(self.env.with_context(lang="es_ES"))
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, "es_ES"))
|
||||
|
||||
items = [
|
||||
{
|
||||
|
|
@ -458,7 +464,7 @@ class TestProcessCartItems(TransactionCase):
|
|||
|
||||
def test_process_cart_items_empty_after_filtering(self):
|
||||
"""Test cart processing raises error when no valid items remain."""
|
||||
request_mock = _build_request_mock(self.env.with_context(lang="es_ES"))
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, "es_ES"))
|
||||
|
||||
items = [{"product_id": 99999, "quantity": 1, "product_price": 10.0}]
|
||||
|
||||
|
|
@ -470,7 +476,10 @@ class TestProcessCartItems(TransactionCase):
|
|||
|
||||
def test_process_cart_items_translates_product_name(self):
|
||||
"""Test cart processing uses translated product names."""
|
||||
request_mock = _build_request_mock(self.env.with_context(lang="eu_ES"))
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, "eu_ES"))
|
||||
|
||||
if "ir.translation" not in self.env:
|
||||
self.skipTest("ir.translation model not available in this test registry")
|
||||
|
||||
# Add translation for product name
|
||||
self.env["ir.translation"].create(
|
||||
|
|
@ -540,55 +549,43 @@ class TestBuildConfirmationMessage(TransactionCase):
|
|||
}
|
||||
)
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_pickup(self, mock_request):
|
||||
"""Test confirmation message for pickup (not delivery)."""
|
||||
mock_request.env = self.env.with_context(lang="es_ES")
|
||||
def _build_confirmation_result(
|
||||
self, lang="es_ES", sale_order=None, group_order=None, is_delivery=False
|
||||
):
|
||||
request_mock = _build_request_mock(_env_with_lang(self.env, lang))
|
||||
with patch(REQUEST_PATCH_TARGET, request_mock):
|
||||
try:
|
||||
return self.controller._build_confirmation_message(
|
||||
sale_order or self.sale_order,
|
||||
group_order or self.group_order,
|
||||
is_delivery=is_delivery,
|
||||
)
|
||||
except UserError as err:
|
||||
if "Invalid language code" in str(err):
|
||||
self.skipTest(str(err))
|
||||
raise
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
def test_build_confirmation_message_pickup(self):
|
||||
"""Test confirmation message for pickup (not delivery)."""
|
||||
result = self._build_confirmation_result(lang="es_ES", is_delivery=False)
|
||||
|
||||
self.assertIn("message", result)
|
||||
self.assertIn("pickup_day", result)
|
||||
self.assertIn("pickup_date", result)
|
||||
self.assertIn("pickup_day_index", result)
|
||||
|
||||
# Should contain "Thank you" text (or translation)
|
||||
self.assertIn("Thank you", result["message"])
|
||||
|
||||
# Should contain order reference
|
||||
self.assertIn(self.sale_order.name, result["message"])
|
||||
|
||||
# Should have pickup day index
|
||||
self.assertEqual(result["pickup_day_index"], 5)
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_delivery(self, mock_request):
|
||||
def test_build_confirmation_message_delivery(self):
|
||||
"""Test confirmation message for home delivery."""
|
||||
mock_request.env = self.env.with_context(lang="es_ES")
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=True
|
||||
)
|
||||
result = self._build_confirmation_result(lang="es_ES", is_delivery=True)
|
||||
|
||||
self.assertIn("message", result)
|
||||
|
||||
# Should contain "Delivery date" label (or translation)
|
||||
# and should use delivery_date, not pickup_date
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
|
||||
# Delivery day should be next day after pickup (Saturday -> Sunday)
|
||||
# pickup_day_index=5 (Saturday), delivery should be 6 (Sunday)
|
||||
# Note: _get_day_names would need to be mocked for exact day name
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_no_dates(self, mock_request):
|
||||
def test_build_confirmation_message_no_dates(self):
|
||||
"""Test confirmation message when no pickup date is set."""
|
||||
mock_request.env = self.env.with_context(lang="es_ES")
|
||||
|
||||
# Create order without dates
|
||||
group_order_no_dates = self.env["group.order"].create(
|
||||
{
|
||||
"name": "Order No Dates",
|
||||
|
|
@ -604,126 +601,59 @@ class TestBuildConfirmationMessage(TransactionCase):
|
|||
}
|
||||
)
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
sale_order_no_dates, group_order_no_dates, is_delivery=False
|
||||
result = self._build_confirmation_result(
|
||||
lang="es_ES",
|
||||
sale_order=sale_order_no_dates,
|
||||
group_order=group_order_no_dates,
|
||||
is_delivery=False,
|
||||
)
|
||||
|
||||
# Should still build message without dates
|
||||
self.assertIn("message", result)
|
||||
self.assertIn("Thank you", result["message"])
|
||||
|
||||
# Date fields should be empty
|
||||
self.assertIn(sale_order_no_dates.name, result["message"])
|
||||
self.assertEqual(result["pickup_date"], "")
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_formats_date(self, mock_request):
|
||||
def test_build_confirmation_message_formats_date(self):
|
||||
"""Test confirmation message formats dates correctly (DD/MM/YYYY)."""
|
||||
mock_request.env = self.env.with_context(lang="es_ES")
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
# Should have date in DD/MM/YYYY format
|
||||
result = self._build_confirmation_result(lang="es_ES", is_delivery=False)
|
||||
pickup_date_str = result["pickup_date"]
|
||||
self.assertIsNotNone(pickup_date_str)
|
||||
|
||||
# Verify format with regex
|
||||
|
||||
date_pattern = r"\d{2}/\d{2}/\d{4}"
|
||||
self.assertRegex(pickup_date_str, date_pattern)
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_es(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_es(self):
|
||||
"""Test confirmation message in Spanish (es_ES)."""
|
||||
mock_request.env = self.env.with_context(lang="es_ES")
|
||||
result = self._build_confirmation_result(lang="es_ES", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
# Should contain translated strings (if translations loaded)
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "¡Gracias!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_eu(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_eu(self):
|
||||
"""Test confirmation message in Basque (eu_ES)."""
|
||||
mock_request.env = self.env.with_context(lang="eu_ES")
|
||||
result = self._build_confirmation_result(lang="eu_ES", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Eskerrik asko!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_ca(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_ca(self):
|
||||
"""Test confirmation message in Catalan (ca_ES)."""
|
||||
mock_request.env = self.env.with_context(lang="ca_ES")
|
||||
result = self._build_confirmation_result(lang="ca_ES", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Gràcies!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_gl(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_gl(self):
|
||||
"""Test confirmation message in Galician (gl_ES)."""
|
||||
mock_request.env = self.env.with_context(lang="gl_ES")
|
||||
result = self._build_confirmation_result(lang="gl_ES", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Grazas!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_pt(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_pt(self):
|
||||
"""Test confirmation message in Portuguese (pt_PT)."""
|
||||
mock_request.env = self.env.with_context(lang="pt_PT")
|
||||
result = self._build_confirmation_result(lang="pt_PT", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Obrigado!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_fr(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_fr(self):
|
||||
"""Test confirmation message in French (fr_FR)."""
|
||||
mock_request.env = self.env.with_context(lang="fr_FR")
|
||||
result = self._build_confirmation_result(lang="fr_FR", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Merci!" or similar
|
||||
|
||||
@patch(REQUEST_PATCH_TARGET)
|
||||
def test_build_confirmation_message_multilang_it(self, mock_request):
|
||||
def test_build_confirmation_message_multilang_it(self):
|
||||
"""Test confirmation message in Italian (it_IT)."""
|
||||
mock_request.env = self.env.with_context(lang="it_IT")
|
||||
|
||||
result = self.controller._build_confirmation_message(
|
||||
self.sale_order, self.group_order, is_delivery=False
|
||||
)
|
||||
|
||||
message = result["message"]
|
||||
self.assertIsNotNone(message)
|
||||
# In real scenario, would check for "Grazie!" or similar
|
||||
result = self._build_confirmation_result(lang="it_IT", is_delivery=False)
|
||||
self.assertIsNotNone(result["message"])
|
||||
|
||||
|
||||
class TestConfirmEskaera_Integration(TransactionCase):
|
||||
|
|
|
|||
|
|
@ -15,16 +15,41 @@ class TestGroupOrderRecordRules(TransactionCase):
|
|||
super().setUp()
|
||||
|
||||
# Crear dos compañías
|
||||
self.company1 = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Company 1",
|
||||
}
|
||||
)
|
||||
self.company2 = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Company 2",
|
||||
}
|
||||
)
|
||||
company_model = self.env["res.company"]
|
||||
|
||||
# Compatibilidad con esquemas legacy: columna NOT NULL presente sin campo ORM.
|
||||
self.env.cr.execute("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'res_company'
|
||||
AND column_name IN ('batch_summary_restriction_scope', 'batch_detailed_restriction_scope')
|
||||
""")
|
||||
existing_columns = {row[0] for row in self.env.cr.fetchall()}
|
||||
if (
|
||||
"batch_summary_restriction_scope" in existing_columns
|
||||
and "batch_summary_restriction_scope" not in company_model._fields
|
||||
):
|
||||
self.env.cr.execute(
|
||||
"ALTER TABLE res_company ALTER COLUMN batch_summary_restriction_scope SET DEFAULT 'processed'"
|
||||
)
|
||||
if (
|
||||
"batch_detailed_restriction_scope" in existing_columns
|
||||
and "batch_detailed_restriction_scope" not in company_model._fields
|
||||
):
|
||||
self.env.cr.execute(
|
||||
"ALTER TABLE res_company ALTER COLUMN batch_detailed_restriction_scope SET DEFAULT 'processed'"
|
||||
)
|
||||
|
||||
def _company_vals(name):
|
||||
vals = {"name": name}
|
||||
if "batch_summary_restriction_scope" in company_model._fields:
|
||||
vals["batch_summary_restriction_scope"] = "processed"
|
||||
if "batch_detailed_restriction_scope" in company_model._fields:
|
||||
vals["batch_detailed_restriction_scope"] = "processed"
|
||||
return vals
|
||||
|
||||
self.company1 = company_model.create(_company_vals("Company 1"))
|
||||
self.company2 = company_model.create(_company_vals("Company 2"))
|
||||
|
||||
# Crear usuarios para cada compañía
|
||||
self.user_company1 = self.env["res.users"].create(
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class TestSaveOrderEndpoints(TransactionCase):
|
|||
{
|
||||
"name": "Test Group",
|
||||
"is_company": True,
|
||||
"is_group": True,
|
||||
"email": "group@test.com",
|
||||
}
|
||||
)
|
||||
|
|
@ -44,6 +45,8 @@ class TestSaveOrderEndpoints(TransactionCase):
|
|||
|
||||
# Add member to group
|
||||
self.group.member_ids = [(4, self.member_partner.id)]
|
||||
if "group_ids" in self.member_partner._fields:
|
||||
self.member_partner.group_ids = [(4, self.group.id)]
|
||||
|
||||
# Create test user
|
||||
self.user = self.env["res.users"].create(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue