Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

构建一个动态field.selection控件的问题



  • 我现在想实现如下的功能,在crm.lead中,建立一个sales.contacts对象,用来建立销售纪录。在sales.contacts中,定义一个联系人字段,初始化它是从与crm.lead关联(通过一个新建字段lead_id)的res.partner.address中取得所有联系人的name,然后构成一个列表,可以供用户选择。
    基本代码如下:

    <br />class crm_sales_contacts(crm.crm_case, osv.osv):<br />_name = &quot;crm.sales.contacts&quot;<br /><br />def _get_contacts_list(self,cr,uid,ids,context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; if context is None:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; lead_obj = self.pool.get(&#039;crm.lead&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; contact_obj = self.pool.get(&#039;res.partner.address&#039;)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; contact_ids = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; rec_ids = context and context.get(&#039;active_ids&#039;, &#91;])<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; for lead in lead_obj.browse(cr, uid, rec_ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contact_id=contact_obj.search(cr,uid,[(&#039;lead_id&#039;,&#039;=&#039;,lead)],context=context)[0]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if contact_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contact = contact_obj.browse(cr, uid, contact_id, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #contact_name = contact_obj.name_get(cr, uid,contact_id)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #contact_name = contact_obj.read(cr, uid, contact_id, &#91;&#039;name&#039;],context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contact_ids.append(contact.name)<br />&nbsp; &nbsp; &nbsp; &nbsp; if contact_ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return contact_ids<br />&nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise osv.except_osv(_(&#039;错误 !&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _(&#039;查询不到联系人,请首先建立联系人信息!&#039;))<br />&nbsp; &nbsp; &nbsp; &nbsp; return True<br />_columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;contact_name&#039;:fields.selection(&#91;],string=&#039;Contacts&#039;),<br />}<br />_defaults = {&nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;contact_name&#039;:_get_contacts_list<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />
    


    现在的问题是,一旦新建sales_contact纪录,openerp就死掉了,也没有错误信息弹出,电脑风扇开始狂转,似乎是陷入了死循环一样的境地。
    请问我上述的代码是哪里出了问题呢?
    请帮忙看看,非常感谢。


Log in to reply