0

I need to create many2one field.but it should need to filter data as per my logic in function.It should be selectbox also.then how to implement this in OpenERP ver 7 ?

i tried with below code.But its not give a list, which i need. It just load all value from the model.And I need the first value of the select box should be get selected by default.

 def _sel_proj(self, cr, uid,context=None):
        cr.execute("""SELECT project.id,account.name FROM project_project project
                           LEFT JOIN account_analytic_account account ON account.id = project.analytic_account_id
                           LEFT JOIN project_user_rel rel ON rel.project_id = project.id
                           WHERE (account.user_id = %s or rel.uid = %s) GROUP BY project.id,account.name"""%(uid, uid))
        return [(r[0],r[1]) for r in cr.fetchall()]

 _name  = 'mat.mgmt'
 _columns = {'project_id':fields.many2one('project.project','Project',selection=_sel_proj,select=True,required=True),}
4

2 回答 2

0

您可以使用

'project_id': fields.selection(_get_project, 'Select Supplier'),
于 2014-07-13T02:05:28.017 回答
0

您需要将 project_id 设置为 many2one 并从字段定义中删除选择属性。您可以通过在该字段上使用 widget="selection" 属性从 xml 中进行选择。

要获得一个默认值,您需要为此创建默认函数,在那里添加您的逻辑并使用结果 [0] 返回其第一个值。从 py 中的 _defaults 调用此函数,如下所示:

def _get_project(self, cr, uid, context=None):
        #ADD YOUR LOGIC
        return result[0]

'project_id': _get_project

并根据您的逻辑显示有限的记录,如果可能,您可以将其转换为域并像这样在 xml 的 project_id 字段上添加域

domain="[('analytic_account_id.user_id','=',uid)]" 
于 2013-05-15T05:48:35.317 回答