After inheriting CRM-Lead unable to hide or add fields to my Custom module in Openerp

时间秒杀一切 提交于 2019-12-24 13:23:02

问题


I have created a new custom module and inherited CRM-LEAD. I'm trying add new fields and hide existing fields.I couldn't do it.Can anyone please tell me how can I do it. My code is

__init__.py:

import lead

__openerp__.py:

{
'name': 'Lead Information',
'version': '0.1',
'category': 'Tools',
'description': """This module is Lead information.""",
'author': 'Nitesh',
'website': '',
'depends': ['crm'],
'init_xml': ['lead_view.xml'],
'update_xml': [],
'demo_xml': [],
'installable': True,
'active': True,
'application': True
}

lead.py:

from osv import osv
from osv import fields

class crm_lead(osv.osv):
 _name = 'bala.lead'
 _inherit = 'crm.lead'
 _description = "adding fields to crm.lead"
 _coloumns = {
    'nitesh_lead': fields.char('Nitesh Lead',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_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="email_from" postion="replace"/>
            <field name="partner_name" postion="after">
                <field name="nitesh_lead"/>
            </field>
       </field>
    </record>
    <record id="new_lead" model="ir.actions.act_window">
        <field name="name">Lead</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_extended"/>
    </record>
       <!-- ===========================Menu Settings=========================== -->
    <menuitem name ="Lead" id = "menu_lis_lab" action="new_lead"/>
</data>
</openerp>

Can anyone please say me where did I go wrong?


回答1:


update your xml file,

<?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">bala.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
    <field name="email_from" postion="replace"/>
    <xpath expr="//label[@for='contact_name']" position="before">
                <field name="nitesh_lead"/>
    </xpath>
    <field name="function" position="replace"/>
    <field name="partner_name" position="replace"/>
    <field name="priority" position="replace"/>
    <field name="partner_id" position="replace"/>
</field>
</record>
<record id="new_lead" model="ir.actions.act_window">
  <field name="name">Lead</field>
  <field name="res_model">bala.lead</field>
  <field name="view_type">form</field>
  <field name="view_mode">form</field>
  <field name="view_id" ref="crm_case_form_view_leads_extended"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Lead" id = "menu_lis_lab" action="new_lead"/>
</data>
</openerp>

you py file should be,

from openerp.osv import fields, osv

class crm_lead(osv.osv):
    _name = 'bala.lead'
    _inherit = 'crm.lead'
    _description = "adding fields to crm.lead"
    _columns = {
          'nitesh_lead': fields.char('Nitesh Lead',size=64)
    }
crm_lead()

Hope this will give you desired output. and don't forget to update your module after this changes.



来源:https://stackoverflow.com/questions/21527899/after-inheriting-crm-lead-unable-to-hide-or-add-fields-to-my-custom-module-in-op

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!