Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
9454 Zobrazení

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
Zrušit

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

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

Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
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

Related Posts Odpovědi Zobrazení Aktivita
4
led 20
3260
0
lis 18
4489
0
dub 17
3731
1
led 25
1994
3
říj 22
5988