1

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.

0

1 Answer 1

3

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.