我正在尝试在Odoo中的现有对象上添加继承,将“mail.alias.mixin”添加到“utm.campaign”对象中。
我试着做_inherit = [“mail.alias.mixin”,“utm.campaign”]但是当我安装我的模块时它总是说
File "/home/randy/Odoo/odoo_12/odoo/modules/registry.py", line 180, in __getitem__
return self.models[model_name]
KeyError: None
这是我的完整代码:
manifest.朋友
{
"name": "CRM ext",
"version": "12.4.0.0.0",
'author': 'me',
"description": """
extend CRM.
""",
"depends": [
'crm',
'calendar',
'fetchmail',
'utm',
'web_tour',
'digest',
'mail',
],
'init_xml': [],
'data': [
"security/ir.model.access.csv",
'data/crm_question.xml',
'wizard/lost_and_link_partner_crm_wizard_views.xml',
'views/crm_lead_view.xml',
],
'installable': True,
'active': False,
'application': False,
}
而我的utm.py
from odoo import api, fields, models, SUPERUSER_ID
from odoo.http import request
from odoo.tools import pycompat
from odoo.tools.safe_eval import safe_eval
class Campaign(models.Model):
_name = "utm.campaign"
_inherit = ["mail.alias.mixin", "utm.campaign"]
alias_id = fields.Many2one('mail.alias', string='Alias', ondelete="restrict", required=True, help="The email address associated with this campaign. New emails received will automatically create new leads assigned to the campaign.")
crm_team_id = fields.Many2one('crm.team', string="CRM Team")
我除了我的继承是正确的,但似乎我遗漏了一些东西。
根据Odoo 12文档,只有设置了_name,才能从多个模型继承。在您的代码中,_name等于父模型,与未设置名称相同。您没有定义新模型,因此您无法从多个父项继承。
https://www.odoo.com/documentation/12.0/reference/orm.html#reference-orm-inheritance
_inherit如果设置了_name,则继承的父模型的名称。如果从单个父级继承,则可以是str如果未设置_name,则将单个模型的名称扩展到位
我找到了,
所以“mail.alias.mixin”是抽象对象,我想念这个。所以,我也需要实现所有的抽象方法。
希望这可以拯救某人的一天!