From feef39aee083294f8c8d19aecef0434af04c48d0 Mon Sep 17 00:00:00 2001 From: batuto Date: Fri, 21 Jul 2017 15:18:12 -0500 Subject: [PATCH] [IMP] doc: add warning about constrain method trigger It may be confusing that a constraint is not triggered in a name_create call. Testing the absence of value should be done in an override of create, not in a api.constrains. Closes #18382 --- odoo/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/odoo/api.py b/odoo/api.py index 1adbd08f6e5..413a6b8a2a5 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -155,6 +155,14 @@ def constrains(*args): ``@constrains`` only supports simple field names, dotted names (fields of relational fields e.g. ``partner_id.customer``) are not supported and will be ignored + + ``@constrains`` will be triggered only if the declared fields in the + decorated method are included in the ``create`` or ``write`` call. + It implies that fields not present in a view will not trigger a call + during a record creation. A override of ``create`` is necessary to make + sure a constraint will always be triggered (e.g. to test the absence of + value). + """ return attrsetter('_constrains', args)