Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
9089 มุมมอง

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>



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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')

อวตาร
ละทิ้ง
ผู้เขียน

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.

ผู้เขียน

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

ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 21
3111
3
เม.ย. 21
5949
0
มิ.ย. 20
2923
1
ก.พ. 24
1225
1
มี.ค. 19
3765