Error when I'm trying to create opportunity when converting lead to opportunity in my custom module in OpenERP

StackOverflow https://stackoverflow.com/questions/21570495

  •  07-10-2022
  •  | 
  •  

Question

I successfully inherited the CRM module into my custom module. Now I need to convert lead to opportunity and schedule a call.I'm getting the following error when I try to convert Lead to opportunity.

Error:

Client Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/http.py", line 204, in dispatch
    response["result"] = method(self, **self.params)
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/controllers/main.py", line 1128, in call_kw
    return self._call_kw(req, model, method, args, kwargs)
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/controllers/main.py", line 1120, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 42, in proxy
    result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 30, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 103, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)


Server Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 89, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/pymodules/python2.7/openerp/addons/crm/wizard/crm_lead_to_opportunity.py", line 51, in default_get
    res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/addons/crm/wizard/crm_partner_binding.py", line 89, in default_get
    res = super(crm_partner_binding, self).default_get(cr, uid, fields, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 1583, in default_get
    self.view_init(cr, uid, fields_list, context)
  File "/usr/lib/pymodules/python2.7/openerp/addons/crm/wizard/crm_lead_to_opportunity.py", line 91, in view_init
    if lead.state in ['done', 'cancel']:
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 499, in __getattr__
    raise AttributeError(e)
AttributeError: 'Field state not found in browse_record(crm.lead, 4)'

Code 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"
 _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_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"/>
    <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">bala.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>

<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Lead" id = "menu_lis_lab" />
  <menuitem name="Leads" id="sub_lead" parent="menu_lis_lab" />
    <menuitem name="Create Lead" id="create_lead" parent="sub_lead" action="new_lead"/> 
</data>
</openerp>
Was it helpful?

Solution

You're not inheriting the crm.lead model, instead you're creating a new model bala.lead. That's, ofcourse, your choice, but then you can't inherit a form view for your new model. But you're doing it right here:

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

If you wish to really extend the original crm.lead model just call your model like that (_name=crm.lead) and change your xml-file, too:

<field name="model">bala.lead</field> (to crm.lead)

<field name="res_model">bala.lead</field> (to crm.lead)

If you want your own lead model with all fields from crm.lead, just write your own bala.lead form view and don't inherit from other models views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top