Merge lp:~openerp-dev/openobject-server/trunk-improve-translation into lp:openobject-server

Proposed by Vidhin Mehta (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/trunk-improve-translation
Merge into: lp:openobject-server
Diff against target: 258 lines (+88/-14)
7 files modified
openerp/addons/base/module/wizard/base_language_install.py (+6/-0)
openerp/addons/base/module/wizard/base_language_install_view.xml (+1/-1)
openerp/addons/base/res/res_lang.py (+50/-4)
openerp/addons/base/res/res_lang_view.xml (+5/-1)
openerp/addons/base/res/res_users.py (+6/-1)
openerp/osv/orm.py (+16/-7)
openerp/service/db.py (+4/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-improve-translation
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+205294@code.launchpad.net
To post a comment you must log in.
5055. By Vidhin Mehta (OpenERP)

[MERGE]Trunk.

5056. By Chirag Dodiya(OpenERP)

[MRG]Merge with trunk

5057. By Vidhin Mehta (OpenERP)

[MERGE]Trunk

5058. By Vidhin Mehta (OpenERP)

[MERGE]Trunk.

5059. By Vidhin Mehta (OpenERP)

[MERGE]cod's branch with improvement

5060. By Vidhin Mehta (OpenERP)

[IMP]Change type.

5061. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

5062. By Chirag Dodiya(OpenERP)

[IMP]Improved warning message when deactive launguage and also improved typo for diactive button

5063. By Chirag Dodiya(OpenERP)

[IMP]Improved code when user try to diactive his preferred lang a warning message will popup

5064. By Chirag Dodiya(OpenERP)

[IMP]Improved warning message when user try to deactive language

5065. By Chirag Dodiya(OpenERP)

[IMP]Improved code as par coding convention and renamed method name for active deactive language.

5066. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

5067. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

Unmerged revisions

5067. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

5066. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

5065. By Chirag Dodiya(OpenERP)

[IMP]Improved code as par coding convention and renamed method name for active deactive language.

5064. By Chirag Dodiya(OpenERP)

[IMP]Improved warning message when user try to deactive language

5063. By Chirag Dodiya(OpenERP)

[IMP]Improved code when user try to diactive his preferred lang a warning message will popup

5062. By Chirag Dodiya(OpenERP)

[IMP]Improved warning message when deactive launguage and also improved typo for diactive button

5061. By Chirag Dodiya(OpenERP)

[MRG]Merged with lp:openobject-server

5060. By Vidhin Mehta (OpenERP)

[IMP]Change type.

5059. By Vidhin Mehta (OpenERP)

[MERGE]cod's branch with improvement

5058. By Vidhin Mehta (OpenERP)

[MERGE]Trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/addons/base/module/wizard/base_language_install.py'
--- openerp/addons/base/module/wizard/base_language_install.py 2012-12-10 15:27:23 +0000
+++ openerp/addons/base/module/wizard/base_language_install.py 2014-05-02 09:19:21 +0000
@@ -49,6 +49,7 @@
49 context = {'overwrite': True}49 context = {'overwrite': True}
50 modobj.update_translations(cr, uid, mids, lang, context or {})50 modobj.update_translations(cr, uid, mids, lang, context or {})
51 self.write(cr, uid, ids, {'state': 'done'}, context=context)51 self.write(cr, uid, ids, {'state': 'done'}, context=context)
52 self.pool.get('res.users').write(cr, uid, uid, {'lang': lang})
52 return {53 return {
53 'name': _('Language Pack'),54 'name': _('Language Pack'),
54 'view_type': 'form',55 'view_type': 'form',
@@ -61,5 +62,10 @@
61 'target': 'new',62 'target': 'new',
62 'res_id': ids and ids[0] or False,63 'res_id': ids and ids[0] or False,
63 }64 }
65 def reload_lang(self, cr, uid, ids, context=None):
66 return {
67 'type': 'ir.actions.client',
68 'tag': 'reload',
69 }
6470
65# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:71# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
6672
=== modified file 'openerp/addons/base/module/wizard/base_language_install_view.xml'
--- openerp/addons/base/module/wizard/base_language_install_view.xml 2012-08-17 07:25:55 +0000
+++ openerp/addons/base/module/wizard/base_language_install_view.xml 2014-05-02 09:19:21 +0000
@@ -21,7 +21,7 @@
21 <button special="cancel" string="Cancel" class="oe_link"/>21 <button special="cancel" string="Cancel" class="oe_link"/>
22 </footer>22 </footer>
23 <footer states="done">23 <footer states="done">
24 <button special="cancel" string="Close"/>24 <button name="reload_lang" type="object" string="Close"/>
25 </footer>25 </footer>
26 </form>26 </form>
27 </field>27 </field>
2828
=== modified file 'openerp/addons/base/res/res_lang.py'
--- openerp/addons/base/res/res_lang.py 2013-12-03 21:19:03 +0000
+++ openerp/addons/base/res/res_lang.py 2014-05-02 09:19:21 +0000
@@ -79,7 +79,6 @@
79 if not lang_name:79 if not lang_name:
80 lang_name = tools.ALL_LANGUAGES.get(lang, lang)80 lang_name = tools.ALL_LANGUAGES.get(lang, lang)
8181
82
83 def fix_xa0(s):82 def fix_xa0(s):
84 """Fix badly-encoded non-breaking space Unicode character from locale.localeconv(),83 """Fix badly-encoded non-breaking space Unicode character from locale.localeconv(),
85 coercing to utf-8, as some platform seem to output localeconv() in their system84 coercing to utf-8, as some platform seem to output localeconv() in their system
@@ -122,12 +121,25 @@
122 or (lang.date_format and pattern in lang.date_format):121 or (lang.date_format and pattern in lang.date_format):
123 return False122 return False
124 return True123 return True
124
125 def _check_active_lang(self, cr, uid, ids, context=None):
126 lang_ids = self.search(cr, uid, [('active', '=', True)])
127 if len(lang_ids) < 1:
128 return False
129 return True
125130
126 def _get_default_date_format(self, cursor, user, context=None):131 def _get_default_date_format(self, cursor, user, context=None):
127 return '%m/%d/%Y'132 return '%m/%d/%Y'
128133
129 def _get_default_time_format(self, cursor, user, context=None):134 def _get_default_time_format(self, cursor, user, context=None):
130 return '%H:%M:%S'135 return '%H:%M:%S'
136
137 def _no_of_user(self, cr, uid, ids, name, args, context=None):
138 res = {}
139 for lang in self.browse(cr, uid, ids, context=context):
140 user = len(self.pool.get('res.users').search(cr, uid, [('lang', '=', lang.code)]))
141 res[lang.id] = user
142 return res
131143
132 _columns = {144 _columns = {
133 'name': fields.char('Name', size=64, required=True),145 'name': fields.char('Name', size=64, required=True),
@@ -141,6 +153,7 @@
141 'grouping':fields.char('Separator Format',size=64,required=True,help="The Separator Format should be like [,n] where 0 < n :starting from Unit digit.-1 will end the separation. e.g. [3,2,-1] will represent 106500 to be 1,06,500;[1,2,-1] will represent it to be 106,50,0;[3] will represent it as 106,500. Provided ',' as the thousand separator in each case."),153 'grouping':fields.char('Separator Format',size=64,required=True,help="The Separator Format should be like [,n] where 0 < n :starting from Unit digit.-1 will end the separation. e.g. [3,2,-1] will represent 106500 to be 1,06,500;[1,2,-1] will represent it to be 106,50,0;[3] will represent it as 106,500. Provided ',' as the thousand separator in each case."),
142 'decimal_point':fields.char('Decimal Separator', size=64,required=True),154 'decimal_point':fields.char('Decimal Separator', size=64,required=True),
143 'thousands_sep':fields.char('Thousands Separator',size=64),155 'thousands_sep':fields.char('Thousands Separator',size=64),
156 'no_of_user': fields.function(_no_of_user, string="Number of user",help='Number of user for this language.', type='integer'),
144 }157 }
145 _defaults = {158 _defaults = {
146 'active': 1,159 'active': 1,
@@ -158,7 +171,8 @@
158 ]171 ]
159172
160 _constraints = [173 _constraints = [
161 (_check_format, 'Invalid date/time format directive specified. Please refer to the list of allowed directives, displayed when you edit a language.', ['time_format', 'date_format'])174 (_check_format, 'Invalid date/time format directive specified. Please refer to the list of allowed directives, displayed when you edit a language.', ['time_format', 'date_format']),
175 (_check_active_lang, 'Atleast one language should be enabled.', ['active'])
162 ]176 ]
163177
164 @tools.ormcache(skiparg=3)178 @tools.ormcache(skiparg=3)
@@ -173,11 +187,27 @@
173 decimal_point = lang_obj.decimal_point187 decimal_point = lang_obj.decimal_point
174 grouping = lang_obj.grouping188 grouping = lang_obj.grouping
175 return grouping, thousands_sep, decimal_point189 return grouping, thousands_sep, decimal_point
176190
191 def send_notification(self, cr, uid, ids, context=None):
192 user_obj = self.pool.get('res.users')
193 for rec in self.browse(cr, uid, ids, context=context):
194 user_ids = user_obj.search(cr, uid, [('lang', '=', rec['code'])])
195 email_from = user_obj.browse(cr, uid, uid, context=context)
196 for uids in user_ids:
197 user = user_obj.browse(cr, uid, uids, context=context)
198 subject = 'Language notification'
199 body = _('Dear %s,\n %s Langague is no more supported, edited by %s in database "%s".')% (user.name, rec['name'], email_from.name, cr.dbname)
200 tools.email_send(email_from.email, [user.email], subject, body)
201 return True
202
177 def write(self, cr, uid, ids, vals, context=None):203 def write(self, cr, uid, ids, vals, context=None):
178 for lang_id in ids :204 for lang_id in ids :
179 self._lang_data_get.clear_cache(self)205 self._lang_data_get.clear_cache(self)
180 return super(lang, self).write(cr, uid, ids, vals, context)206 return_value = super(lang, self).write(cr, uid, ids, vals, context)
207 lang_status = vals.get('active')
208 if not lang_status and isinstance(lang_status, bool):
209 self.send_notification(cr, uid, ids, context=context)
210 return return_value
181211
182 def unlink(self, cr, uid, ids, context=None):212 def unlink(self, cr, uid, ids, context=None):
183 if context is None:213 if context is None:
@@ -196,6 +226,22 @@
196 trans_obj.unlink(cr, uid, trans_ids, context=context)226 trans_obj.unlink(cr, uid, trans_ids, context=context)
197 return super(lang, self).unlink(cr, uid, ids, context=context)227 return super(lang, self).unlink(cr, uid, ids, context=context)
198228
229 def check_single_lang_enable(self, cr, uid, context=None):
230 ids = self.search(cr, uid, [('active','=',True)], context=context)
231 return True if len(ids) == 1 else False
232
233 def set_deactive(self, cr, uid, ids, context=None):
234 lang = self.read(cr, uid, ids, ['code'], context=context)[0]
235 user_lang = self.pool.get('res.users').read(cr, uid, uid, ['lang'], context=context)
236 if lang['code'] == user_lang['lang']:
237 raise osv.except_osv(_('Error!'), _("You cannot deactivate your preferred language. If you still want to deactivate, kindly change it from your user preferences."))
238 self.write(cr, uid, ids, { 'active': False}, context=context)
239 return True
240
241 def set_active(self, cr, uid, ids, context=None):
242 self.write(cr, uid, ids, { 'active': True}, context=context)
243 return True
244
199 #245 #
200 # IDS: can be a list of IDS or a list of XML_IDS246 # IDS: can be a list of IDS or a list of XML_IDS
201 #247 #
202248
=== modified file 'openerp/addons/base/res/res_lang_view.xml'
--- openerp/addons/base/res/res_lang_view.xml 2012-08-07 12:51:38 +0000
+++ openerp/addons/base/res/res_lang_view.xml 2014-05-02 09:19:21 +0000
@@ -11,7 +11,10 @@
11 <field name="iso_code"/>11 <field name="iso_code"/>
12 <field name="direction"/>12 <field name="direction"/>
13 <field name="translatable"/>13 <field name="translatable"/>
14 <field name="active"/>14 <field name="no_of_user"/>
15 <field name="active" invisible="1"/>
16 <button name="set_deactive" help="Active" attrs="{'invisible': [('active', '=', False)]}" type="object" icon="gtk-yes"/>
17 <button name="set_active" help="Deactive" attrs="{'invisible': [('active', '=', True)]}" type="object" icon="gtk-no"/>
15 <button name="%(base.action_wizard_update_translations)d"18 <button name="%(base.action_wizard_update_translations)d"
16 string="Update Terms" type="action" icon="gtk-ok" help="Update Languague Terms"/>19 string="Update Terms" type="action" icon="gtk-ok" help="Update Languague Terms"/>
17 </tree>20 </tree>
@@ -38,6 +41,7 @@
38 <newline/>41 <newline/>
39 <field name="active" />42 <field name="active" />
40 <field name="translatable"/>43 <field name="translatable"/>
44 <field name="no_of_user"/>
41 </group>45 </group>
42 <separator colspan="4" string="Legends for Date and Time Formats"/>46 <separator colspan="4" string="Legends for Date and Time Formats"/>
43 <group col="4" colspan="4">47 <group col="4" colspan="4">
4448
=== modified file 'openerp/addons/base/res/res_users.py'
--- openerp/addons/base/res/res_users.py 2014-05-01 15:26:04 +0000
+++ openerp/addons/base/res/res_users.py 2014-05-02 09:19:21 +0000
@@ -157,6 +157,10 @@
157 def _get_password(self, cr, uid, ids, arg, karg, context=None):157 def _get_password(self, cr, uid, ids, arg, karg, context=None):
158 return dict.fromkeys(ids, '')158 return dict.fromkeys(ids, '')
159159
160 def _no_of_lang_enable(self, cr, uid, ids, arg, karg, context=None):
161 val = self.pool.get('res.lang').check_single_lang_enable(cr, uid, context=context)
162 return dict.fromkeys(ids, val)
163
160 _columns = {164 _columns = {
161 'id': fields.integer('ID'),165 'id': fields.integer('ID'),
162 'login_date': fields.date('Latest connection', select=1),166 'login_date': fields.date('Latest connection', select=1),
@@ -185,6 +189,7 @@
185 # backward compatibility fields189 # backward compatibility fields
186 'user_email': fields.related('email', type='char',190 'user_email': fields.related('email', type='char',
187 deprecated='Use the email field instead of user_email. This field will be removed with OpenERP 7.1.'),191 deprecated='Use the email field instead of user_email. This field will be removed with OpenERP 7.1.'),
192 'translation_flag':fields.function(_no_of_lang_enable, type='boolean', string='One language Enable'),
188 }193 }
189194
190 def on_change_login(self, cr, uid, ids, login, context=None):195 def on_change_login(self, cr, uid, ids, login, context=None):
@@ -364,7 +369,7 @@
364 for k in self._all_columns.keys():369 for k in self._all_columns.keys():
365 if k.startswith('context_'):370 if k.startswith('context_'):
366 context_key = k[8:]371 context_key = k[8:]
367 elif k in ['lang', 'tz']:372 elif k in ['lang', 'tz','translation_flag']:
368 context_key = k373 context_key = k
369 else:374 else:
370 context_key = False375 context_key = False
371376
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2014-04-16 14:34:31 +0000
+++ openerp/osv/orm.py 2014-05-02 09:19:21 +0000
@@ -3886,6 +3886,8 @@
3886 updend = []3886 updend = []
3887 direct = []3887 direct = []
3888 totranslate = context.get('lang', False) and (context['lang'] != 'en_US')3888 totranslate = context.get('lang', False) and (context['lang'] != 'en_US')
3889 single_lang_mode = self.pool.get('res.lang').check_single_lang_enable(cr, user, context=None)
3890
3889 for field in vals:3891 for field in vals:
3890 field_column = self._all_columns.get(field) and self._all_columns.get(field).column3892 field_column = self._all_columns.get(field) and self._all_columns.get(field).column
3891 if field_column and field_column.deprecated:3893 if field_column and field_column.deprecated:
@@ -3921,15 +3923,22 @@
39213923
3922 if totranslate:3924 if totranslate:
3923 # TODO: optimize3925 # TODO: optimize
3926 ir_translation = self.pool.get('ir.translation')
3927 model_name = self.pool[self._name]
3928 context_wo_lang = dict(context, lang=None)
3924 for f in direct:3929 for f in direct:
3930 src_trans = model_name.read(cr, user, ids, [f])[0][f]
3925 if self._columns[f].translate:3931 if self._columns[f].translate:
3926 src_trans = self.pool[self._name].read(cr, user, ids, [f])[0][f]3932 if single_lang_mode:
3927 if not src_trans:3933 if self.write(cr, user, ids, {f: vals[f]}, context_wo_lang):
3928 src_trans = vals[f]3934 ids_to_unlink = ir_translation.search(cr, user, [('src', '=', src_trans or vals[f]), ('type', '=', 'model'),('name', '=', self._name+','+f),('res_id', 'in', ids)])
3929 # Inserting value to DB3935 ir_translation.unlink(cr, user, ids_to_unlink, context)
3930 context_wo_lang = dict(context, lang=None)3936 else:
3931 self.write(cr, user, ids, {f: vals[f]}, context=context_wo_lang)3937 if not src_trans:
3932 self.pool.get('ir.translation')._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans)3938 src_trans = vals[f]
3939 # Inserting value to DB
3940 self.write(cr, user, ids, {f: vals[f]}, context=context_wo_lang)
3941 ir_translation._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans)
39333942
39343943
3935 # call the 'set' method of fields which are not classic_write3944 # call the 'set' method of fields which are not classic_write
39363945
=== modified file 'openerp/service/db.py'
--- openerp/service/db.py 2014-03-21 15:56:59 +0000
+++ openerp/service/db.py 2014-05-02 09:19:21 +0000
@@ -49,6 +49,10 @@
49 values = {'password': user_password, 'lang': lang}49 values = {'password': user_password, 'lang': lang}
50 registry['res.users'].write(cr, SUPERUSER_ID, [SUPERUSER_ID], values)50 registry['res.users'].write(cr, SUPERUSER_ID, [SUPERUSER_ID], values)
5151
52 lang_obj = registry['res.lang']
53 lang_ids = lang_obj.search(cr, SUPERUSER_ID, [('code', '!=', lang)])
54 lang_obj.write(cr, SUPERUSER_ID, lang_ids, {'active': False})
55
52 cr.execute('SELECT login, password FROM res_users ORDER BY login')56 cr.execute('SELECT login, password FROM res_users ORDER BY login')
53 self_actions[id].update(users=cr.dictfetchall(), clean=True)57 self_actions[id].update(users=cr.dictfetchall(), clean=True)
54 cr.commit()58 cr.commit()