Merge lp:~therp-nl/openobject-server/7.0_lp1321675_crash_on_copy into lp:openobject-server/7.0

Proposed by Ronald Portier (Therp)
Status: Needs review
Proposed branch: lp:~therp-nl/openobject-server/7.0_lp1321675_crash_on_copy
Merge into: lp:openobject-server/7.0
Diff against target: 31 lines (+14/-7)
1 file modified
openerp/osv/orm.py (+14/-7)
To merge this branch: bzr merge lp:~therp-nl/openobject-server/7.0_lp1321675_crash_on_copy
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+220430@code.launchpad.net

Description of the change

Fixes lp1321675.

Prevent crash when copying record with (not stored) one2many function field.

To post a comment you must log in.

Unmerged revisions

5307. By Ronald Portier (Therp)

[FIX] Prevents exception when copying record with one2many function field.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2014-05-19 16:12:41 +0000
+++ openerp/osv/orm.py 2014-05-21 10:59:15 +0000
@@ -5066,13 +5066,20 @@
5066 old_record, new_record = self.browse(cr, uid, [old_id, new_id], context=context_wo_lang)5066 old_record, new_record = self.browse(cr, uid, [old_id, new_id], context=context_wo_lang)
5067 # we must recursively copy the translations for o2o and o2m5067 # we must recursively copy the translations for o2o and o2m
5068 if field_def['type'] == 'one2many':5068 if field_def['type'] == 'one2many':
5069 target_obj = self.pool.get(field_def['relation'])5069 # do not copy function fields, unless they are stored:
5070 # here we rely on the order of the ids to match the translations5070 if ((not 'function' in field_def)
5071 # as foreseen in copy_data()5071 or ('store' in field_def and field_def['store'])):
5072 old_children = sorted(r.id for r in old_record[field_name])5072 target_obj = self.pool.get(field_def['relation'])
5073 new_children = sorted(r.id for r in new_record[field_name])5073 # here we rely on the order of the ids to match the
5074 for (old_child, new_child) in zip(old_children, new_children):5074 # translations as foreseen in copy_data()
5075 target_obj.copy_translations(cr, uid, old_child, new_child, context=context)5075 old_children = sorted(
5076 r.id for r in old_record[field_name])
5077 new_children = sorted(
5078 r.id for r in new_record[field_name])
5079 for (old_child, new_child) in zip(
5080 old_children, new_children):
5081 target_obj.copy_translations(
5082 cr, uid, old_child, new_child, context=context)
5076 # and for translatable fields we keep them for copy5083 # and for translatable fields we keep them for copy
5077 elif field_def.get('translate'):5084 elif field_def.get('translate'):
5078 if field_name in self._columns:5085 if field_name in self._columns: