python - Many2one field with our own function in openerp -


i need create many2one field.but should need filter data per logic in function.it should selectbox also.then how implement in openerp ver 7 ?

i tried below code.but not give list, need. load value model.and need first value of select box should selected default.

 def _sel_proj(self, cr, uid,context=none):         cr.execute("""select project.id,account.name 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                            (account.user_id = %s or rel.uid = %s) group project.id,account.name"""%(uid, uid))         return [(r[0],r[1]) r in cr.fetchall()]   _name  = 'mat.mgmt'  _columns = {'project_id':fields.many2one('project.project','project',selection=_sel_proj,select=true,required=true),} 

you need set project_id many2one , remove selection attribute field definition. can make selection xml using widget="selection" attribute on field.

to 1 value in default, need make default function that, add logic on there , return first value using result[0]. call function _defaults in py this:

def _get_project(self, cr, uid, context=none):         #add logic         return result[0]  'project_id': _get_project 

and show limited records per logic, if possible, can convert domain , add domain on project_id field xml this

domain="[('analytic_account_id.user_id','=',uid)]"  

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -