- 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>
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
"""Backfill the URL slug of consumer group orders created before this version.
|
|
|
|
Public pages moved from /eskaera/<id> to /eskaera/<slug>. Orders that already
|
|
existed have no slug yet, so they would not be reachable until saved again.
|
|
Generate one from their name, keeping it unique.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from odoo import SUPERUSER_ID
|
|
from odoo import api
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def migrate(cr, version):
|
|
if not version:
|
|
return
|
|
|
|
# tracking_disable: `slug` is a tracked field, backfilling it would post a
|
|
# chatter message and notify the followers of every pre-existing order.
|
|
env = api.Environment(cr, SUPERUSER_ID, {"tracking_disable": True})
|
|
orders = env["group.order"].search([("slug", "=", False)], order="id")
|
|
for order in orders:
|
|
# One write at a time: the search inside `_generate_unique_slug` flushes
|
|
# the previous one, so two orders sharing a name get distinct slugs.
|
|
order.slug = order._generate_unique_slug(order.name)
|
|
|
|
if orders:
|
|
_logger.info(
|
|
"Generated URL slugs for %d consumer group orders: %s",
|
|
len(orders),
|
|
", ".join(orders.mapped("slug")),
|
|
)
|