But it give me an error saying that record.env doesn't exist. I tried to find answer to this error but none matched with my code.

I looked to dozens of topics, tried all the morning to fix it, but whatever I do, it won't works. (The first thing I did -appear in first class I wrote- didn't gave me any error but changed nothing in the database.)

Thanks for reading and for any help you could provide.

EDIT: I think the only real question here is "How to give an ID as a value for a many2one?" But I'm not sure that this is the only problem here so I let all the text.

When you create an onchange, it seams that it will only change the javascript, if the field you try to modify, thanks to an onchange on an other field, isn't in your tree, it won't be changed. What I figured out, doing some attempt while looking at phppgadmin:

When you change your field, it update the javascript, nothing is done in the database.

Once you saved your change, the javascript seams to analyse the fields and update the database with those.

So when something is not in the xml, you can't use onchange on it. It's a real pain if you want to change something in another model or module. But more of that it was really stupid to try this and it perfectly make sense: the purpose of onchange is to update before any registration is done, the only interest is to show it while your still modify it.

The solution was quite simple thanks to the Odoo 8.0 API. Here is an exemple (This is in res partner):

'my_field': field.many2one(compute='_compute_second_field', store=True, readonly=True)
@api.depends('name_ids.type') //name_ids is the one2many reverse of name's many2one in model1
for record in self:
if self.name_ids://if some names are pointing to this, name_ids is not empty
self.model3_id = 2
else://if doesn't exist, default value
self.model3_id = 0

So when you create in res_partner, this res_partner is still not in model1, take value '0'. Then you add it in model1, take value 2. If you remove him from model1, take value '0' again (removing is still a modification).

for openerp-7 it is 'fields.function' (with type='many2one' as argument and store={('model1':_other_function, ['type'], 10)} but I didn't managed to finish it this way, so I won't show it