我正在尝试将crm.lead继承到我的自定义模块中。以下是我的代码 lead.py
from osv import osv
from osv import fields
class res_partner(osv.osv):
_name =
_inherit = 'crm.lead'
_description = "adding fields to crm.lead"
_coloumns = {
'nitesh': fields.char('Nitesh',size=64)
}
铅view.xml用
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ========================This is Form layout===============================-->
<record id="crm_case_form_view_leads" model="ir.ui.view">
<field name="name">CRM - Leads Form</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<field name="partner_name" postion="after">
<field name="nitesh"/>
</field>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record id="create_lead" model="ir.actions.act_window">
<field name="name">Lead Form</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="crm_case_form_view_leads"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name="Lead" id="menu_lis_lab"/>
<menuitem name="Lead Info" id="sublead_menu" parent="menu_lis_lab"/>
<menuitem name="Create Lead" id="create_lead" parent="sublead_menu" action="create_lead"/>
</data>
</openerp>
发出以下错误:
'You may need to add a dependency on the parent class\' module.' % (name, parent_name))
TypeError: The model "crm.lead" specifies an unexisting parent class "crm.lead"
您可能需要在父类的模块上添加依赖项。
任何人都可以告诉我哪里出错了。谢谢你提前
现在我在 openerp .py
中添加了依赖项openerp .py
{
'name': 'Lead Information',
'version': '0.1',
'category': 'Tools',
'description': """This module is Lead information.""",
'author': 'Nitesh',
'website': '',
'depends': ['base','crm'],
'init_xml': ['customer_view.xml'],
'update_xml': [],
'demo_xml': [],
'installable': True,
'active': True,
'application': True
}
我收到了这个错误:
except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')
答案 0 :(得分:1)
如果你想从对象继承,请给它一个正确的名称。首先检查已开发模块的代码,看看它们是如何继承的。并了解 _inherit 和 _name 的含义。
在.py文件中进行以下更改。
from osv import osv
from osv import fields
class crm_lead(osv.osv):
_inherit = 'crm.lead'
_description = "adding fields to crm.lead"
_coloumns = {
'nitesh': fields.char('Nitesh',size=64)
}
就在你的view.xml中,你只需输入以下代码:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ========================This is Form layout===============================-->
<record id="crm_case_form_view_leads_extended" model="ir.ui.view">
<field name="name">CRM - Leads Form</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<field name="partner_name" postion="after">
<field name="nitesh"/>
</field>
</field>
</record>
</data>
</openerp>
有了这个,你会看到nitesh在crm.lead表格上添加。
希望这能解决您的问题。