From 52af5b6d0a69db7b6291292fb2bc013f8b5c05d4 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Fri, 1 Sep 2023 11:22:40 +0200 Subject: [PATCH] [FIX] im_livechat: bad coping of chatschript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit when you copy a chatbot script, the triggering answer are mixing. - Create a chatbot - Create a line A - question ligne with one response 1 - Create a line B - type text - Create a line C - type text - Save - Invert line B and C - on ligne C add response 1 in triggering answer - Save - Copy the script --> Issue the response 1 in triggering answer is now in line B closes odoo/odoo#134565 X-original-commit: 118a065e38d6fd73a49cfd52ec4693808bfc11d1 Signed-off-by: Alexandre Kühn (aku) --- addons/im_livechat/models/chatbot_script.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/im_livechat/models/chatbot_script.py b/addons/im_livechat/models/chatbot_script.py index 1c3764eaacd..97caa3e7904 100644 --- a/addons/im_livechat/models/chatbot_script.py +++ b/addons/im_livechat/models/chatbot_script.py @@ -10,7 +10,7 @@ class ChatbotScript(models.Model): _description = 'Chatbot Script' _inherit = ['image.mixin', 'utm.source.mixin'] _rec_name = 'title' - _order = 'title' + _order = 'title, id' # we keep a separate field for UI since name is manipulated by 'utm.source.mixin' title = fields.Char('Title', required=True, translate=True, default="Chatbot") @@ -68,13 +68,15 @@ class ChatbotScript(models.Model): if 'question_ids' in default: return clone_chatbot_script - answers_map = { - original_answer: clone_answer - for clone_answer, original_answer - in zip(clone_chatbot_script.script_step_ids.answer_ids, self.script_step_ids.answer_ids) - } + original_steps = self.script_step_ids.sorted() + clone_steps = clone_chatbot_script.script_step_ids.sorted() - for clone_step, original_step in zip(clone_chatbot_script.script_step_ids, self.script_step_ids): + answers_map = {} + for clone_step, original_step in zip(clone_steps, original_steps): + for clone_answer, original_answer in zip(clone_step.answer_ids.sorted(), original_step.answer_ids.sorted()): + answers_map[original_answer] = clone_answer + + for clone_step, original_step in zip(clone_steps, original_steps): clone_step.write({ 'triggering_answer_ids': [ (4, answer.id)