Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
9392 Vistas

I want to use a Many2one field that relates n cases with 1 investigator:

assigned_investigator = fields.Many2one('ufodata.investigator', string='Assigned Investigator')

From investigator, I want to specify a field "user_name" as related field of the many2one relation:

assigned_investigator = fields.Many2one('ufodata.investigator', string='Assigned Investigator', related='???')

In the Investigator model, the field is defined as user_name = fields.Char()
Now I'm missing the correct notation to specify the related field:

related='ufodata.investigator.user_name' --> KeyError: 'ufodata'
related='investigator.user_name' --> KeyError: 'investigator'
related='Investigator.user_name' --> KeyError: 'Investigator'
related='user_name' --> KeyError: 'user_name'
related='ufodata.investigator_id.user_name' --> KeyError: 'ufodata'
related='investigator_id.user_name' --> KeyError: 'investigator_id'

do all not work. What I am doing wrong?

Avatar
Descartar

bill_id = fields.Many2one('model.one','Bill Ref')

bill_batch_id = fields.Many2one(related='bill_id.bill_batch_id', string="Batch Ref.")

Autor Mejor respuesta

To make my problem more clear: I've got a Many2one field from (many) cases to (one) investigator. This field is a link to the assigned investigator dataset, but the text of the link is not any value of the dataset, but "ufodata.investigator,1", i.e. the type combined with an id (can't add screenshots here). Of course, I do not want this, but the name of the investigator. I can help myself with adding a related field that extracts one the investigator's values (user_name), but then I've got only a label, not a link (or combo box in edit mode). I want to have the link, but with a value representing the linked dataset.

Edit: question has been answered here: https://www.odoo.com/de_DE/forum/hilfe-1/question/representation-of-many2one-in-view-163488

Avatar
Descartar
Mejor respuesta

The example is a bit confusing. The name of the second field (assigned_investigator) in your example is the same as the first field (assigned_investigator). Shouldnt the second field be called assigned_investigator_name or something similar ?

Avatar
Descartar
Autor

Yes, it's confusing, sorry! It was meant only as two versions of the same line of code, without and with the "related" parameter. Without the parameter, the Many2One field is represented in the view by a "<type>,<id>" tuple, e.g. "ufodata.investigator,1". Now I want the investigator's name instead of this tuple, and as I understand it, this should be achieved by applying the "related" parameter.

You will need to define 2 fields - a Many2one for the id (for example investigator_id) and the other for the name (for example investigator_name). investigator_name will have to be declared with a related=investigator_id.user_name

Publicaciones relacionadas Respuestas Vistas Actividad
4
ene 20
3204
0
nov 18
4439
0
abr 17
3661
1
ene 25
1890
3
oct 22
5908