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
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2014-05-19 16:12:41 +0000
3+++ openerp/osv/orm.py 2014-05-21 10:59:15 +0000
4@@ -5066,13 +5066,20 @@
5 old_record, new_record = self.browse(cr, uid, [old_id, new_id], context=context_wo_lang)
6 # we must recursively copy the translations for o2o and o2m
7 if field_def['type'] == 'one2many':
8- target_obj = self.pool.get(field_def['relation'])
9- # here we rely on the order of the ids to match the translations
10- # as foreseen in copy_data()
11- old_children = sorted(r.id for r in old_record[field_name])
12- new_children = sorted(r.id for r in new_record[field_name])
13- for (old_child, new_child) in zip(old_children, new_children):
14- target_obj.copy_translations(cr, uid, old_child, new_child, context=context)
15+ # do not copy function fields, unless they are stored:
16+ if ((not 'function' in field_def)
17+ or ('store' in field_def and field_def['store'])):
18+ target_obj = self.pool.get(field_def['relation'])
19+ # here we rely on the order of the ids to match the
20+ # translations as foreseen in copy_data()
21+ old_children = sorted(
22+ r.id for r in old_record[field_name])
23+ new_children = sorted(
24+ r.id for r in new_record[field_name])
25+ for (old_child, new_child) in zip(
26+ old_children, new_children):
27+ target_obj.copy_translations(
28+ cr, uid, old_child, new_child, context=context)
29 # and for translatable fields we keep them for copy
30 elif field_def.get('translate'):
31 if field_name in self._columns: