[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
This commit is contained in:
Thibault Delavallée
2020-05-27 12:48:21 +00:00
parent 936d206559
commit 2598061be8
5 changed files with 6 additions and 5 deletions
@@ -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'})})
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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({
+1 -1
View File
@@ -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):