简体   繁体   中英

Onclick of Lead couldn't get the details of Lead in custom Module in openerp

I'm creating a custom module and trying to convert the Lead to Opportunity.Now i'm fetching all the leads and showing like in img1. But actually i want to display like img2 and on click of any lead it should take me to simlar scrren like img3 where i can have option to converting a lead to Opportunity. My problem is on click of any lead in img1 ,there is no response.Thanks in advance. My Code is

lead.py

from osv import osv
from osv import fields

class crm_lead(osv.osv):
 _name = 'crm.lead'
 _inherit = 'crm.lead'
 _description = "adding fields to crm.lead"
 _columns = {
    'nitesh_lead': fields.char('Nitesh Lead',size=64),
    'lead_source': fields.many2one('crm.lead.source','Lead Source'),
    'lead_status': fields.many2one('crm.lead.status','Lead Status')
 }
 class res_partner_title(osv.osv):
    _name = 'crm.lead.source'
    _order = 'name'
    _columns = {
        'name': fields.char('Source', required=True, size=46, translate=True)
    }
 class res_partner_title(osv.osv):
    _name = 'crm.lead.status'
    _order = 'name'
    _columns = {
        'name': fields.char('Status', required=True, size=46, translate=True)
    }

lead_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

 <!-- ========================This is Form layout===============================-->
<record id="crm_case_tree_view_oppor_extended" model="ir.ui.view">
<field name="name">Opportunities Tree</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor" />
<field name="arch" type="xml">
    <field name="planned_revenue" position="replace"/>
    <field name="probability" position="replace"/>
</field>
</record>


<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="contact_name" position="replace"/>
    <label for="contact_name" position="replace">
      <br/>
    </label>
    <xpath expr="//label[@for='street']" position="before">
                <field name="contact_name"/>
    </xpath>
    <xpath expr="//label[@for='section_id']" position="before">
                <field name="lead_source"/>
                <field name="lead_status"/>
    </xpath>

    <field name="function" position="replace"/>
    <field name="partner_name" position="replace"/>
    <field name="priority" position="replace"/>
    <field name="categ_ids" position="replace"/>
    <field name="partner_id" position="replace"/>

</field>
</record>


<!-- ===========================Action layout=========================== -->
<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,tree</field>
  <field name="view_id" ref="crm_case_form_view_leads_extended"/>
</record>

  <record id="show_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">tree</field>
    <field name="view_mode">tree</field>
    <field name="view_id" ref="crm_case_tree_view_oppor_extended"/>
  </record>

<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Lead" id = "menu_lead" />
  <menuitem name="Leads" id="sub_menu_lead" parent="menu_lead" />
    <menuitem name="Create Lead" id="create_lead" parent="sub_menu_lead" action="new_lead"/> 
    <menuitem name="Show Lead" id="show_leads" parent="sub_menu_lead" action="show_lead"/> 
</data>
</openerp>

IMG1

IMG2

IMG3

you only need one menuitem to show your leads (you can create from within it).

so first the action:

<record id="show_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,tree</field>
    <field name="view_id" ref="crm_case_tree_view_oppor_extended"/>
</record>

and the menuitem:

<menuitem name="Show Lead" id="show_leads" parent="sub_menu_lead" action="show_lead"/>

just delete the create_lead action and menuitem

and a little hint: if you got xml errors, go to the stacktrace riiiiight before the output of the xml part (the record where the error belongs to) and you will mostly find the real error message like "can't find field anyfield in model anymodel "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM