Odoo Help


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.


How to retrieve the value of a many2many field for each sale order?

James Ford
on 8/21/16, 3:36 PM 129 views

Hi guys!

I've created a many2many field in the sale.order model that it's related with fleet.vehicle model (id).

How it's showed in the follow image:

IMAGE 1: http://es.zimagez.com/zimage/defm2m.php

Well, the 'x_vehiculo' field is a multi-selection fieldHow it's showed in the follow image:

IMAGE 2: http://es.zimagez.com/zimage/m2mmulti.php

The idea is that for each sale order i can to store more that 1 vehicle.

The trouble is that i can't see the value for of x_vehiculo' field for each sale order when i make a query in the SGB Postgresql (PgAdmin III).

IMAGE 3: http://es.zimagez.com/zimage/salida2.php

There is any way to can retrieve values of 'x_vehicle' multi-selection field for each sale.order?

Please if somebody could help me. I'd be very gratefull.

Thanks you so much


Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
| 5 3 5
--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 8/22/16, 3:02 AM


In your case the values of the records will be stored in the : x_fleet_vehicle_sale_order_rel. so you can query this table to get the result or make a JOIN to this table to get the data you want.

Also if you have a recordset [browse record] you can access these records directly as:

sale_object.x_vehiculo; this will return a recordset of the vehicles in the relation ...

Hope this could helps



| 4 3 5
Hyderabad, India

On 8/22/16, 1:50 AM

James, many2many records are stored in a seperate table..

While creating many2many field, if u remember the structure,

x_vehiculo = fields.many2many('fleet.vehicle', '<NEW_TABLE>', 'sale_id', 'vehicle_id', '<STRING>')

your structure must be something like this.....

here, <New Table> is the table on which u can query to get records and sale_id is id for sale.order and vehicle_id is for fleet.vehicle, like:
"select vehicle_id from <NEW_TABLE> where sale_id = <ID>";

hope it help!!!

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)


Asked: 8/21/16, 3:36 PM
Seen: 129 times
Last updated: 8/22/16, 3:02 AM