[FIX] fields: in `one2many.set`, replace incorrect query by ORM access
When linking a record into a `one2many` relation with command `(4, rid)`, a query checks whether the record is already linked to the current record id: SELECT 1 FROM {inv_table} WHERE id={rid} AND {inv_field}={id} where `inv_field` is the name of the inverse field, and `inv_table` is the table where this field is stored. The query is wrong if the inverse field is inherited, because the `rid` does not belong to the table `inv_table`. The test has been replaced by a plain ORM access: rec = obj.browse(cr, SUPERUSER_ID, rid) if int(rec[inv_field]) != id: ... This fixes #4685.
This commit is contained in:
parent
b89b7e0554
commit
085875619f
|
@ -823,12 +823,9 @@ class one2many(_column):
|
||||||
else:
|
else:
|
||||||
cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],))
|
cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],))
|
||||||
elif act[0] == 4:
|
elif act[0] == 4:
|
||||||
# table of the field (parent_model in case of inherit)
|
# check whether the given record is already linked
|
||||||
field = obj.pool[self._obj]._fields[self._fields_id]
|
rec = obj.browse(cr, SUPERUSER_ID, act[1], {'prefetch_fields': False})
|
||||||
field_model = field.base_field.model_name
|
if int(rec[self._fields_id]) != id:
|
||||||
field_table = obj.pool[field_model]._table
|
|
||||||
cr.execute("select 1 from {0} where id=%s and {1}=%s".format(field_table, self._fields_id), (act[1], id))
|
|
||||||
if not cr.fetchone():
|
|
||||||
# Must use write() to recompute parent_store structure if needed and check access rules
|
# 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 {})
|
obj.write(cr, user, [act[1]], {self._fields_id:id}, context=context or {})
|
||||||
elif act[0] == 5:
|
elif act[0] == 5:
|
||||||
|
|
Loading…
Reference in New Issue