Merge lp:~openerp-dev/openobject-server/trunk-bug-705364-ysa into lp:openobject-server

Proposed by Yogesh (SerpentCS)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-bug-705364-ysa
Merge into: lp:openobject-server
Diff against target: 56 lines (+28/-11)
1 file modified
openerp/osv/orm.py (+28/-11)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-bug-705364-ysa
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Needs Fixing
Vo Minh Thu Pending
Review via email: mp+64526@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello Yogesh,

You are searching on the ir_translation object with the res_id as the new_id. Which means you will never ever get records here becuase you are searching the records before creating them. i.e for the new id.
Does your the code in the diff from line no 29 to 39 makes sense ?

can you please recheck you commit ?

Note: The issue lp:799655 is also related to translation and a partial fix for the server side is done here.http://bazaar.launchpad.net/~openerp-dev/openobject-server/trunk-bug-799655-nch/revision/3501. Also for this we need to have a way to override copy_translation method in the objects.

Thanks !

review: Needs Fixing

Unmerged revisions

3459. By xrg

[FIX] fix problem of function field type one2many create duplicate translation record in ir.translation.

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 2011-06-10 17:31:30 +0000
3+++ openerp/osv/orm.py 2011-06-14 10:31:19 +0000
4@@ -4361,7 +4361,7 @@
5 trans_obj = self.pool.get('ir.translation')
6 fields = self.fields_get(cr, uid, context=context)
7
8- translation_records = []
9+ translation_names = []
10 for field_name, field_def in fields.items():
11 # we must recursively copy the translations for o2o and o2m
12 if field_def['type'] in ('one2one', 'one2many'):
13@@ -4381,16 +4381,33 @@
14 elif field_name in self._inherit_fields:
15 trans_name = self._inherit_fields[field_name][0] + "," + field_name
16 if trans_name:
17- trans_ids = trans_obj.search(cr, uid, [
18- ('name', '=', trans_name),
19- ('res_id', '=', old_id)
20- ])
21- translation_records.extend(trans_obj.read(cr, uid, trans_ids, context=context))
22-
23- for record in translation_records:
24- del record['id']
25- record['res_id'] = new_id
26- trans_obj.create(cr, uid, record, context=context)
27+ translation_names.append(trans_name)
28+
29+ if translation_names:
30+ # first, find all ids of translations that already exist
31+ trans_exist_ids = trans_obj.search(cr, uid, [
32+ ('name', 'in', translation_names),
33+ ('res_id', '=', new_id)
34+ ])
35+ if trans_exist_ids:
36+ # Remove from the list the names that are already translated
37+ for res in trans_obj.read(cr,uid, trans_exist_ids, ['name'], context=context):
38+ if res['name'] in translation_names:
39+ translation_names.remove(res['name'])
40+
41+ trans_ids = []
42+ if translation_names:
43+ # then, locate the ones that we need to copy
44+ trans_ids = trans_obj.search(cr, uid, [
45+ ('name', 'in', translation_names),
46+ ('res_id', '=', old_id)
47+ ])
48+
49+ if trans_ids:
50+ for record in trans_obj.read(cr, uid, trans_ids, context=context):
51+ del record['id']
52+ record['res_id'] = new_id
53+ trans_obj.create(cr, uid, record, context=context)
54
55
56 def copy(self, cr, uid, id, default=None, context=None):