尝试使用 mail_thread 时 Odoo 继承错误
Odoo inherit error when try to use mail_thread
我正在尝试在 odoo 中制作一个通知应用程序,它将向用户发送邮件。我找到了文档 https://www.odoo.com/documentation/12.0/reference/mixins.html,但是当我尝试启动 odoo 时,我收到错误不存在的模型 'mail.thread'。我该如何解决这个问题?
models.py:
class skype_bot(models.Model):
_name = 'my.skype'
_inherit = ['mail.thread']
_description = 'My Skype'
# class MySkype(skpy.SkypeEventLoop):
# def onEvent(self, event):
# if isinstance(event, skpy.SkypeNewMessageEvent):
# print(repr(event))
# message = ('New message from user {} at {}: \'{} \''.format(event.msg.userId,
# event.msg.time.strftime(
# '%H:%M dd. %d.%m.%Y'),
# event.msg.content))
@api.one
def SentMail(self, message):
print('called function sentmail')
self.env['mail.message'].create({'message_type': 'notification',
'subtype': self.env.ref('mail.mt_comment').id,
'body': message,
'subject': 'Message subject',
'needaction_partner_ids': [(4, 3)],
})
self.message_post(
subject='Skype message',
body=message,
partner_ids=[(4, 3)]
)
log
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 417, in load_modules
сту 19 16:20:46 PK odoo[20993]: force, status, report, loaded_modules, update_module, models_to_check)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 313, in load_marked_modules
сту 19 16:20:46 PK odoo[20993]: perform_checks=perform_checks, models_to_check=models_to_check
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 188, in load_module_graph
сту 19 16:20:46 PK odoo[20993]: model_names = registry.load(cr, package)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/registry.py", line 240, in load
сту 19 16:20:46 PK odoo[20993]: model = cls._build_model(self, cr)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/models.py", line 458, in _build_model
сту 19 16:20:46 PK odoo[20993]: raise TypeError("Model %r inherits from non-existing model %r." % (name, parent))
сту 19 16:20:46 PK odoo[20993]: TypeError: Model 'my.skype' inherits from non-existing model 'mail.thread'. - - -
您需要在 manifest.py 模块中添加以下依赖项:
'depends' : ['mail'],
因为您正试图从插件的 'mail' 模块继承(mail.thread 在此模块上找到)。基本这个模块没有安装。因此,在安装此模块之前,您正在尝试从不存在的模型继承。我建议您使用 depends on all modules that are using another models (inherit model/views)。在这种情况下,您将不会再收到任何此类错误。
祝你好运!
我正在尝试在 odoo 中制作一个通知应用程序,它将向用户发送邮件。我找到了文档 https://www.odoo.com/documentation/12.0/reference/mixins.html,但是当我尝试启动 odoo 时,我收到错误不存在的模型 'mail.thread'。我该如何解决这个问题?
models.py:
class skype_bot(models.Model):
_name = 'my.skype'
_inherit = ['mail.thread']
_description = 'My Skype'
# class MySkype(skpy.SkypeEventLoop):
# def onEvent(self, event):
# if isinstance(event, skpy.SkypeNewMessageEvent):
# print(repr(event))
# message = ('New message from user {} at {}: \'{} \''.format(event.msg.userId,
# event.msg.time.strftime(
# '%H:%M dd. %d.%m.%Y'),
# event.msg.content))
@api.one
def SentMail(self, message):
print('called function sentmail')
self.env['mail.message'].create({'message_type': 'notification',
'subtype': self.env.ref('mail.mt_comment').id,
'body': message,
'subject': 'Message subject',
'needaction_partner_ids': [(4, 3)],
})
self.message_post(
subject='Skype message',
body=message,
partner_ids=[(4, 3)]
)
log
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 417, in load_modules
сту 19 16:20:46 PK odoo[20993]: force, status, report, loaded_modules, update_module, models_to_check)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 313, in load_marked_modules
сту 19 16:20:46 PK odoo[20993]: perform_checks=perform_checks, models_to_check=models_to_check
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 188, in load_module_graph сту 19 16:20:46 PK odoo[20993]: model_names = registry.load(cr, package) сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/registry.py", line 240, in load
сту 19 16:20:46 PK odoo[20993]: model = cls._build_model(self, cr)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/models.py", line 458, in _build_model
сту 19 16:20:46 PK odoo[20993]: raise TypeError("Model %r inherits from non-existing model %r." % (name, parent))
сту 19 16:20:46 PK odoo[20993]: TypeError: Model 'my.skype' inherits from non-existing model 'mail.thread'. - - -
您需要在 manifest.py 模块中添加以下依赖项: 'depends' : ['mail'], 因为您正试图从插件的 'mail' 模块继承(mail.thread 在此模块上找到)。基本这个模块没有安装。因此,在安装此模块之前,您正在尝试从不存在的模型继承。我建议您使用 depends on all modules that are using another models (inherit model/views)。在这种情况下,您将不会再收到任何此类错误。 祝你好运!