[FIX] website_sale_aplicoop: three defects in the group order slug

- create(): slugs were only checked against the database, so records created
  in the same batch (duplicating several orders from the list view, importing
  rows sharing a name) collided on group_order_slug_uniq. _generate_unique_slug
  now also skips the slugs already handed out in the batch.
- _redirect_to_slug_url(): `post` is passed as a dict instead of splatted, so a
  query parameter named `suffix` no longer binds to the keyword argument of the
  same name (HTTP 500 on /eskaera/<id>/checkout?suffix=x, and a corrupted path
  on the shop route).
- post-migrate: the backfill runs with tracking_disable, `slug` is tracked and
  the upgrade posted a chatter message on every pre-existing order.

Tests for the two reachable cases: batch create and query parameters kept
across the legacy redirect.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
GitHub Copilot 2026-08-11 22:53:09 +02:00
parent 23edee6154
commit 157b344d4b
4 changed files with 65 additions and 20 deletions

View file

@ -13,7 +13,7 @@ from odoo.tests.common import TransactionCase
class GroupOrderSlugCommon:
"""Helpers to build consumer group orders with the mandatory fields."""
def _create_group_order(self, name, **values):
def _group_order_vals(self, name, **values):
start_date = datetime.now().date()
vals = {
"name": name,
@ -26,7 +26,10 @@ class GroupOrderSlugCommon:
"cutoff_day": "0",
}
vals.update(values)
return self.env["group.order"].create(vals)
return vals
def _create_group_order(self, name, **values):
return self.env["group.order"].create(self._group_order_vals(name, **values))
class TestGroupOrderSlug(GroupOrderSlugCommon, TransactionCase):
@ -53,6 +56,25 @@ class TestGroupOrderSlug(GroupOrderSlugCommon, TransactionCase):
self.assertEqual(first.slug, "weekly-order")
self.assertEqual(second.slug, "weekly-order-2")
def test_slug_is_unique_within_a_single_create(self):
"""Records created in one batch cannot see each other in the database."""
orders = self.env["group.order"].create(
[self._group_order_vals("Weekly Order") for _ in range(3)]
)
self.assertEqual(
orders.mapped("slug"),
["weekly-order", "weekly-order-2", "weekly-order-3"],
)
def test_generated_slug_avoids_an_explicit_one_in_the_same_create(self):
orders = self.env["group.order"].create(
[
self._group_order_vals("Something Else", slug="weekly-order"),
self._group_order_vals("Weekly Order"),
]
)
self.assertEqual(orders.mapped("slug"), ["weekly-order", "weekly-order-2"])
def test_explicit_slug_is_normalized(self):
order = self._create_group_order("Weekly Order", slug="Fructuós Gelabert")
self.assertEqual(order.slug, "fructuos-gelabert")
@ -151,6 +173,19 @@ class TestGroupOrderSlugRoutes(GroupOrderSlugCommon, HttpCase):
f"got {response.headers.get('Location')}",
)
def test_numeric_url_keeps_query_parameters(self):
"""A `suffix` parameter must stay in the query string, not in the path."""
self.authenticate(self.portal_login, self.portal_login)
response = self.url_open(
f"/eskaera/{self.group_order.id}/checkout?suffix=x&search=apple",
allow_redirects=False,
)
self.assertIn(response.status_code, (301, 302, 303))
location = response.headers.get("Location", "")
self.assertIn(f"/eskaera/{self.group_order.slug}/checkout?", location)
self.assertIn("suffix=x", location)
self.assertIn("search=apple", location)
def test_unknown_slug_falls_back_to_the_list(self):
self.authenticate(self.portal_login, self.portal_login)
response = self.url_open("/eskaera/does-not-exist", allow_redirects=False)