~openerp-dev/openobject-server/trunk-missing-default-values-pza

« back to all changes in this revision

Viewing changes to openerp/addons/base/ir/ir_translation.py

  • Committer: Pooja Zankhariya (OpenERP)
  • Date: 2014-01-31 06:44:29 UTC
  • mfrom: (5013.1.35 trunk)
  • Revision ID: pza@tinyerp.com-20140131064429-0a1u9ax5cf3sslug
[MERGE]Sync with Trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
        return translations
269
269
 
270
270
    def _set_ids(self, cr, uid, name, tt, lang, ids, value, src=None):
271
 
        # clear the caches
272
 
        tr = self._get_ids(cr, uid, name, tt, lang, ids)
273
 
        for res_id in tr:
274
 
            if tr[res_id]:
275
 
                self._get_source.clear_cache(self, uid, name, tt, lang, tr[res_id])
276
 
            self._get_ids.clear_cache(self, uid, name, tt, lang, res_id)
277
 
        self._get_source.clear_cache(self, uid, name, tt, lang)
 
271
        self._get_ids.clear_cache(self)
 
272
        self._get_source.clear_cache(self)
278
273
 
279
274
        cr.execute('delete from ir_translation '
280
275
                'where lang=%s '
294
289
        return len(ids)
295
290
 
296
291
    @tools.ormcache(skiparg=3)
297
 
    def _get_source(self, cr, uid, name, types, lang, source=None):
 
292
    def _get_source(self, cr, uid, name, types, lang, source=None, res_id=None):
298
293
        """
299
294
        Returns the translation for the given combination of name, type, language
300
295
        and source. All values passed to this method should be unicode (not byte strings),
304
299
        :param types: single string defining type of term to translate (see ``type`` field on ir.translation), or sequence of allowed types (strings)
305
300
        :param lang: language code of the desired translation
306
301
        :param source: optional source term to translate (should be unicode)
 
302
        :param res_id: optional resource id to translate (if used, ``source`` should be set)
307
303
        :rtype: unicode
308
304
        :return: the request translation, or an empty unicode string if no translation was
309
305
                 found and `source` was not passed
321
317
                        AND type in %s
322
318
                        AND src=%s"""
323
319
            params = (lang or '', types, tools.ustr(source))
 
320
            if res_id:
 
321
                query += "AND res_id=%s"
 
322
                params += (res_id,)
324
323
            if name:
325
324
                query += " AND name=%s"
326
325
                params += (tools.ustr(name),)
342
341
        if context is None:
343
342
            context = {}
344
343
        ids = super(ir_translation, self).create(cr, uid, vals, context=context)
345
 
        self._get_source.clear_cache(self, uid, vals.get('name',0), vals.get('type',0),  vals.get('lang',0), vals.get('src',0))
346
 
        self._get_ids.clear_cache(self, uid, vals.get('name',0), vals.get('type',0), vals.get('lang',0), vals.get('res_id',0))
 
344
        self._get_source.clear_cache(self)
 
345
        self._get_ids.clear_cache(self)
 
346
        self.pool['ir.ui.view'].clear_cache()
347
347
        return ids
348
348
 
349
349
    def write(self, cursor, user, ids, vals, context=None):
356
356
        if vals.get('value'):
357
357
            vals.update({'state':'translated'})
358
358
        result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)
359
 
        for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
360
 
            self._get_source.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['src'])
361
 
            self._get_ids.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['res_id'])
 
359
        self._get_source.clear_cache(self)
 
360
        self._get_ids.clear_cache(self)
 
361
        self.pool['ir.ui.view'].clear_cache()
362
362
        return result
363
363
 
364
364
    def unlink(self, cursor, user, ids, context=None):
366
366
            context = {}
367
367
        if isinstance(ids, (int, long)):
368
368
            ids = [ids]
369
 
        for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
370
 
            self._get_source.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['src'])
371
 
            self._get_ids.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['res_id'])
 
369
 
 
370
        self._get_source.clear_cache(self)
 
371
        self._get_ids.clear_cache(self)
372
372
        result = super(ir_translation, self).unlink(cursor, user, ids, context=context)
373
373
        return result
374
374