summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odoo/fields.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index b96c9fe64f8..fc1a225ef34 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -823,11 +823,15 @@ class Field(MetaField('DummyField', (object,), {})):
# the column is new or it becomes required; initialize its values
if model._table_has_rows():
model._init_column(self.name)
+
+ if self.required and not has_notnull:
+ # _init_column may delay computations in post-init phase
+ @model.pool.post_init
+ def add_not_null():
# flush values before adding NOT NULL constraint
model.flush([self.name])
+ model.pool.post_constraint(sql.set_not_null, model._cr, model._table, self.name)
- if self.required and not has_notnull:
- model.pool.post_constraint(sql.set_not_null, model._cr, model._table, self.name)
elif not self.required and has_notnull:
sql.drop_not_null(model._cr, model._table, self.name)