Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2775 Vistas

Hi,


I have a One2many in a model, and a Many2one as an inverse. I'm noticing however that the Many2one is only filled once the One2many is saved.

The reason why this is an issue is because I want to use this Many2one in another One2many inside that child model, but I dont want to create child 1 first before having to create child 2.


So summarised:

Model 1 has a One2many of Model 2

Model 2 then has a One2many of Model 3 (and Many2one of Model 1)

Model 3 has a Many2one which has a domain, that relies on a (related) value up to Model 1. So Many2one(Model 1, related='Model 2.Model 1')

Hope this makes sense.

Avatar
Descartar
Autor

Ok, so as an addition to this: I sort of understand why it's going wrong, but still don't know how to fix it.
I believe it's because the original record of model 1 goes into a sort of edit-state. Which means that the many2one of model 2 only knows the edit-state version of model 1 and not the origin. I can however select the original record of model 1, after which I can do the rest (i.e. the domain is filled correctly).
So question becomes: how do I make sure the original record of model 1 is filled in the many2one in model 2?

Mejor respuesta

It sounds like you want to be able to access the fields of Model 1 from Model 3 through Model 2. To do this, you can use Odoo's relational fields.

For example, if you want to access the "name" field of Model 1 from Model 3, you can add a field to Model 3 like this:

name = fields.Char(related="model_2_id.model_1_id.name")

This will allow you to access the "name" field of Model 1 from Model 3 using the "name" field of Model 3. You can use this same technique to access any fields in Model 1 from Model 3, as long as they are accessible through the relationship between Model 2 and Model 1.

If you want to use this field in a domain filter, you can use the "name" field in the domain like this:

[('name', '=', 'some value')]

This will filter the records in Model 3 based on the value of the "name" field in Model 1.

I hope this helps! Let me know if you have any other questions.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
sept 23
1914
1
may 23
3573
2
may 23
3324
1
mar 23
2324
0
dic 22
2946