Skip to Content
Menu
This question has been flagged

I want to select configuration_template_ids which has also app_configuration_ids (configuration_template_ids. app_configuration_ids) and how can I pass all selected configuration_template_ids. app_configuration_ids into the field  <field name="app_configuration_ids" />

The list of app_configuration_ids should dynamically add all configuration_template_ids. app_configuration_ids or remove when deselect it.

<page string="App Configs"> 
        <field name="configuration_template_ids" string="Choose Template" widget="many2many_tags" options="{'no_create_edit': True}"  />

  <field name="app_configuration_ids" />

</page>



Avatar
Discard
Best Answer

You need to define app_configuration_ids in your model as a computed field which will get the union of those configuration_template_ids. then you can display it in your view.

app_configuration_ids = fields.Many2many('<app_configuration_model>', compute='get_app_configurations')

@api.depends('configuration_template_ids')
@api.one
def get_app_configurations(self)
    self.app_configuration_ids = self.configuration_template_ids.mapped('app_configuration_ids')

Avatar
Discard
Author

thanks for your answer.

Unfortunately it does not work.

app_configuration_ids is one2many.

If I use compute I cannot edit app_configuration_ids anymore.

Then you just need to remove the compute parameter and change the decorator to @api.onchange.

Though I'm not sure you will declare it as a one2many field. many2many seems for me the better option.

Author

app_configuration_ids = fields.One2many('ia.app.property', inverse_name='product_id', string='App Configs')

app_configuration_template_ids = fields.One2many('ia.app.configuration.template', store=False)

@api.onchange('app_configuration_template_ids')

def get_app_configurations(self): self.app_configuration_ids=self.app_configuration_template_ids.app_property_ids

I have change to onchange, but the method get_app_configurations will not trigger. Do u know why?

It probably does trigger but since you have a One2many field you need to use the special syntax to update it:

self.write({'app_configuration_ids': [(6, 0, self.app_configuration_template_ids.app_property_ids.ids)]})

There is also a neat solution where you can instead declare the product_id as a related field in your 'ia.app.property' model:

product_id = fields.Many2one('product.product', related='app_configuration_template_id.product_id', store=True)

I haven't tried it but I think it will also work

Author

the problem is that I don't want to store it. just have the ids -> store= False

Related Posts Replies Views Activity
1
Sep 21
2115
3
Apr 21
4777
0
Jun 20
1944
1
Feb 24
380
1
Mar 19
3009