addons-cm/website_sale_aplicoop/views/load_from_history_templates.xml
GitHub Copilot 23edee6154 [IMP] website_sale_aplicoop: readable slug in the group order URL
Group order pages were published under their database id (`/eskaera/1`), which
says nothing to the member opening the link. `group.order` gains a `slug` field
and the public pages move to `/eskaera/<slug>` (e.g. `/eskaera/escola-fructuos`).

The slug is generated from the order name on creation, is unique, and can be
edited under the name on the form; emptying it regenerates it from the current
name. Values that would make the order unreachable are rejected: a plain number
(the legacy numeric URLs win that match) and the static routes served under
`/eskaera/` (`labels`, `save-order`, `i18n`, ...).

`/eskaera/<id>` and `/eskaera/<id>/checkout` are kept as redirects to their slug
URL, so the links already shared with members keep working. The AJAX endpoints
(`load-page`, `save-order`, `confirm`, ...) stay numeric: they never show up in
the address bar. Consequently the frontend now reads the order id from the
`data-order-id` attribute only, as the URL no longer carries it.

The post-migration script fills the slug of the orders that already existed.

Renaming the `/eskaera` prefix itself (`/escolas` for a schools deployment)
needs no code: a *308 Redirect / Rewrite* rule per public route in Website >
Configuration > Redirects serves the pages on the new prefix, rewrites the
links in the templates and redirects the old URLs, per website. Documented in
`readme/CONFIGURE.rst`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 16:49:54 +02:00

77 lines
4.8 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<!-- Template to load items from history and redirect to group order -->
<template id="eskaera_load_from_history" name="Load Order from History">
<html>
<head>
<meta charset="utf-8"/>
<title>Loading Order...</title>
</head>
<body>
<script type="text/javascript">
// Items are embedded directly in the script (pre-serialized JSON from controller)
var itemsJson = <t t-raw="items_json"/>; // This is a JSON array/string
var groupOrderId = <t t-esc="group_order_id"/>;
var groupOrderUrl = '<t t-esc="group_order_url"/>';
var saleOrderName = '<t t-esc="sale_order_name"/>';
var pickupDay = '<t t-esc="pickup_day or ''"/>';
var pickupDate = '<t t-esc="pickup_date or ''"/>';
var pickupSlotLabel = '<t t-esc="pickup_slot_label or ''"/>';
var homeDelivery = <t t-esc="home_delivery and 'true' or 'false'"/>;
var sameGroupOrder = <t t-esc="same_group_order and 'true' or 'false'"/>;
// Product availability warning
var hasUnavailableItems = <t t-esc="has_unavailable_items and 'true' or 'false'"/>;
var warningMessage = '<t t-esc="warning_message or ''"/>';
console.log('load_from_history template: groupOrderId=', groupOrderId);
console.log('load_from_history template: saleOrderName=', saleOrderName);
console.log('load_from_history template: pickupDay=', pickupDay);
console.log('load_from_history template: pickupDate=', pickupDate);
console.log('load_from_history template: homeDelivery=', homeDelivery);
console.log('load_from_history template: sameGroupOrder=', sameGroupOrder);
console.log('load_from_history template: hasUnavailableItems=', hasUnavailableItems);
console.log('load_from_history template: itemsJson type=', typeof itemsJson);
console.log('load_from_history template: itemsJson value=', itemsJson);
// If itemsJson is already a string, use it directly; if it's an array, stringify it
var itemsJsonString = (typeof itemsJson === 'string') ? itemsJson : JSON.stringify(itemsJson);
// Store items to sessionStorage
sessionStorage['load_from_history_' + groupOrderId] = itemsJsonString;
// Store sale order name separately
sessionStorage['load_from_history_order_name_' + groupOrderId] = saleOrderName;
// Store pickup fields ONLY if from same group order
if (sameGroupOrder === 'true') {
sessionStorage['load_from_history_pickup_day_' + groupOrderId] = pickupDay;
sessionStorage['load_from_history_pickup_date_' + groupOrderId] = pickupDate;
// Only store a human-readable label for pickup slot.
// Do NOT persist or expose internal slot IDs to sessionStorage.
sessionStorage['load_from_history_pickup_slot_label_' + groupOrderId] = pickupSlotLabel;
sessionStorage['load_from_history_home_delivery_' + groupOrderId] = homeDelivery;
console.log('Saved pickup fields (same group order)');
} else {
console.log('Skipped saving pickup fields (different group order - will use current group order days)');
}
// Store warning about unavailable products if they exist
if (hasUnavailableItems === 'true') {
sessionStorage['load_from_history_warning_' + groupOrderId] = warningMessage;
console.log('Unavailable products detected:', warningMessage);
}
console.log('Saved to sessionStorage[load_from_history_' + groupOrderId + ']:', itemsJsonString);
console.log('Saved order name to sessionStorage[load_from_history_order_name_' + groupOrderId + ']:', saleOrderName);
// Redirect to group order page
// The JavaScript on that page will detect this and load the items
window.location.href = groupOrderUrl;
</script>
</body>
</html>
</template>
</data>
</odoo>