From 06003b7d01a9583249e556bfae2fe36026c9acae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Mon, 11 Apr 2022 12:47:31 +0000 Subject: [PATCH] [FIX] website_event_exhibitor: correctly apply event sponsors ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the event sponsor ordering on the website is non-deterministic as it uses a non-ordered dictionary to accumulate items, which then dictates the order of display. We fix that issue by using a OrderedDict that will correctly retain the order. In addition, we force the sorting of sponsors based on their event.sponsor.type's sequence first and then based on their own sequence. The '_order' of event.sponsor is currently 'sequence, sponsor_type_id' which seems wrong but has to stay that way in order to avoid backend issues. Indeed, the backend and the "handle widget" do not have the capability to sort on multiple levels as we would need here (sponsor type sequence, then sponsor sequence). To completely fix this issue, we would need to: - Store the sponsor.type's sequence field on the sponsor (related stored) - Modify the _order to be sponsor_type_sequence, sequence - Only allow people to sort event.sponsors within a single category at a time Those changes would not be doable on a stable branch, hence why we use a local sorting when displaying sponsors on the website. Task-2818538 closes odoo/odoo#88633 X-original-commit: c32583a2160a289748616d4b0e49cba2bd5778fb Signed-off-by: Warnon Aurélien (awa) Signed-off-by: Thibault Delavallee (tde) --- addons/website_event_exhibitor/controllers/exhibitor.py | 7 +++++-- .../views/event_templates_sponsor.xml | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/website_event_exhibitor/controllers/exhibitor.py b/addons/website_event_exhibitor/controllers/exhibitor.py index d609139fb2b..657c3b41abd 100644 --- a/addons/website_event_exhibitor/controllers/exhibitor.py +++ b/addons/website_event_exhibitor/controllers/exhibitor.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from ast import literal_eval +from collections import OrderedDict from random import randint, sample from werkzeug.exceptions import NotFound, Forbidden @@ -72,12 +73,14 @@ class ExhibitorController(WebsiteEventController): # fetch data to display; use sudo to allow reading partner info, be sure domain is correct event = event.with_context(tz=event.date_tz or 'UTC') - sponsors = request.env['event.sponsor'].sudo().search(search_domain) + sponsors = request.env['event.sponsor'].sudo().search( + search_domain + ).sorted(lambda sponsor: (sponsor.sponsor_type_id.sequence, sponsor.sequence)) sponsors_all = request.env['event.sponsor'].sudo().search(search_domain_base) sponsor_types = sponsors_all.mapped('sponsor_type_id') sponsor_countries = sponsors_all.mapped('partner_id.country_id').sorted('name') # organize sponsors into categories to help display - sponsor_categories_dict = dict() + sponsor_categories_dict = OrderedDict() sponsor_categories = [] is_event_user = request.env.user.has_group('event.group_event_registration_desk') for sponsor in sponsors: diff --git a/addons/website_event_exhibitor/views/event_templates_sponsor.xml b/addons/website_event_exhibitor/views/event_templates_sponsor.xml index eae65320af8..f57ec5acace 100644 --- a/addons/website_event_exhibitor/views/event_templates_sponsor.xml +++ b/addons/website_event_exhibitor/views/event_templates_sponsor.xml @@ -6,7 +6,9 @@
- +