Merge lp:~unifield-team/unifield-wm/uf-1786 into lp:unifield-wm
- uf-1786
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 1814 |
Proposed branch: | lp:~unifield-team/unifield-wm/uf-1786 |
Merge into: | lp:unifield-wm |
Diff against target: |
236 lines (+142/-4) 4 files modified
msf_audittrail/audittrail.py (+132/-1) msf_audittrail/audittrail_view.xml (+2/-2) msf_audittrail/report/log_line.rml (+1/-1) msf_profile/i18n/fr_MF.po (+7/-0) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-wm/uf-1786 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Dev Team | Pending | ||
Review via email: mp+190936@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'msf_audittrail/audittrail.py' |
2 | --- msf_audittrail/audittrail.py 2013-09-05 15:26:55 +0000 |
3 | +++ msf_audittrail/audittrail.py 2013-10-14 12:23:55 +0000 |
4 | @@ -29,6 +29,7 @@ |
5 | import pooler |
6 | import time |
7 | import tools |
8 | +import logging |
9 | from tools.safe_eval import safe_eval as eval |
10 | import logging |
11 | |
12 | @@ -114,6 +115,63 @@ |
13 | |
14 | account_period() |
15 | |
16 | + |
17 | +class ir_module(osv.osv): |
18 | + _inherit = 'ir.module.module' |
19 | + |
20 | + def update_translations(self, cr, uid, ids, filter_lang=None, context=None): |
21 | + ''' |
22 | + Override the lang install to apply the translation on Track changes ir.actions |
23 | + ''' |
24 | + res = super(ir_module, self).update_translations(cr, uid, ids, filter_lang=None, context=context) |
25 | + |
26 | + msf_profile_id = self.search(cr, uid, [('name', '=', 'msf_profile')], context=context) |
27 | + |
28 | + if not msf_profile_id or msf_profile_id[0] not in ids: |
29 | + return res |
30 | + |
31 | + tr_obj = self.pool.get('ir.translation') |
32 | + act_obj = self.pool.get('ir.actions.act_window') |
33 | + language_obj = self.browse(cr, uid, ids)[0] |
34 | + src = 'Track changes' |
35 | + if not filter_lang: |
36 | + pool = pooler.get_pool(cr.dbname) |
37 | + lang_obj = pool.get('res.lang') |
38 | + lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) |
39 | + filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] |
40 | + elif not isinstance(filter_lang, (list, tuple)): |
41 | + filter_lang = [filter_lang] |
42 | + |
43 | + for lang in filter_lang: |
44 | + trans_ids = tr_obj.search(cr, uid, [('lang', '=', lang), |
45 | + ('xml_id', '=', 'action_audittrail_view_log'), |
46 | + ('module', '=', 'msf_audittrail')], context=context) |
47 | + if trans_ids: |
48 | + logger = logging.getLogger('i18n') |
49 | + logger.info('module msf_profile: loading translation for \'Track changes\' ir.actions.act_window for language %s', lang) |
50 | + trans = tr_obj.browse(cr, uid, trans_ids[0], context=context).value |
51 | + # Search all actions to rename |
52 | + act_ids = act_obj.search(cr, uid, [('name', '=', src)], context=context) |
53 | + for act in act_ids: |
54 | + exist = tr_obj.search(cr, uid, [('lang', '=', lang), |
55 | + ('type', '=', 'model'), |
56 | + ('src', '=', src), |
57 | + ('name', '=', 'ir.actions.act_window,name'), |
58 | + ('value', '=', trans), |
59 | + ('res_id', '=', act)], context=context) |
60 | + if not exist: |
61 | + tr_obj.create(cr, uid, {'lang': lang, |
62 | + 'src': src, |
63 | + 'name': 'ir.actions.act_window,name', |
64 | + 'type': 'model', |
65 | + 'value': trans, |
66 | + 'res_id': act}, context=context) |
67 | + |
68 | + return res |
69 | + |
70 | +ir_module() |
71 | + |
72 | + |
73 | class audittrail_log_sequence(osv.osv): |
74 | _name = 'audittrail.log.sequence' |
75 | _rec_name = 'model' |
76 | @@ -212,13 +270,14 @@ |
77 | self.write(cr, uid, [thisrule.id], {"state": "draft"}) |
78 | search_view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'msf_audittrail', 'view_audittrail_log_line_search') |
79 | val = { |
80 | - "name": 'Track changes', |
81 | + "name": _('Track changes'), |
82 | "res_model": 'audittrail.log.line', |
83 | "src_model": thisrule.object_id.model, |
84 | "search_view_id": search_view_id and search_view_id[1] or False, |
85 | "domain": "[('object_id','=', " + str(thisrule.object_id.id) + "), ('res_id', '=', active_id)]" |
86 | |
87 | } |
88 | + |
89 | action_id = obj_action.create(cr, uid, val) |
90 | self.write(cr, uid, [thisrule.id], {"state": "subscribed", "action_id": action_id}) |
91 | keyword = 'client_action_relate' |
92 | @@ -351,6 +410,77 @@ |
93 | |
94 | return res |
95 | |
96 | + def _get_field_name(self, cr, uid, ids, field_name, arg, context=None): |
97 | + ''' |
98 | + Return the name of the field in the user language |
99 | + ''' |
100 | + tr_obj = self.pool.get('ir.translation') |
101 | + |
102 | + res = {} |
103 | + lang = self.pool.get('res.users').browse(cr, uid, uid, context=context).context_lang |
104 | + |
105 | + for line in self.browse(cr, uid, ids, context=context): |
106 | + res[line.id] = False |
107 | + |
108 | + # Translation of field name |
109 | + if line.field_id: |
110 | + field_name = '%s,%s' % (line.object_id.model, line.field_id.name) |
111 | + tr_ids = tr_obj.search(cr, uid, [('name', '=', field_name), |
112 | + ('lang', '=', lang), |
113 | + ('type', '=', 'field'), |
114 | + ('src', '=', line.field_id.field_description)], context=context) |
115 | + if tr_ids: |
116 | + res[line.id] = tr_obj.browse(cr, uid, tr_ids[0], context=context).value |
117 | + |
118 | + # Translation of one2many object if any |
119 | + if not res[line.id] and line.fct_object_id: |
120 | + field_name = '%s,%s' % (line.fct_object_id.model, line.field_id.name) |
121 | + tr_ids = tr_obj.search(cr, uid, [('name', '=', field_name), |
122 | + ('lang', '=', lang), |
123 | + ('type', '=', 'field'), |
124 | + ('src', '=', line.field_id.field_description)], context=context) |
125 | + if tr_ids: |
126 | + res[line.id] = tr_obj.browse(cr, uid, tr_ids[0], context=context).value |
127 | + |
128 | + # Translation of main object |
129 | + if not res[line.id] and (line.object_id or line.fct_object_id): |
130 | + tr_ids = tr_obj.search(cr, uid, [('name', '=', 'ir.model,name'), |
131 | + ('lang', '=', lang), |
132 | + ('type', '=', 'model'), |
133 | + ('src', '=', line.name)], context=context) |
134 | + if tr_ids: |
135 | + res[line.id] = tr_obj.browse(cr, uid, tr_ids[0], context=context).value |
136 | + |
137 | + # No translation |
138 | + if not res[line.id]: |
139 | + res[line.id] = line.field_description |
140 | + |
141 | + return res |
142 | + |
143 | + def _src_field_name(self, cr, uid, obj, name, args, context=None): |
144 | + ''' |
145 | + Search field description with the user lang |
146 | + ''' |
147 | + tr_obj = self.pool.get('ir.translation') |
148 | + |
149 | + res = [] |
150 | + lang = self.pool.get('res.users').browse(cr, uid, uid, context=context).context_lang |
151 | + |
152 | + for arg in args: |
153 | + if arg[0] == 'trans_field_description': |
154 | + tr_fields = tr_obj.search(cr, uid, [('lang', '=', lang), |
155 | + ('type', 'in', ['field', 'model']), |
156 | + ('value', arg[1], arg[2])], context=context) |
157 | + |
158 | + field_names = [] |
159 | + for f in tr_obj.browse(cr, uid, tr_fields, context=context): |
160 | + field_names.append(f.src) |
161 | + |
162 | + res = [('field_description', 'in', field_names)] |
163 | + |
164 | + return res |
165 | + |
166 | + |
167 | _columns = { |
168 | 'name': fields.char(size=256, string='Description', required=True), |
169 | 'object_id': fields.many2one('ir.model', string='Object'), |
170 | @@ -367,6 +497,7 @@ |
171 | 'old_value': fields.text("Old Value"), |
172 | 'new_value': fields.text("New Value"), |
173 | 'field_description': fields.char('Field Description', size=64), |
174 | + 'trans_field_description': fields.function(_get_field_name, fnct_search=_src_field_name, method=True, type='char', size=64, string='Field Description', store=False), |
175 | 'sub_obj_name': fields.char(size=64, string='Order line'), |
176 | # 'sub_obj_name': fields.function(fnct=_get_name_line, fnct_search=_search_name_line, method=True, type='char', string='Order line', store=False), |
177 | # These 3 fields allows the computation of the name of the subobject (sub_obj_name) |
178 | |
179 | === modified file 'msf_audittrail/audittrail_view.xml' |
180 | --- msf_audittrail/audittrail_view.xml 2012-09-12 14:01:30 +0000 |
181 | +++ msf_audittrail/audittrail_view.xml 2013-10-14 12:23:55 +0000 |
182 | @@ -103,7 +103,7 @@ |
183 | <field name="timestamp" /> |
184 | <newline /> |
185 | <field name="sub_obj_name" /> |
186 | - <field name="field_description" /> |
187 | + <field name="trans_field_description" /> |
188 | <field name="old_value_text" /> |
189 | <field name="new_value_text" /> |
190 | <field name="user_id" /> |
191 | @@ -122,7 +122,7 @@ |
192 | <field name="timestamp" /> |
193 | <field name="sub_obj_name" /> |
194 | <field name="method" /> |
195 | - <field name="field_description" /> |
196 | + <field name="trans_field_description" /> |
197 | <field name="old_value_fct" string="Old value" /> |
198 | <field name="new_value_fct" string="New value" /> |
199 | <!-- <field name="old_value_text" invisible="1" /> |
200 | |
201 | === modified file 'msf_audittrail/report/log_line.rml' |
202 | --- msf_audittrail/report/log_line.rml 2012-03-29 08:15:57 +0000 |
203 | +++ msf_audittrail/report/log_line.rml 2013-10-14 12:23:55 +0000 |
204 | @@ -105,7 +105,7 @@ |
205 | <para style="P4">[[ get_method(line, 'method') ]]</para> |
206 | </td> |
207 | <td> |
208 | - <para style="P4left">[[ line.field_description ]]</para> |
209 | + <para style="P4left">[[ line.trans_field_description ]]</para> |
210 | </td> |
211 | <td> |
212 | <para style="P4">[[ line.old_value_fct ]]</para> |
213 | |
214 | === modified file 'msf_profile/i18n/fr_MF.po' |
215 | --- msf_profile/i18n/fr_MF.po 2013-09-06 08:05:11 +0000 |
216 | +++ msf_profile/i18n/fr_MF.po 2013-10-14 12:23:55 +0000 |
217 | @@ -24521,6 +24521,12 @@ |
218 | msgstr "Message SMS" |
219 | |
220 | #. module: msf_audittrail |
221 | +#: code:addons/msf_audittrail/audittrail.py:214 |
222 | +#, python-format |
223 | +msgid "Track changes" |
224 | +msgstr "Suivi des Modifications" |
225 | + |
226 | +#. module: msf_audittrail |
227 | #: model:ir.actions.act_window,name:msf_audittrail.action_audittrail_view_log |
228 | msgid "Track changes" |
229 | msgstr "Suivi des Modifications" |
230 | @@ -27388,6 +27394,7 @@ |
231 | |
232 | #. module: msf_audittrail |
233 | #: field:audittrail.log.line,field_description:0 |
234 | +#: field:audittrail.log.line,trans_field_description:0 |
235 | msgid "Field Description" |
236 | msgstr "Description du Champ" |
237 |