summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-05-27 08:44:15 +0000
committerThibault Delavallée <tde@odoo.com>2020-05-27 12:48:21 +0000
commit2598061be8ef8ce44f92f61bf16befb977f3030c (patch)
tree4460e4e863d59324bf00f30fa7da5aadd8b5b8e3
parent936d206559035627b07a25e7a0f807ad43d39f54 (diff)
[IMP] mail_bot: remove required on odoobot_state
Purpose is to avoid having strong requirements on fields where it is not really necessary. In this commit we consider now that a void odoobot_state is the same as ``not_initialized`` key. It allows to remove both the default and required parameters on the field. Task ID 2233014 PR #49661
-rw-r--r--addons/im_livechat_mail_bot/models/res_users.py3
-rw-r--r--addons/mail_bot/models/ir_http.py2
-rw-r--r--addons/mail_bot/models/mail_bot.py2
-rw-r--r--addons/mail_bot/models/mail_channel.py2
-rw-r--r--addons/mail_bot/models/res_users.py2
5 files changed, 6 insertions, 5 deletions
diff --git a/addons/im_livechat_mail_bot/models/res_users.py b/addons/im_livechat_mail_bot/models/res_users.py
index 2803dddd98e..ce1bd2668f9 100644
--- a/addons/im_livechat_mail_bot/models/res_users.py
+++ b/addons/im_livechat_mail_bot/models/res_users.py
@@ -6,6 +6,7 @@ from odoo import models, fields
class Users(models.Model):
_inherit = 'res.users'
+
odoobot_state = fields.Selection(selection_add=[
('onboarding_canned', 'Onboarding canned'),
- ], ondelete={'onboarding_canned': 'set default'})
+ ], ondelete={'onboarding_canned': lambda users: users.write({'odoobot_state': 'disabled'})})
diff --git a/addons/mail_bot/models/ir_http.py b/addons/mail_bot/models/ir_http.py
index c2f358a281e..1c5c391630c 100644
--- a/addons/mail_bot/models/ir_http.py
+++ b/addons/mail_bot/models/ir_http.py
@@ -10,5 +10,5 @@ class Http(models.AbstractModel):
def session_info(self):
res = super(Http, self).session_info()
if self.env.user.has_group('base.group_user'):
- res['odoobot_initialized'] = self.env.user.odoobot_state != 'not_initialized'
+ res['odoobot_initialized'] = self.env.user.odoobot_state not in [False, 'not_initialized']
return res
diff --git a/addons/mail_bot/models/mail_bot.py b/addons/mail_bot/models/mail_bot.py
index 6c17d60bbd4..8432fa51092 100644
--- a/addons/mail_bot/models/mail_bot.py
+++ b/addons/mail_bot/models/mail_bot.py
@@ -53,7 +53,7 @@ class MailBot(models.AbstractModel):
self.env.user.odoobot_state = "idle"
self.env.user.odoobot_failed = False
return _("I am a simple bot, but if that's a dog, he is the cutest 😊 <br/>Congratulations, you finished this tour. You can now <b>close this chat window</b>. Enjoy discovering Odoo.")
- elif odoobot_state in ("idle", "not_initialized") and (_('start the tour') in body.lower()):
+ elif odoobot_state in (False, "idle", "not_initialized") and (_('start the tour') in body.lower()):
self.env.user.odoobot_state = "onboarding_emoji"
return _("To start, try to send me an emoji :)")
# easter eggs
diff --git a/addons/mail_bot/models/mail_channel.py b/addons/mail_bot/models/mail_channel.py
index 909696e5618..6abccc8b426 100644
--- a/addons/mail_bot/models/mail_channel.py
+++ b/addons/mail_bot/models/mail_channel.py
@@ -13,7 +13,7 @@ class Channel(models.Model):
@api.model
def init_odoobot(self):
- if self.env.user.odoobot_state == 'not_initialized':
+ if self.env.user.odoobot_state in [False, 'not_initialized']:
partner = self.env.user.partner_id
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
channel = self.with_context(mail_create_nosubscribe=True).create({
diff --git a/addons/mail_bot/models/res_users.py b/addons/mail_bot/models/res_users.py
index 8468bc16d0f..6b49a3217d8 100644
--- a/addons/mail_bot/models/res_users.py
+++ b/addons/mail_bot/models/res_users.py
@@ -15,7 +15,7 @@ class Users(models.Model):
('onboarding_ping', 'Onboarding ping'),
('idle', 'Idle'),
('disabled', 'Disabled'),
- ], string="OdooBot Status", readonly=True, required=True, default="not_initialized") # keep track of the state: correspond to the code of the last message sent
+ ], string="OdooBot Status", readonly=True, required=False) # keep track of the state: correspond to the code of the last message sent
odoobot_failed = fields.Boolean(readonly=True)
def __init__(self, pool, cr):