Hello Community,
I am writing some code that changes the value of a field in all the lines of a sales order. So if a user changed the category_id in one sale order line, other lines should be change this categ_id as well.
But for some reason this is not working. The values on other lines are not updated and stay the same like nothing happened.
class SaleOrderLine(models.Model):
_inherit="sale.order.line"
@api.onchange('categ_id')
def _onchange_categ_id(self):
for changed_line in self:
#find all lines of the parent sale_order
all_lines = changed_line.order_id.order_line
vals = {'categ_id': changed_line.categ_id}
for line in all_lines:
line.update(vals)
return {}
-> update to give more clarification on what the reason behind this code is.
The reason for this that, in the bigger picture, is that I can create groups of sale order lines, separated by line_sections. Each group of lines has the same categ_id, so if the categ_id of a section changes, all the lines in this section should change to the categ_id as well.
All the help is welcome.
Greetings,
In that case I think it's not possible,
In the ORM API documentation,
It is not possible for a one2many or many2many field to modify itself via onchange. This is a webclient limitation - see #2693.
https://www.odoo.com/documentation/13.0/reference/orm.html
https://github.com/odoo/odoo/issues/2693
I think you're right. That is a pity, I will have to look for an other solution.
can you change your remark to an answer so we can set that as the right answer? Thanks again for the help.