19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:39 +01:00
parent 5df8c07b59
commit daa394e8b0
2114 changed files with 564841 additions and 299642 deletions

View file

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields
from odoo.osv import expression
from odoo.fields import Domain
import textwrap
@ -18,48 +17,30 @@ class ChatbotScriptAnswer(models.Model):
help="The visitor will be redirected to this link upon clicking the option "
"(note that the script will end if the link is external to the livechat website).")
script_step_id = fields.Many2one(
'chatbot.script.step', string='Script Step', required=True, ondelete='cascade')
'chatbot.script.step', string='Script Step', required=True, index=True, ondelete='cascade')
chatbot_script_id = fields.Many2one(related='script_step_id.chatbot_script_id')
def name_get(self):
if self._context.get('chatbot_script_answer_display_short_name'):
return super().name_get()
@api.depends('script_step_id')
@api.depends_context('chatbot_script_answer_display_short_name')
def _compute_display_name(self):
if self.env.context.get('chatbot_script_answer_display_short_name'):
return super()._compute_display_name()
result = []
for answer in self:
answer_message = answer.script_step_id.message.replace('\n', ' ')
shortened_message = textwrap.shorten(answer_message, width=26, placeholder=" [...]")
result.append((
answer.id,
"%s: %s" % (shortened_message, answer.name)
))
return result
if answer.script_step_id:
answer_message = answer.script_step_id.message.replace('\n', ' ')
shortened_message = textwrap.shorten(answer_message, width=26, placeholder=" [...]")
answer.display_name = f"{shortened_message}: {answer.name}"
else:
answer.display_name = answer.name
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
"""
Search the records whose name or step message are matching the ``name`` pattern.
The chatbot_script_id is also passed to the context through the custom widget
('chatbot_triggering_answers_widget') This allows to only see the question_answer
from the same chatbot you're configuring.
"""
force_domain_chatbot_script_id = self.env.context.get('force_domain_chatbot_script_id')
if name and operator == 'ilike':
if not args:
args = []
def _search_display_name(self, operator, value):
"""Search the records whose name or step message are matching the ``name`` pattern."""
if value and operator == 'ilike':
# search on both name OR step's message (combined with passed args)
name_domain = [('name', operator, name)]
step_domain = [('script_step_id.message', operator, name)]
domain = expression.AND([args, expression.OR([name_domain, step_domain])])
return Domain('name', operator, value) | Domain('script_step_id.message', operator, value)
return super()._search_display_name(operator, value)
else:
domain = args or []
if force_domain_chatbot_script_id:
domain = expression.AND([domain, [('chatbot_script_id', '=', force_domain_chatbot_script_id)]])
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
def _to_store_defaults(self, target):
return ["name", "redirect_link"]