~therp-nl/openobject-server/7.0_lp1321675_crash_on_copy

« back to all changes in this revision

Viewing changes to openerp/osv/orm.py

  • Committer: Ronald Portier
  • Date: 2014-05-21 10:50:17 UTC
  • Revision ID: ronald@therp.nl-20140521105017-pya8lt0feql97ufu
[FIX] Prevents exception when copying record with one2many function field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5066
5066
            old_record, new_record = self.browse(cr, uid, [old_id, new_id], context=context_wo_lang)
5067
5067
            # we must recursively copy the translations for o2o and o2m
5068
5068
            if field_def['type'] == 'one2many':
5069
 
                target_obj = self.pool.get(field_def['relation'])
5070
 
                # here we rely on the order of the ids to match the translations
5071
 
                # as foreseen in copy_data()
5072
 
                old_children = sorted(r.id for r in old_record[field_name])
5073
 
                new_children = sorted(r.id for r in new_record[field_name])
5074
 
                for (old_child, new_child) in zip(old_children, new_children):
5075
 
                    target_obj.copy_translations(cr, uid, old_child, new_child, context=context)
 
5069
                # do not copy function fields, unless they are stored:
 
5070
                if ((not 'function' in field_def)
 
5071
                        or ('store' in field_def and field_def['store'])):
 
5072
                    target_obj = self.pool.get(field_def['relation'])
 
5073
                    # here we rely on the order of the ids to match the
 
5074
                    # translations as foreseen in copy_data()
 
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
5083
            # and for translatable fields we keep them for copy
5077
5084
            elif field_def.get('translate'):
5078
5085
                if field_name in self._columns: