This question has been flagged

Hi everybody,

I'm stuck in catch onchange event of o2m field (order_line). The first time I add a record, it work fine. But when I add the second row the onchange does not work (the Amount_Total is not updated). I dont know how to fix it.

Pls Help me out :((

Thank all.

Here is my code:


@api.onchange('order_line')
def _onchange_add_product(self):
      for lines in self.order_line:
            if lines.price_unit > 1:
                  vals_tool.append((0, 0, {'product_id': line.product_id.id, ......}))
     self.update({
           'order_line': vals_tool,
})
Avatar
Discard
Author Best Answer

The problem happens when I added a product which had sub-product in it (the super product is a Combo), after that I add one more line and the onchange didn't work. The evidence is the amount_total isn't updated. I'm not good at explaining. Sorry about that.

Avatar
Discard
Best Answer

I think Onchange working properly but the problem is your appending and updating only one line at a time

vals_tool  this not a global variable , so always it have a values of last line, if the price unit is less than 1 then it will through an error " vals_tool Global variable is not defined".

Avatar
Discard