0
votes

I have a One2many field that depends on the value of a Many2one field in the form. The related model for the One2many field depends upon the value of the Many2one field.

i_name = fields.Many2one('mod.items',string="Item")
i_fields = fields.One2many('mod.x_fields','field_name',string="Item Characteristics")

Here, the 'mod.x_fields' (model name) should vary according to the i_name field value. Is it possible to make such a field? Can this be done using api.onchange?

2

2 Answers

0
votes

Yes you can put @api.onchange in mod.x_fields model and update your field according to your parent model access like self.field_name.i_name

0
votes

This is how i had to do it. I had to use reference field for i_name and give the model names as selection options. As given here.Though this answer is different from what i wanted(the question), this is the nearest i got.

i_name = fields.Reference(selection='_referencable_models',string='Item')

 @api.model
 def _referencable_models(self):
     return [('mod.item1_fields', 'Item 1'),('mod.item2_fields','Item 2'),...]