Merge lp:~unifield-team/unifield-server/us-1567 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4083
Proposed branch: lp:~unifield-team/unifield-server/us-1567
Merge into: lp:unifield-server
Diff against target: 46 lines (+26/-0)
1 file modified
bin/addons/product_attributes/product_attributes.py (+26/-0)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-1567
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+311282@code.launchpad.net

This proposal supersedes a proposal from 2016-11-18.

To post a comment you must log in.
Revision history for this message
jftempo (jfb-tempo-consulting) wrote :

(diff not generated by launchpad ...)

Does not work if default_code contains a comma, please retrieve xmlid_code from ir.model.data only in sync context.

In update_existing_translations, could you test this to prevent the iteration on all fields ?
trans_ids = trans_obj.search(cr, uid, [
                            ('res_id', '=', 0),
                            ('xml_id', '=', xmlid),
                            ('type', '=', 'model'),
                            ('name', '=like', '%s,%%' % (model,)),
                        ], context=context)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/product_attributes/product_attributes.py'
2--- bin/addons/product_attributes/product_attributes.py 2016-09-28 08:24:48 +0000
3+++ bin/addons/product_attributes/product_attributes.py 2016-11-21 14:09:07 +0000
4@@ -1217,10 +1217,26 @@
5 :return: The ID of the new product.template record
6 """
7 sptc_obj = self.pool.get('standard.price.track.changes')
8+ trans_obj = self.pool.get('ir.translation')
9+ data_obj = self.pool.get('ir.model.data')
10
11 if context is None:
12 context = {}
13
14+ def update_existing_translations(model, res_id, xmlid):
15+ # If we are in the creation of product by sync. engine, attach the already existing translations to this product
16+ if context.get('sync_update_execution'):
17+ trans_ids = trans_obj.search(cr, uid, [
18+ ('res_id', '=', 0),
19+ ('xml_id', '=', xmlid),
20+ ('type', '=', 'model'),
21+ ('name', '=like', '%s,%%' % model),
22+ ], context=context)
23+ if trans_ids:
24+ trans_obj.write(cr, uid, trans_ids, {
25+ 'res_id': res_id,
26+ }, context=context)
27+
28 if 'default_code' in vals:
29 vals['default_code'] = vals['default_code'].strip()
30 if not context.get('sync_update_execution') and ' ' in vals['default_code']:
31@@ -1252,6 +1268,16 @@
32 res = super(product_attributes, self).create(cr, uid, vals,
33 context=context)
34
35+ # Update existing translations for product.product and product.template
36+ product_tmpl_id = self.read(cr, uid, [res], ['product_tmpl_id'])[0]['product_tmpl_id'][0]
37+ prd_data_ids = data_obj.search(cr, uid, [
38+ ('res_id', '=', res),
39+ ('model', '=', 'product.product'),
40+ ], context=context)
41+ for prd_data in data_obj.browse(cr, uid, prd_data_ids, context=context):
42+ update_existing_translations('product.product', res, prd_data.name)
43+ update_existing_translations('product.template', product_tmpl_id, prd_data.name)
44+
45 sptc_obj.track_change(cr, uid, res, _('Product creation'), vals,
46 context=context)
47

Subscribers

People subscribed via source and target branches

to all changes: