Browse Source

[CHG] read_translations() not working as expected on OpenERP 7, use the normal read()

pull/1312/head
Guewen Baconnier 11 years ago
committed by Timon Tschanz
parent
commit
c2d7cf346f
  1. 21
      web_translate_dialog/__init__.py
  2. 2
      web_translate_dialog/__openerp__.py
  3. 79
      web_translate_dialog/orm.py
  4. 3
      web_translate_dialog/static/src/js/web_translate_dialog.js

21
web_translate_dialog/__init__.py

@ -1,22 +1 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2012 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import orm

2
web_translate_dialog/__openerp__.py

@ -27,8 +27,6 @@ Replace the standard translation view by an alternative one:
* Add a "Translate" button item in the "More" menu * Add a "Translate" button item in the "More" menu
* The translations are displayed in a dialog (much like the OpenERP * The translations are displayed in a dialog (much like the OpenERP
6.1's one) 6.1's one)
* The translation dialog displays empty fields for the untranslated fields,
instead of the source values.
* Support HTML fields * Support HTML fields
* Autosize the textareas to the size of the content * Autosize the textareas to the size of the content

79
web_translate_dialog/orm.py

@ -1,79 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2012-2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import openerp.osv.orm
# add the method in the orm so we can use it from the TranslateDialog of the
# webclient instead of the normal read
def read_translations(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
""" Read records with given ids with the given fields, if a field is not
translated, its value will be False instead of the source language's value.
:param fields: optional list of field names to return (default: all fields would be returned)
:type fields: list (example ['field_name_1', ...])
:return: list of dictionaries((dictionary per record asked)) with requested field values
:rtype: [{name_of_the_field: value, ...}, ...]
:raise AccessError: * if user has no read rights on the requested object
* if user tries to bypass access rules for read on the requested object
"""
if context is None:
context = {}
self.check_access_rights(cr, user, 'read')
fields = self.check_field_access_rights(cr, user, 'read', fields)
if isinstance(ids, (int, long)):
select = [ids]
else:
select = ids
select = map(lambda x: isinstance(x, dict) and x['id'] or x, select)
result = self._read_flat(cr, user, select, fields, context, load)
if context.get('lang') and context['lang'] != 'en_US':
fields_pre = [f for f in fields if
(f in self._columns and
getattr(self._columns[f], '_classic_write'))] + \
self._inherits.values()
for f in fields_pre:
if self._columns[f].translate:
res_ids = [x['id'] for x in result]
res_trans = self.pool.get('ir.translation')._get_ids(
cr, user,
self._name + ',' + f,
'model',
context['lang'],
res_ids)
for r in result:
if not res_trans.get(r['id']):
r[f] = None
for r in result:
for key, v in r.iteritems():
if v is None:
r[key] = False
if isinstance(ids, (int, long, dict)):
return result and result[0] or False
return result
openerp.osv.orm.BaseModel.read_translations = read_translations

3
web_translate_dialog/static/src/js/web_translate_dialog.js

@ -60,7 +60,6 @@ openerp.web_translate_dialog = function (instance) {
sup = this._super; sup = this._super;
// the template needs the languages // the template needs the languages
$.when(this.languages_loaded).then(function() { $.when(this.languages_loaded).then(function() {
// if (self.view.translatable_fields && self.view.translatable_fields.length) {
return sup.call(self); return sup.call(self);
}); });
}, },
@ -139,7 +138,7 @@ openerp.web_translate_dialog = function (instance) {
var callback = function(values) { var callback = function(values) {
}; };
self.view.dataset.call( self.view.dataset.call(
'read_translations',
'read',
[[self.view.datarecord.id], [[self.view.datarecord.id],
self.translatable_fields_keys, self.translatable_fields_keys,
self.view.dataset.get_context({ self.view.dataset.get_context({

Loading…
Cancel
Save