From 4e8d835b80804488d3f1edbbfe5fd56b0f494502 Mon Sep 17 00:00:00 2001 From: "Levi Siuzdak (sile)" Date: Thu, 30 Nov 2023 16:13:57 +0100 Subject: [PATCH] [FIX] website_event: copy template question translations Versions: --------- - 15.0+ Steps to reproduce: ------------------- 1. Have multiple languages and Studio enabled; 2. create an event template; 3. add a question; 4. add translation to question; 5. use template to create event. Issue: ------ Translation doesn't get copied from template to event. Cause: ------ The `_compute_question_ids` method copied the questions by *manually* recreating them. It didn't use the `copy_translations` method like the regular `copy` methods does. The reason the questions were recreated is because question records cannot link directly from event template to event, as changes to the event shouldn't affect the template. Solution: --------- Use the `copy` method instead while setting `event_type_id` to `False` to satisfy the restriction. opw-3572599 closes odoo/odoo#144451 X-original-commit: 73d603b65fca33773557012c4ba38da1bc98271d Signed-off-by: Thibault Delavallee (tde) Signed-off-by: Levi Siuzdak --- addons/website_event/models/event_event.py | 20 +++++-------------- .../tests/test_event_internals.py | 18 +++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/addons/website_event/models/event_event.py b/addons/website_event/models/event_event.py index 3fad0c76b56..77b66edee2a 100644 --- a/addons/website_event/models/event_event.py +++ b/addons/website_event/models/event_event.py @@ -208,7 +208,7 @@ class Event(models.Model): When synchronizing questions: - * lines that no answer are removed; + * lines with no registered answers are removed; * type lines are added; """ if self._origin.question_ids: @@ -229,22 +229,12 @@ class Event(models.Model): command = [(3, question.id) for question in questions_toremove] else: command = [(5, 0)] - if event.event_type_id.question_ids: - command += [ - (0, 0, { - 'answer_ids': [(0, 0, { - 'name': answer.name, - 'sequence': answer.sequence - }) for answer in question.answer_ids], - 'is_mandatory_answer': question.is_mandatory_answer, - 'once_per_order': question.once_per_order, - 'question_type': question.question_type, - 'sequence': question.sequence, - 'title': question.title, - }) for question in event.event_type_id.question_ids - ] event.question_ids = command + # copy questions so changes in the event don't affect the event type + for question in event.event_type_id.question_ids: + event.question_ids += question.copy({'event_type_id': False}) + # ------------------------------------------------------------------------- # CONSTRAINT METHODS # ------------------------------------------------------------------------- diff --git a/addons/website_event/tests/test_event_internals.py b/addons/website_event/tests/test_event_internals.py index b460990c5ac..842a88e772d 100644 --- a/addons/website_event/tests/test_event_internals.py +++ b/addons/website_event/tests/test_event_internals.py @@ -14,7 +14,13 @@ class TestEventData(TestEventQuestionCommon): @users('user_eventmanager') def test_event_type_configuration_from_type(self): + """ Enure configuration & translations are copied from Event Type on Event creation """ + self.env['res.lang'].sudo()._activate_lang('nl_NL') + event_type = self.event_type_questions.with_user(self.env.user) + event_type_question_nl = self.event_question_1.with_context(lang='nl_NL') + event_type_question_nl.title = "Vraag1" + event_type_question_nl.answer_ids[0].name = "V1-Antwoord1" event = self.env['event.event'].create({ 'name': 'Event Update Type', @@ -41,6 +47,18 @@ class TestEventData(TestEventQuestionCommon): self.assertEqual( set(event.general_question_ids[0].mapped('answer_ids.name')), set(['Q2-Answer1', 'Q2-Answer2'])) + # verify translations + event_question_nl = event.specific_question_ids.filtered_domain([ + ('title', '=', self.event_question_1.title), + ]).with_context(lang='nl_NL') + self.assertNotEqual(event_question_nl.title, self.event_question_1.title, + "Translated title should differ from untranslated title.") + self.assertEqual(event_question_nl.title, event_type_question_nl.title, + "Translated title should be copied.") + self.assertEqual( + set(event_question_nl.answer_ids.mapped('name')), + set(event_type_question_nl.answer_ids.mapped('name')), + "Translated answer names should be copied.") def test_process_attendees_form(self): event = self.env['event.event'].create({