[IMP] ir_translation: GUI improve in order to be able to change the english value of a model field (eg: a product name) directly in the translation window + small refactoring in order to test 'if context is None' rather than 'if not context' (see lp bug 525808)

bzr revid: qdp-launchpad@openerp.com-20130416091501-sgm3gdm80oxajahz
This commit is contained in:
Quentin (OpenERP) 2013-04-16 11:15:01 +02:00
commit d2e71a65e1
2 changed files with 44 additions and 7 deletions

View File

@ -155,12 +155,49 @@ class ir_translation(osv.osv):
lang_data = lang_model.read(cr, uid, lang_ids, ['code', 'name'], context=context)
return [(d['code'], d['name']) for d in lang_data]
def _get_src(self, cr, uid, ids, name, arg, context=None):
''' Get source name for the translation. If object type is model then
return the value store in db. Otherwise return value store in src field
'''
if context is None:
context = {}
res = {}
for record in self.browse(cr, uid, ids, context=context):
if record.type != 'model':
res[record.id] = record.src
else:
model, field = record.name.split(',')
#We need to take the context without the language information, because we want to read the
#value store in db and not on the one associate with current language.
context_wo_lang = context.copy()
context_wo_lang.pop('lang', None)
res[record.id] = model.read(cr, uid, record.res_id, [field], context=context_wo_lang)[field]
return res
def _set_src(self, cr, uid, id, name, value, args, context=None):
''' When changing source term of a translation, change its value in db for
the associated object, and the src field
'''
if context is None:
context = {}
if value and record.model == 'model':
record = self.browse(cr, uid, id, context=context)
model, field = record.name.split(',')
#We need to take the context without the language information, because we want to write on the
#value store in db and not on the one associate with current language.
#Also not removing lang from context trigger an error when lang is different
context_wo_lang = context.copy()
context_wo_lang.pop('lang', None)
model.write(cr, uid, record.res_id, {field: value}, context=context_wo_lang)
return self.write(cr, uid, id, {'src': value}, context=context_wo_lang)
_columns = {
'name': fields.char('Translated field', required=True),
'res_id': fields.integer('Record ID', select=True),
'lang': fields.selection(_get_language, string='Language'),
'type': fields.selection(TRANSLATION_TYPE, string='Type', select=True),
'src': fields.text('Source'),
'src': fields.text('Old source'),
'source': fields.function(_get_src, fnct_inv=_set_src, type='text', string='Source'),
'value': fields.text('Translation Value'),
'module': fields.char('Module', help="Module this term belongs to", select=True),
@ -300,7 +337,7 @@ class ir_translation(osv.osv):
return trad
def create(self, cr, uid, vals, context=None):
if not context:
if context is None:
context = {}
ids = super(ir_translation, self).create(cr, uid, vals, context=context)
self._get_source.clear_cache(self, uid, vals.get('name',0), vals.get('type',0), vals.get('lang',0), vals.get('src',0))
@ -308,7 +345,7 @@ class ir_translation(osv.osv):
return ids
def write(self, cursor, user, ids, vals, context=None):
if not context:
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
@ -323,7 +360,7 @@ class ir_translation(osv.osv):
return result
def unlink(self, cursor, user, ids, context=None):
if not context:
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]

View File

@ -14,7 +14,7 @@
domain="[('comments', 'like', 'openerp-web')]"/>
<field name="name" operator="="/>
<field name="lang"/>
<field name="src"/>
<field name="source"/>
<field name="value"/>
</search>
</field>
@ -38,7 +38,7 @@
<field name="res_id"/>
</group>
<group string="Source Term">
<field name="src" nolabel="1" height="400"/>
<field name="source" nolabel="1" height="400"/>
</group>
<group string="Translation">
<field name="value" nolabel="1" height="400"/>
@ -55,7 +55,7 @@
<field name="model">ir.translation</field>
<field name="arch" type="xml">
<tree string="Translations" editable="top">
<field name="src"/>
<field name="source"/>
<field name="value"/>
<field name="name"/>
<field name="lang"/>