[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) <tde@openerp.com> Signed-off-by: Levi Siuzdak <sile@odoo.com>
This commit is contained in:
@@ -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
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user