1
votes

Odoo - multiple Many2one fields that point to the same model

1.I would like to know how I can do to obtain two Many2one fields from the same class, Actually I've only been able to get a many2one field.

In model A I have two fields

cod_modA = fields.Char()
descr_modA = fields.Char()

I want that from the model B I can obtain two Many2one fields:

rel_cod_modB = fields.Many2one ('cod_modA')   
rel_descr_modB = fields.Many2one ('descr_modA')

The purpose of this is to be able to select the register according to cod_modA or according to descr_modA

currently this is:

rel_cod_modB = fields.Many2one('cod_modA')
rel_descr_modB = fields.Text(related='rel_cod_modB.descrmodA ')

2.If I select the field Many2one rel_cod_modB, the field rel_desr_modB is autocomplete.

and if I select the field Many2one rel_descr_modB, the field rel_cod_modB will autoplete

Similar to what happens with related.

1
what!!!!!!!!!!!!Charif DZ

1 Answers

3
votes

Try this code :

Model A:

model_A1 = fields.Char()
model_desc = fields.Char()

Model B:

model_A1_child = fields.Many2one('modelA')
model_A1_desc = fields.Char(related='model_A1_child.model_desc')