Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can i have Reverse relation for many2many field in version 7.0?

By
samba
on 9/8/15, 6:50 AM 542 views

I have two models. 1.chercheurs  2. structures

i have chercheurs -> many2many -> structures

for example i have selected  structures structures1, structures2 in chercheurs form. The name of the chercheurs is "ch1".

This "ch1" i want to show in structures1, structures2 form, tree view.

if structures1 is selected in more chercheurs called "ch2", "ch3" then these all chercheurs should show in structures1 form, tree view.

Which field in the odoo can help me?. Here is my two models.


class chercheurs(osv.osv):

_name='chercheurs'

_columns={

'code':fields.integer('id'),

'name':fields.char('name'),

'email':fields.char('email'),

'phone':fields.char('phone'),

'function':fields.char('function'),

'responsible':fields.many2one('res.users',string='responsible'),

'active':fields.boolean('active'),

'structures_ids':fields.many2many('structures','structures_rel',string='Structures'),

'publication_ids':fields.many2many('publication', 'chercheurs_publication_rel', string='publications'),

}

_defaults={

'active':True,

}


## structures model ###


class structures(osv.osv):

_name='structures'

 

_columns={

'code':fields.integer('id'),

'name':fields.char('name'),

'establishment_id':fields.many2one('establishment',string='establishment'),

'type_id':fields.many2one('type',string="type"),

'active':fields.boolean('active'),

}

_defaults={

'active':True,

}


0
samba
On 9/14/15, 11:52 PM

Solved this with fuction field in structures. 'chercheurs_id1':fields.function(_get_chercheurs_ids, type='many2many', relation="chercheurs", string="chercheurs"), def _get_chercheurs_ids(self, cr, uid, ids,field_name, arg, context=None): result = {} for record in self.browse(cr, uid, ids, context=context): result[record.id] = [] cr.execute('select chercheurs_id from structures_rel where structures_id=%s'%(record.id,)) res=cr.fetchall() if len(res)>0: result[record.id] = [x[0] for x in res] return result

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/8/15, 6:50 AM
Seen: 542 times
Last updated: 9/14/15, 11:52 PM