top of page

onChange method in the one2Many field

  • Writer: Tek Siong, Hock
    Tek Siong, Hock
  • Jun 23, 2022
  • 1 min read

If you are doing something in the onChange method in the one2Many field, eg, in the order_line in the sales.order, if you want to update additional info to the description ('name' field) upon adding of the product.

There will be a problem to get the parent ID. For example


a) You will not be able to get the id of the parent sale.order with self._origin.id.


b) Use the Context to pass the id of the parent.

<field name="myone2manyfields_ids" context="{'active_id': id}"> 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          order = self.env['sales.order'].search([('id', '=', self.env.context.get('active_id'))], limit=1)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

Recent Posts

See All

Comentários


Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page