[FIX] fields: when executing (4, *) operations on o2m fields, check the existence based on the sql model of the table.

If the o2m field linked to the o2m is stored on a different table (eg: inherit), previous request would crash as the field do not exists in the '_table' sql table

bzr revid: mat@openerp.com-20140324162130-fyotk8vqmkha43eb
This commit is contained in:
Martin Trigaux 2014-03-24 17:21:30 +01:00
parent 7b0b8a0790
commit 66d6fb065f
1 changed files with 3 additions and 1 deletions

View File

@ -571,7 +571,9 @@ class one2many(_column):
else:
cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],))
elif act[0] == 4:
cr.execute("select 1 from {0} where id=%s and {1}=%s".format(_table, self._fields_id), (act[1], id))
field_model = obj.pool.get(self._obj)._all_columns[self._fields_id].parent_model
field_table = obj.pool.get(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
obj.write(cr, user, [act[1]], {self._fields_id:id}, context=context or {})