Skip to Content
Menu
This question has been flagged
2 Replies
5627 Views

Hi,

in the child (sale.order.line) class I have a boolean field which should be updated when parent field is changed.

Parent:

class SaleOrder(models.Model):
    _inherit = "sale.order"

    sub = fields.Many2One(...)

Child:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"

    b = fields.Boolean(compute="_check_sub", default=False)

    @api.depends("order_id.sub")
    def _check_sub(self):
        for rec in self:
            if(rec.order_id.sub != False):
                rec.b = True


_check_sub is never called. What is the right way to update a child field depending on a parent field?

Thanks!



Avatar
Discard
Author

I resolved this by adding an onchange-method in the parent model and change the child field in there.

Best Answer

One way is to have a sub field also in order.line and have it related to the sale.order sub field and replace your function with on change so...

class SaleOrderLine(models.Model):
...
    sub = fields.Many2one(..., related='order_id.sub', store=False)

    @api.multi
    @api.onchange('sub')​
    def _check_sub(self):​
     ​...            ​
Avatar
Discard
Author Best Answer

Thanks for your reply!

The onchange-method "_check_sub()" is not called.. It is the same problem as before.. 

I change a parent field and the child-methods are not invoked.


Avatar
Discard