diff options
| author | XavierDo <xdo@odoo.com> | 2018-08-13 18:49:19 +0200 |
|---|---|---|
| committer | XavierDo <xdo@odoo.com> | 2018-08-13 21:45:53 +0200 |
| commit | 2df29bcfbdf8e754903b6ef3a0a7dddc00f61b08 (patch) | |
| tree | c38ad750cb029e450b3a83ef0d8776fe26cb7966 /addons/im_livechat_mail_bot/models | |
| parent | 9916e5bad3ed5eb77d2dadaa1d06949ec3b02347 (diff) | |
[IMP] mail_bot: make odoobot statefull
The current implementation of odoobot is stateless, making him a little dummy.
Adding a state on the user allow to be sure that the user don't skip a step,
or loop back to a previous step.
States also allows odoobot to repeat the question when the user don't give the
right answer.
A quick modification asked by FP before freeze, in order to change the field
type in time.
Diffstat (limited to 'addons/im_livechat_mail_bot/models')
| -rw-r--r-- | addons/im_livechat_mail_bot/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/im_livechat_mail_bot/models/mail_bot.py | 10 | ||||
| -rw-r--r-- | addons/im_livechat_mail_bot/models/res_users.py | 12 |
3 files changed, 21 insertions, 2 deletions
diff --git a/addons/im_livechat_mail_bot/models/__init__.py b/addons/im_livechat_mail_bot/models/__init__.py index ce6a8455179..dc2d4b2fef6 100644 --- a/addons/im_livechat_mail_bot/models/__init__.py +++ b/addons/im_livechat_mail_bot/models/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import mail_bot +from . import res_users diff --git a/addons/im_livechat_mail_bot/models/mail_bot.py b/addons/im_livechat_mail_bot/models/mail_bot.py index 57eacc5db5d..0c042d56fab 100644 --- a/addons/im_livechat_mail_bot/models/mail_bot.py +++ b/addons/im_livechat_mail_bot/models/mail_bot.py @@ -8,10 +8,13 @@ class MailBot(models.AbstractModel): _inherit = 'mail.bot' def _get_answer(self, record, body, values, command): + odoobot_state = self.env.user.odoobot_state if self._is_bot_in_private_channel(record): - if self._is_bot_pinged(values): + if odoobot_state == "onboarding_ping" and self._is_bot_pinged(values): + self.env.user.odoobot_state = "onboarding_canned" return _("That's me! 🎉<br/>Try to type \":\" to use canned responses.") - elif values.get("canned_response_ids"): + elif odoobot_state == "onboarding_canned" and values.get("canned_response_ids"): + self.env.user.odoobot_state = "idle" discuss_href = 'href="/web#action=mail.mail_channel_action_client_chat&active_id=%s"' % record.id discuss_src = 'src="/mail_bot/static/img/odoobot_discuss.png"' chatter_src = 'src="/mail_bot/static/img/odoobot_chatter.png"' @@ -21,5 +24,8 @@ class MailBot(models.AbstractModel): -via the <a href=%s>Discuss</a> application:<br/><img %s/><br/><br/>\ -or via the chatter:<br/><img %s/><br/><br/>\ Aaaaand that's it! Enjoy discovering Odoo!") % (discuss_href, discuss_src, chatter_src) + #repeat question if needed + elif odoobot_state == 'onboarding_canned': + return _("Not sure wat you are doing. Please press : and wait for the propositions. Select one of them and press enter.") return super(MailBot, self)._get_answer(record, body, values, command) diff --git a/addons/im_livechat_mail_bot/models/res_users.py b/addons/im_livechat_mail_bot/models/res_users.py new file mode 100644 index 00000000000..7e4a526b897 --- /dev/null +++ b/addons/im_livechat_mail_bot/models/res_users.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + +class Users(models.Model): + _inherit = 'res.users' + odoobot_state = fields.Selection( + selection_add=[ + ('onboarding_canned', 'Onboarding canned'), + ]) + |
