summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index 8b7cbfe71cc..6ad32a505b6 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -2638,9 +2638,13 @@ class Many2one(_Relational):
""" Remove `records` from the cached values of the inverse fields of `self`. """
cache = records.env.cache
record_ids = set(records._ids)
+
+ # align(id) returns a NewId if records are new, a real id otherwise
+ align = (lambda id_: id_) if all(record_ids) else (lambda id_: id_ and NewId(id_))
+
for invf in records._field_inverses[self]:
corecords = records.env[self.comodel_name].browse(
- id_ for id_ in cache.get_values(records, self)
+ align(id_) for id_ in cache.get_values(records, self)
)
for corecord in corecords:
ids0 = cache.get(corecord, invf, None)