python - 尝试使用 mail_thread 时 Odoo 继承错误

标签 python python-3.x odoo odoo-12

我正在尝试在 odoo 中制作一个通知应用程序,它将向用户发送邮件。我找到了文档 https://www.odoo.com/documentation/12.0/reference/mixins.html ,但是当我尝试启动 odoo 时,我收到错误消息 non-existing model 'mail.thread'。我该如何解决这个问题?

模型.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)]
        )

日志

сту 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'. - - -

最佳答案

您需要在您的模块中添加以下依赖项:ma​​nifest.py: '取决于':['邮件'], 因为您正试图从插件的“邮件”模块继承(在此模块上找到 mail.thread)。基本这个模块没有安装。因此,在安装此模块之前,您正在尝试从不存在的模型继承。我建议您使用依赖于使用其他模型(继承模型/ View )的所有模块。在这种情况下,您将不会再收到任何此类错误。 祝你好运!

关于python - 尝试使用 mail_thread 时 Odoo 继承错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54267687/

相关文章:

python - PyTorch 中带有 dropout 正则化的逻辑回归

Python:有选择地重载属性?

python - 是否建议不要在来自不同 conda channel 的 conda 环境中混合包?

python - Odoo-9:通过 setattr 添加字段时出现 "RuntimeError: maximum recursion depth exceeded"

javascript - 在 Python 中从 WebSocket 读取(来自 Javascript WebSocket 的数据)

python - 将元组扩展为参数

python - Odoo Python3 base64 错误 : TypeError: expected bytes-like object, 不是文本

python - 当我尝试使用 odoo Controller 向我的模型添加记录时,出现此错误 "The requested URL was not found on the server"

python - 在单元测试中测试一个函数是否在另一个函数内部被调用

python - 我们可以在位置格式化中执行算术运算吗?