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

Many2Many relationship; how to make it two-way?

By
Mohamed Mahmoud
on 3/18/15, 12:19 AM 1,038 views

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

0
Jordan Vrtanoski
On 3/18/15, 1:41 AM

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)
0

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 3/18/15, 1:33 AM

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...


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: 3/18/15, 12:19 AM
Seen: 1038 times
Last updated: 3/18/15, 1:41 AM