Odoo Help


How to execute constraints validations in one2many field when it is being saved, not when the parent is saved?

Alexei R. Acosta
on 8/21/13, 12:22 PM 2,405 views

I have an object with some _sql_constraints and _constraints. This object is a column of a "parent" object, an one2many field in parent class. I need to execute those constraints and _sql_constraints validations when I save the "child" object, not at the moment of saving parent object. Please any help will be welcome, I need a solution as soon as posible....thanks in advanced!!

pd: Sorry my English.


IT Libertas

--IT Libertas--
| 4 3 7
Saint Petersburg, Russian Federation
--IT Libertas--

Visit us: itlibertas.com

IT Libertas is a team of developers and automation experts to help you to unlock Odoo ERP system's potential. We have been communicating with end users to whom the software became a main business tool since 2012. As a result, we are proud of dozens of successful implementations.

IT Libertas guarantees deadlines predictability and transparent pricing. We rely upon the best international practices and invest in local markets' study. That is why the company's services are in demand of European, Asian, American and African entrepreneurs.

We are open for cooperation and keep searching for new solutions to the end that IT Libertas clients go ahead of the curve, deal with less routine and generate more profit.

IT Libertas
On 5/14/17, 6:48 AM


the point is that child object is not saved until parent is saved. In order to achieve desired behaviour, you might:

1. Instead of constraints, introduce a check as onchange in validated fields. E.g.

from openerp import exceptions
def _onchange_field_1(self):
    for object in self:
        if object.field_1 > object.field_2:
             raise exceptions.Warning('NOT GOOD!')

Have a look for a similar example in the 'sale' module, when a partner is changed.

2. Force save of a parent object, when child is saved. It ontradicts Odoo logic! But in the onchange you may add some 'write' function, which launch check of constraints.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 8/21/13, 12:22 PM
Seen: 2405 times
Last updated: 5/14/17, 6:48 AM