Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to deal with cascading write?

Mathieu Laflamme
on 8/3/15, 6:10 PM 423 views

I did some code to update the child partner records automatically upon modification of a field, stock_owner_id. I overwrote the "write" function to achieve that.

    def write(self, vals):
        """ This will overwrite children stock owner to the same as the current one.
        soid = vals.get('stock_owner_id')
        if soid is not None:
            children = self.search([('parent_id', 'child_of', self.ids)])
            if children:
                children.write({'stock_owner_id': soid})
        result = super(Partner, self).write(vals)
        return result
The problem is that the "write" function is triggered for each child write and that trigger other useless queries on the database.

Any suggestion to prevent that behaviour and still update all my children in bulk?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 8/3/15, 6:10 PM
Seen: 423 times
Last updated: 8/3/15, 6:10 PM