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),}