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
1=== modified file 'openerp/addons/base/module/wizard/base_language_install.py'
2--- openerp/addons/base/module/wizard/base_language_install.py 2012-12-10 15:27:23 +0000
3+++ openerp/addons/base/module/wizard/base_language_install.py 2014-05-02 09:19:21 +0000
4@@ -49,6 +49,7 @@
5 context = {'overwrite': True}
6 modobj.update_translations(cr, uid, mids, lang, context or {})
7 self.write(cr, uid, ids, {'state': 'done'}, context=context)
8+ self.pool.get('res.users').write(cr, uid, uid, {'lang': lang})
9 return {
10 'name': _('Language Pack'),
11 'view_type': 'form',
12@@ -61,5 +62,10 @@
13 'target': 'new',
14 'res_id': ids and ids[0] or False,
15 }
16+ def reload_lang(self, cr, uid, ids, context=None):
17+ return {
18+ 'type': 'ir.actions.client',
19+ 'tag': 'reload',
20+ }
21
22 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
23
24=== modified file 'openerp/addons/base/module/wizard/base_language_install_view.xml'
25--- openerp/addons/base/module/wizard/base_language_install_view.xml 2012-08-17 07:25:55 +0000
26+++ openerp/addons/base/module/wizard/base_language_install_view.xml 2014-05-02 09:19:21 +0000
27@@ -21,7 +21,7 @@
28 <button special="cancel" string="Cancel" class="oe_link"/>
29 </footer>
30 <footer states="done">
31- <button special="cancel" string="Close"/>
32+ <button name="reload_lang" type="object" string="Close"/>
33 </footer>
34 </form>
35 </field>
36
37=== modified file 'openerp/addons/base/res/res_lang.py'
38--- openerp/addons/base/res/res_lang.py 2013-12-03 21:19:03 +0000
39+++ openerp/addons/base/res/res_lang.py 2014-05-02 09:19:21 +0000
40@@ -79,7 +79,6 @@
41 if not lang_name:
42 lang_name = tools.ALL_LANGUAGES.get(lang, lang)
43
44-
45 def fix_xa0(s):
46 """Fix badly-encoded non-breaking space Unicode character from locale.localeconv(),
47 coercing to utf-8, as some platform seem to output localeconv() in their system
48@@ -122,12 +121,25 @@
49 or (lang.date_format and pattern in lang.date_format):
50 return False
51 return True
52+
53+ def _check_active_lang(self, cr, uid, ids, context=None):
54+ lang_ids = self.search(cr, uid, [('active', '=', True)])
55+ if len(lang_ids) < 1:
56+ return False
57+ return True
58
59 def _get_default_date_format(self, cursor, user, context=None):
60 return '%m/%d/%Y'
61
62 def _get_default_time_format(self, cursor, user, context=None):
63 return '%H:%M:%S'
64+
65+ def _no_of_user(self, cr, uid, ids, name, args, context=None):
66+ res = {}
67+ for lang in self.browse(cr, uid, ids, context=context):
68+ user = len(self.pool.get('res.users').search(cr, uid, [('lang', '=', lang.code)]))
69+ res[lang.id] = user
70+ return res
71
72 _columns = {
73 'name': fields.char('Name', size=64, required=True),
74@@ -141,6 +153,7 @@
75 '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."),
76 'decimal_point':fields.char('Decimal Separator', size=64,required=True),
77 'thousands_sep':fields.char('Thousands Separator',size=64),
78+ 'no_of_user': fields.function(_no_of_user, string="Number of user",help='Number of user for this language.', type='integer'),
79 }
80 _defaults = {
81 'active': 1,
82@@ -158,7 +171,8 @@
83 ]
84
85 _constraints = [
86- (_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'])
87+ (_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']),
88+ (_check_active_lang, 'Atleast one language should be enabled.', ['active'])
89 ]
90
91 @tools.ormcache(skiparg=3)
92@@ -173,11 +187,27 @@
93 decimal_point = lang_obj.decimal_point
94 grouping = lang_obj.grouping
95 return grouping, thousands_sep, decimal_point
96-
97+
98+ def send_notification(self, cr, uid, ids, context=None):
99+ user_obj = self.pool.get('res.users')
100+ for rec in self.browse(cr, uid, ids, context=context):
101+ user_ids = user_obj.search(cr, uid, [('lang', '=', rec['code'])])
102+ email_from = user_obj.browse(cr, uid, uid, context=context)
103+ for uids in user_ids:
104+ user = user_obj.browse(cr, uid, uids, context=context)
105+ subject = 'Language notification'
106+ 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)
107+ tools.email_send(email_from.email, [user.email], subject, body)
108+ return True
109+
110 def write(self, cr, uid, ids, vals, context=None):
111 for lang_id in ids :
112 self._lang_data_get.clear_cache(self)
113- return super(lang, self).write(cr, uid, ids, vals, context)
114+ return_value = super(lang, self).write(cr, uid, ids, vals, context)
115+ lang_status = vals.get('active')
116+ if not lang_status and isinstance(lang_status, bool):
117+ self.send_notification(cr, uid, ids, context=context)
118+ return return_value
119
120 def unlink(self, cr, uid, ids, context=None):
121 if context is None:
122@@ -196,6 +226,22 @@
123 trans_obj.unlink(cr, uid, trans_ids, context=context)
124 return super(lang, self).unlink(cr, uid, ids, context=context)
125
126+ def check_single_lang_enable(self, cr, uid, context=None):
127+ ids = self.search(cr, uid, [('active','=',True)], context=context)
128+ return True if len(ids) == 1 else False
129+
130+ def set_deactive(self, cr, uid, ids, context=None):
131+ lang = self.read(cr, uid, ids, ['code'], context=context)[0]
132+ user_lang = self.pool.get('res.users').read(cr, uid, uid, ['lang'], context=context)
133+ if lang['code'] == user_lang['lang']:
134+ raise osv.except_osv(_('Error!'), _("You cannot deactivate your preferred language. If you still want to deactivate, kindly change it from your user preferences."))
135+ self.write(cr, uid, ids, { 'active': False}, context=context)
136+ return True
137+
138+ def set_active(self, cr, uid, ids, context=None):
139+ self.write(cr, uid, ids, { 'active': True}, context=context)
140+ return True
141+
142 #
143 # IDS: can be a list of IDS or a list of XML_IDS
144 #
145
146=== modified file 'openerp/addons/base/res/res_lang_view.xml'
147--- openerp/addons/base/res/res_lang_view.xml 2012-08-07 12:51:38 +0000
148+++ openerp/addons/base/res/res_lang_view.xml 2014-05-02 09:19:21 +0000
149@@ -11,7 +11,10 @@
150 <field name="iso_code"/>
151 <field name="direction"/>
152 <field name="translatable"/>
153- <field name="active"/>
154+ <field name="no_of_user"/>
155+ <field name="active" invisible="1"/>
156+ <button name="set_deactive" help="Active" attrs="{'invisible': [('active', '=', False)]}" type="object" icon="gtk-yes"/>
157+ <button name="set_active" help="Deactive" attrs="{'invisible': [('active', '=', True)]}" type="object" icon="gtk-no"/>
158 <button name="%(base.action_wizard_update_translations)d"
159 string="Update Terms" type="action" icon="gtk-ok" help="Update Languague Terms"/>
160 </tree>
161@@ -38,6 +41,7 @@
162 <newline/>
163 <field name="active" />
164 <field name="translatable"/>
165+ <field name="no_of_user"/>
166 </group>
167 <separator colspan="4" string="Legends for Date and Time Formats"/>
168 <group col="4" colspan="4">
169
170=== modified file 'openerp/addons/base/res/res_users.py'
171--- openerp/addons/base/res/res_users.py 2014-05-01 15:26:04 +0000
172+++ openerp/addons/base/res/res_users.py 2014-05-02 09:19:21 +0000
173@@ -157,6 +157,10 @@
174 def _get_password(self, cr, uid, ids, arg, karg, context=None):
175 return dict.fromkeys(ids, '')
176
177+ def _no_of_lang_enable(self, cr, uid, ids, arg, karg, context=None):
178+ val = self.pool.get('res.lang').check_single_lang_enable(cr, uid, context=context)
179+ return dict.fromkeys(ids, val)
180+
181 _columns = {
182 'id': fields.integer('ID'),
183 'login_date': fields.date('Latest connection', select=1),
184@@ -185,6 +189,7 @@
185 # backward compatibility fields
186 '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.'),
188+ 'translation_flag':fields.function(_no_of_lang_enable, type='boolean', string='One language Enable'),
189 }
190
191 def on_change_login(self, cr, uid, ids, login, context=None):
192@@ -364,7 +369,7 @@
193 for k in self._all_columns.keys():
194 if k.startswith('context_'):
195 context_key = k[8:]
196- elif k in ['lang', 'tz']:
197+ elif k in ['lang', 'tz','translation_flag']:
198 context_key = k
199 else:
200 context_key = False
201
202=== modified file 'openerp/osv/orm.py'
203--- openerp/osv/orm.py 2014-04-16 14:34:31 +0000
204+++ openerp/osv/orm.py 2014-05-02 09:19:21 +0000
205@@ -3886,6 +3886,8 @@
206 updend = []
207 direct = []
208 totranslate = context.get('lang', False) and (context['lang'] != 'en_US')
209+ single_lang_mode = self.pool.get('res.lang').check_single_lang_enable(cr, user, context=None)
210+
211 for field in vals:
212 field_column = self._all_columns.get(field) and self._all_columns.get(field).column
213 if field_column and field_column.deprecated:
214@@ -3921,15 +3923,22 @@
215
216 if totranslate:
217 # TODO: optimize
218+ ir_translation = self.pool.get('ir.translation')
219+ model_name = self.pool[self._name]
220+ context_wo_lang = dict(context, lang=None)
221 for f in direct:
222+ src_trans = model_name.read(cr, user, ids, [f])[0][f]
223 if self._columns[f].translate:
224- src_trans = self.pool[self._name].read(cr, user, ids, [f])[0][f]
225- if not src_trans:
226- src_trans = vals[f]
227- # Inserting value to DB
228- context_wo_lang = dict(context, lang=None)
229- self.write(cr, user, ids, {f: vals[f]}, context=context_wo_lang)
230- self.pool.get('ir.translation')._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans)
231+ if single_lang_mode:
232+ if self.write(cr, user, ids, {f: vals[f]}, context_wo_lang):
233+ ids_to_unlink = ir_translation.search(cr, user, [('src', '=', src_trans or vals[f]), ('type', '=', 'model'),('name', '=', self._name+','+f),('res_id', 'in', ids)])
234+ ir_translation.unlink(cr, user, ids_to_unlink, context)
235+ else:
236+ if not src_trans:
237+ src_trans = vals[f]
238+ # Inserting value to DB
239+ self.write(cr, user, ids, {f: vals[f]}, context=context_wo_lang)
240+ ir_translation._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans)
241
242
243 # call the 'set' method of fields which are not classic_write
244
245=== modified file 'openerp/service/db.py'
246--- openerp/service/db.py 2014-03-21 15:56:59 +0000
247+++ openerp/service/db.py 2014-05-02 09:19:21 +0000
248@@ -49,6 +49,10 @@
249 values = {'password': user_password, 'lang': lang}
250 registry['res.users'].write(cr, SUPERUSER_ID, [SUPERUSER_ID], values)
251
252+ lang_obj = registry['res.lang']
253+ lang_ids = lang_obj.search(cr, SUPERUSER_ID, [('code', '!=', lang)])
254+ lang_obj.write(cr, SUPERUSER_ID, lang_ids, {'active': False})
255+
256 cr.execute('SELECT login, password FROM res_users ORDER BY login')
257 self_actions[id].update(users=cr.dictfetchall(), clean=True)
258 cr.commit()