From 0be3333f9617b2be86369bc0a21fcf8097ffe393 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 6 Dec 2013 13:54:03 +0100 Subject: [PATCH] [FIX] orm: ignore existing link for operation (4, x) in one2many fields bzr revid: mat@openerp.com-20131206125403-r6uemlh7jagw01gh --- openerp/osv/fields.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index d2f9789c776..c7771bd0327 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -570,8 +570,10 @@ class one2many(_column): else: cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],)) elif act[0] == 4: - # Must use write() to recompute parent_store structure if needed - obj.write(cr, user, [act[1]], {self._fields_id:id}, context=context or {}) + cr.execute("select 1 from {0} where id=%s and {1}!=%s".format(_table, self._fields_id), (act[1], id)) + if cr.fetchone(): + # Must use write() to recompute parent_store structure if needed and check access rules + obj.write(cr, user, [act[1]], {self._fields_id:id}, context=context or {}) elif act[0] == 5: reverse_rel = obj._all_columns.get(self._fields_id) assert reverse_rel, 'Trying to unlink the content of a o2m but the pointed model does not have a m2o'