Odoo Help


Changing one2many widget to many2many causes error on creation, many2many on 2 models seems to not relate them (all web UI)

Roberto Cocchiararo
on 11/16/14, 6:16 PM 1,235 views


First of all, I would like to clarify that I am working with the web interface and not "programing" an instalable module, since I know programing basics, but no python.

My objective is to add functionality to the fleet management module.
I created 2 additional models, "events" and "fleet insurance" (the built in contracts can be used for other objectives, but the actual insurance is managed differently, only 2 companies are used and this allows keeping the vehicles up to date easier).

One is for listing events (name, date, description). Each event can have "x" number of vehicles participating (each vehicle can participate in any number of events, and this is a log).

The other is for registering insurance contracts (number, expiration and company). Each contract can have "y" vehicles associated (but one vehicle can have only 1 fleet insurance contract active).

I then need to extend the fleet.vehicle model, adding a list of all the events where it has participated, and the information of the current insurance contract (it can have only one).

My issues start here.

I first tried using many2many fields. This allowed me to pick vehicles in the events/fleet insurance, or events/fleet insurance from the vehicle form, but changing one entity has no effect on the other.

I then tried with one2many in the vehicles, many2one in events/fleet insurance. Now I could pick correctly from the vehicles, but could only have one on the other models (and it was a selection showing just one field, not all the info). Also, from the events/fleet insurance, the "add new" opened the vehicle creatin form, instead of listing the existing ones.

Finally I went with many2one in vehicles, one2many on the other side. This time the problem was inverted.
Then u tried setting the widget on both ends to "many2many", which seemed to be the answer. Too bad now I can't create new vehicles or events/fleet insurance because I get an " unhashable: list" error.

I tries also having many2many on one end, one2many on the other. Similar error when creating.

Can you helpe fix my issue or instruct on the correct way of achieving my objective, using only the web interface of course?

The XML code i ended up with (with some variations, like read only for the fleet insurance on the vehicle form view) was:

Fleet insurance form view:
<?xml version="1.0"?>
<group string="Seguro">
<field name="x_compania"/>
<field name="x_numeropoliza"/>
<field name="x_fechavencimiento"/>
<group string="Asegurados">
<field name="x_vehiculos" nolabel="1" widget="many2many"/>

Events form view:
<?xml version="1.0"?>
<group string="Evento">
<field name="x_nombreevento"/>
<field name="x_fechaevento"/>
<group string="Descripción">
<field nolabel="1" name="x_descripcion" placeholder="Escriba aquí información del evento"/>
<group string="Participantes">
<field name="x_vehiculos" nolabel="1" widget="many2many"/>

Vehicle form view addition (i tried with and without notebook, but with notebook it looked better):

<page string="Seguro de Flota" attrs="{'invisible': [('x_aseguradoflota','=',False)]}">
<field name="x_seguroflota" nolabel="1" widget="many2many" readonly="1"/>
<page string="Eventos" attrs="{'invisible': [('model_id','=',False)]}">
<field name="x_eventos" nolabel="1" widget="many2many"/>


Roberto Cocchiararo
On 11/17/14, 1:07 PM

I have been doing more experiments, and i believe now that what i tried was not supported, and that is the reason it failed in the first place :P

In any case, now i have:

Events (one2many) > Vehicles (many2many)

Fleet insurance (one2many) > Vehicles (many2one)

Doing it this way, i can have every vehicle participate in any number of events, and modifying one list, does the same on the other. Only downside is i had to change the form view for the events so that the vehicle list is "readonly", because the "one2many" list widget tries to create a new vehicle instead of picking existing ones.

At the same time, each vehicle can have only one fleet insurance active at any moment, which is good. My only issue is that since i am using just the web interface, and these are all custom models/fields, it seems like only "luck" decides what field is displayed in "vehicles" for the "many2one" field relating to "fleet insurance". This time, it was the policy number (more or less usefull), but i had another case where the "user that created the record" was displayed, which was not good at all.

Can i manage this in any way when i am not defining the model/field in python code? If i where, i could set the "_rec_name" of each custom "many2one" field i needed to display the 2 or 3 fields from the "fleet insurance" model in the "vehicle" form view.




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

1 follower(s)


Asked: 11/16/14, 6:16 PM
Seen: 1235 times
Last updated: 3/16/15, 8:10 AM