Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
17221 Visualizzazioni

Hi all,

I have created a many2many relationship via Python code between partners to allow partner A to have more than one associated company B & C for example. 

Now, if I go to partner B or C, I am expecting to see A; but, this is not the case. 

I think this behavior is normal; because I only added the records for B & C under A and not the other way around.

Any idea how I can make this happen the other way around?

Thanks in advance.

Sincerely,

Mohamed

Avatar
Abbandona
Risposta migliore

Hi ,,

Here is the syntax for many2many:-

field_name = fields.Many2many ( 'res.partner.category',  'res_partner_category_rel',  'partner_id',  'category_id',  'Categories'),

Example with book and author:-

In author-

book_ids = fields.Many2many('op.book', 'book_author_rel', 'op_author_id', 'op_book_id', string='Books'),

In book-

author_ids = fields.Many2many('op.author', 'book_author_rel', 'op_book_id', 'op_author_id', string='Author'),

And you can link between both books and authors and its bidirectional.


Hope this helps...


Avatar
Abbandona
Risposta migliore

In Odoo7 you can use the "fields.related" type of fields.

In Odoo8 the "fields.related" are replaced with attributes on the relations fields (one2many, many2one and many2many). The parameters are "related=". Following is example of the related field: 

fields.Char(related=’user_id.partner_id.name’, store=True)
Avatar
Abbandona