nitesh
nitesh

Reputation: 266

How to inherit crm.lead to my custom module in openerp

I'm trying to inherit crm.lead into my custom module.Following is my code 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)
 }

Lead-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>

following Error given:

'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"

You may need to add a dependency on the parent class' module.

Can anyone please tell me where did i go wrong.Thanks in advance

Now i added dependency in openerp.py

openerp.py is

{
'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
}

and i'm getting this error :

except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')

Upvotes: 0

Views: 2239

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

If you want to inherit from object than please give it a proper name. First check the code of already developed modules, to see how they inherit. And know the meaning of _inherit and _name.

Make the following change in your .py file.

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)
    }

And just in your view.xml you only put this code:

<?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>

With that you will see the nitesh filed add on crm.lead form.

Hope this will solve your problem.

Upvotes: 1

Related Questions