Odoo Help


How can I relate product to another using many2many both ways?

on 9/30/14, 10:25 AM 1,047 views

I'm developing a module that should add a field Related Products. I added a many2many field

class product_template(osv.Model):
    _name = 'product.template'
    _inherit = 'product.template'
    _columns = {
        'related_products': fields.many2many('product.template', 'rel_related_product', 'product_id', string="Related Products"),

The problem is that I can relate the product only one way. I.e. if I relate ProductB to ProductA, I can only see the relationship inside ProductA and not the otherway around

How can I solve that?

AFAIK you've to add relation fields in both classes, further check if you've to use the same helper table or different ones in both modules ( 'rel_related_product' ?) and you're missing 'other.object.id' in a definition. please refer to documentation.

on 9/30/14, 10:37 AM

Techno-Functional Associate with 7+ years of experience in Odoo (formerly known as OpenERP).

On 10/1/14, 1:37 AM

You cant relate it like that .... In Product A, you have related Product B, and reverse wont apply for Product B...

Alternate option, along with M2M column, try having a functional field of type M2M, in that function fetch to & fro records pertaining to that product A...

And in your syntax, target object id is missing too...

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/30/14, 10:25 AM
Seen: 1047 times
Last updated: 3/16/15, 8:10 AM