在我在OpenERP中的自定义模块中将潜在客户转换为商机时,我尝试创建机会时出错

时间:2014-02-05 06:53:31

标签: openerp openerp-7

我成功将CRM模块继承到我的自定义模块中。现在我需要将潜在客户转换为机会并安排一个电话。当我尝试将Lead转换为机会时,我收到以下错误。

错误:

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

代码 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>

1 个答案:

答案 0 :(得分:1)

您没有继承crm.lead模型,而是创建了一个新模型bala.lead。那是,当然,你的选择,但是你不能继承新模型的表单视图。但是你在这里做到了:

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

如果您希望真正扩展原始的crm.lead模型,只需调用您的模型(_name = crm.lead)并更改您的xml文件:

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

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

如果你想要自己的主导模型包含来自crm.lead的所有字段,只需编写自己的bala.lead表单视图,不要继承其他模型视图。