Odoo开发通知应用继承mail.thread报错:模型不存在求助
Fix: Non-existing model 'mail.thread' Error in Odoo 12.0
这个错误的核心原因很清晰:你的模块没有声明对mail模块的依赖,导致Odoo在加载my.skype模型时,mail.thread所在的mail模块还未完成加载,自然找不到这个父模型。
Step 1: Add 'mail' Dependency to Your Module
你需要修改模块根目录下的__manifest__.py(如果是旧结构可能叫__openerp__.py),把mail添加到depends列表中:
{ 'name': 'My Skype Notification App', 'version': '1.0', 'depends': ['base', 'mail'], # 新增'mail'依赖项 'author': 'Your Name', 'data': [], 'installable': True, 'auto_install': False, }
Why This Works
Odoo严格按照模块依赖顺序加载模块,只有当依赖的模块完全加载完成后,才会加载你的自定义模块。添加mail依赖后,Odoo会优先加载包含mail.thread的mail模块,你的my.skype模型就能正常继承这个Mixin了。
Bonus: Deprecation Note for Your Code
顺便提个小细节:在Odoo 12.0中@api.one装饰器已经被弃用,建议替换成@api.multi(如果方法需要处理多条记录)或者@api.model(如果不需要操作当前记录集),避免后续出现兼容性问题:
# 替换原来的@api.one @api.multi 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)] )
Your Original Error Context
你遇到的错误日志:
сту 19 16:20:46 PK odoo[20993]: TypeError: Model 'my.skype' inherits from non-existing model 'mail.thread'.
你的模型代码:
class skype_bot(models.Model): _name = 'my.skype' _inherit = ['mail.thread'] _description = 'My Skype' @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)] )
内容的提问来源于stack exchange,提问作者Sabr
相关产品推荐
相关产品推荐

