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

Why can relate two fields one2many?

By
Vicious
on 1/14/14, 5:05 PM 1,023 views

Hi guys, have a query, i write a OpenERP v7 module to workshop, i have a object class 'vehicle' and another object 'service', actually, each vehicle can have many services, through a one2many relational field in object 'vehicle', but I also need to do the opposite, I mean several vehicles relate to each service

0
Timo Talvitie
On 1/14/14, 6:20 PM

Sounds like you should use a many2many relation for this: each of your vehicles can be linked to X services, and each of your services can be linked to Y vehicles. Try using the following fields:

In your vehicle class:

'service_ids':
   fields.many2many(
    'mymodule.service',
    'service_rel',
    'vehicle_id',
    'service_id',
    'Services'),

And in your service class the same thing but in reverse:

'vehicle_ids':
   fields.many2many(
    'mymodule.vehicle',
    'service_rel', # same relation still
    'service_id', # ...but fields of the relation now go in different order
    'vehicle_id',
    'Vehicles'),

The documentation has some notes on m2m usage here: https://doc.openerp.com/trunk/server/03_module_dev_02/

Thanks u! that is the right way, it works 100%! you are great!

Vicious
on 1/14/14, 7:35 PM

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

0 follower(s)

Stats

Asked: 1/14/14, 5:05 PM
Seen: 1023 times
Last updated: 3/16/15, 8:10 AM