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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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
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 ?
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
4
Jan 20
|
2215 | ||
|
0
Nov 18
|
3406 | ||
|
0
Apr 17
|
2732 | ||
|
3
Oct 22
|
4117 | ||
|
1
Nov 17
|
5887 |
bill_id = fields.Many2one('model.one','Bill Ref')
bill_batch_id = fields.Many2one(related='bill_id.bill_batch_id', string="Batch Ref.")