This question has been flagged
1 Reply
3873 Views

Hi

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"?>
<form>
<group string="Seguro">
<field name="x_compania"/>
<field name="x_numeropoliza"/>
<field name="x_fechavencimiento"/>
</group>
<group string="Asegurados">
<field name="x_vehiculos" nolabel="1" widget="many2many"/>
</group>
</form>

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

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

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

 

Avatar
Discard
Author Best Answer

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.

 

 

 

Avatar
Discard