PseudoWithK
PseudoWithK

Reputation: 321

Many2one fields and options

Here is the declaration of my field:

partner_id = fields.Many2one(string="Child", comodel_name="res.partner")

I would like to know if it is possible to target another field of the table res.partner besides the "name"?

And why not a field that depends on another field?

It is possible to declared options?

Thanks for your help !

EDIT :

I'm trying to understand one thing.

When I export my partner_id field via the Odoo interface, I do not have a value of type res_partner_5096 but the value of another field which is an external identifier. "N0000542145" This is what I need to be able to prepare an import file

On the other hand I have a second field "foyer_id" which exports me something of the style "relation_foyer_6055". I understand that it is the identifier that corresponds to registration of this person. Yet my fields are declared the same way.

partner_id = fields.Many2one(string="Child", comodel_name="res.partner")
foyer_id = fields.Many2one(string="Foyer", comodel_name="horanet.relation.foyer")

I can not understand why this difference when exporting these two fields for the same partner.

An idea ?

Upvotes: 1

Views: 198

Answers (1)

mocak
mocak

Reputation: 405

I think you exactly looking for the "_rec_name" attribute. Odoo models uses a field as record name to display records in context where a representative “naming” is necessary. If you don't set _rec_name, model uses name field as record name by default.

Class HoranetRelationFoyer(models.Model):
    # ...
    _rec_name = 'my_field'

    my_field = fields.Char()

Upvotes: 1

Related Questions