diff --git a/addons/l10n_be/__init__.py b/addons/l10n_be/__init__.py index 67dee8c60db..bc43313210c 100644 --- a/addons/l10n_be/__init__.py +++ b/addons/l10n_be/__init__.py @@ -1,2 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp import SUPERUSER_ID + +def load_translations(cr, registry): + chart_template = registry['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'l10n_be.l10nbe_chart_template') + chart_template.process_coa_translations() \ No newline at end of file diff --git a/addons/l10n_be/__openerp__.py b/addons/l10n_be/__openerp__.py index 0c8c4cddabb..ebfc999e287 100644 --- a/addons/l10n_be/__openerp__.py +++ b/addons/l10n_be/__openerp__.py @@ -61,4 +61,5 @@ Wizards provided by this module: ], 'installable': True, 'website': 'https://www.odoo.com/page/accounting', + 'post_init_hook': 'load_translations', } diff --git a/addons/l10n_be/account_chart_template.xml b/addons/l10n_be/account_chart_template.xml index 011c2900390..37d4acee191 100644 --- a/addons/l10n_be/account_chart_template.xml +++ b/addons/l10n_be/account_chart_template.xml @@ -26,6 +26,7 @@ Belgian PCMN + diff --git a/addons/l10n_be/account_chart_template.yml b/addons/l10n_be/account_chart_template.yml index 2275d421b44..609acfedd29 100644 --- a/addons/l10n_be/account_chart_template.yml +++ b/addons/l10n_be/account_chart_template.yml @@ -1,7 +1,3 @@ -- - !python {model: account.chart.template}: | - if 'spoken_languages' in self._all_columns: - self.write(cr, uid, [ref('l10nbe_chart_template')], {'spoken_languages': 'nl_BE'}) - !python {model: account.chart.template, id: l10nbe_chart_template}: | - self[0].try_loading_for_current_company() \ No newline at end of file + self[0].try_loading_for_current_company() diff --git a/addons/l10n_ch/__init__.py b/addons/l10n_ch/__init__.py index 02e36b8822a..f7bd52fa93d 100644 --- a/addons/l10n_ch/__init__.py +++ b/addons/l10n_ch/__init__.py @@ -6,3 +6,8 @@ # Prisme Solutions Informatique SA, Quod SA # Translation contributors: brain-tec AG, Agile Business Group +from openerp import SUPERUSER_ID + +def load_translations(cr, registry): + chart_template = registry['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'l10n_ch.l10nch_chart_template') + chart_template.process_coa_translations() \ No newline at end of file diff --git a/addons/l10n_ch/__openerp__.py b/addons/l10n_ch/__openerp__.py index 86e02ccb972..d01526e5d51 100644 --- a/addons/l10n_ch/__openerp__.py +++ b/addons/l10n_ch/__openerp__.py @@ -53,4 +53,5 @@ https://github.com/OCA/l10n-switzerland 'test': [], 'auto_install': False, 'installable': True, + 'post_init_hook': 'load_translations', } diff --git a/addons/l10n_ch/chart/account.xml b/addons/l10n_ch/chart/account.xml index 7123c0a1337..7567a31f2a7 100644 --- a/addons/l10n_ch/chart/account.xml +++ b/addons/l10n_ch/chart/account.xml @@ -27,6 +27,7 @@ 1000 + diff --git a/addons/l10n_multilang/__init__.py b/addons/l10n_multilang/__init__.py index e2616196f9e..7e333946a66 100644 --- a/addons/l10n_multilang/__init__.py +++ b/addons/l10n_multilang/__init__.py @@ -2,4 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import account -import l10n_multilang +import l10n_multilang \ No newline at end of file diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index aa182e5d6ba..58cd5834796 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -1,132 +1,86 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import fields, osv -import os -from openerp.tools.translate import _ +from openerp import api, models, SUPERUSER_ID import logging _logger = logging.getLogger(__name__) -class wizard_multi_charts_accounts(osv.osv_memory): - """ - Change wizard that a new account chart for a company. - * Add option to install languages during the setup - * Copy translations for COA, Tax, Tax Code and Fiscal Position from templates to target objects. - """ - _inherit = 'wizard.multi.charts.accounts' +class AccountChartTemplate(models.Model): + _inherit = 'account.chart.template' - # FIXME: in trunk, drop the force_write param entirely - def process_translations(self, cr, uid, langs, in_obj, in_field, in_ids, out_obj, out_ids, force_write=False, context=None): + @api.multi + def process_translations(self, langs, in_field, in_ids, out_ids): """ This method copies translations values of templates into new Accounts/Taxes/Journals for languages selected - :param cr: A database cursor - :param uid: ID of the user currently logged in :param langs: List of languages to load for new records :param in_field: Name of the translatable field of source templates - :param in_obj: Name of source object of templates. - :param in_ids: List of ids of source object - :param out_obj: Destination object for which translation is to be copied - :param out_ids: List of ids of destination object - :param force_write: Deprecated as of 7.0, do not use - :param context: usual context information. May contain the key 'lang', which is the language of the user running - the wizard, that will be used if force_write is True + :param in_ids: Recordset of ids of source object + :param out_ids: Recordset of ids of destination object :return: True """ - if context is None: - context = {} - src = {} - xlat_obj = self.pool.get('ir.translation') + xlat_obj = self.env['ir.translation'] #find the source from Account Template - for x in in_obj.browse(cr, uid, in_ids): - src.update({x.id: x.name}) for lang in langs: #find the value from Translation - value = xlat_obj._get_ids(cr, uid, in_obj._name + ',' + in_field, 'model', lang, in_ids) - for j in range(len(in_ids)): - in_id = in_ids[j] - if value[in_id]: + value = xlat_obj._get_ids(in_ids._name + ',' + in_field, 'model', lang, in_ids.ids) + counter = 0 + for element in in_ids: + if value[element.id]: #copy Translation from Source to Destination object - xlat_obj.create(cr, uid, { - 'name': out_obj._name + ',' + in_field, + xlat_obj.create({ + 'name': out_ids._name + ',' + in_field, 'type': 'model', - 'res_id': out_ids[j], + 'res_id': out_ids[counter].id, 'lang': lang, - 'src': src[in_id], - 'value': value[in_id], + 'src': element.name, + 'value': value[element.id], }) else: - _logger.info('Language: %s. Translation from template: there is no translation available for %s!' %(lang, src[in_id]))#out_obj._name)) + _logger.info('Language: %s. Translation from template: there is no translation available for %s!' %(lang, element.name)) + counter += 1 return True - def execute(self, cr, uid, ids, context=None): - if not context: - context = {} - # remove the lang to get the untranslated value - ctx = dict(context, lang=None) - res = super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context=ctx) + @api.multi + def process_coa_translations(self): + installed_lang_ids = self.env['res.lang'].search([]) + installed_langs = [x.code for x in installed_lang_ids] + company_obj = self.env['res.company'] + for chart_template_id in self: + langs = [] + if chart_template_id.spoken_languages: + for lang in chart_template_id.spoken_languages.split(';'): + if lang not in installed_langs: + # the language is not installed, so we don't need to load its translations + continue + else: + langs.append(lang) + if langs: + company_ids = company_obj.search([('chart_template_id', '=', chart_template_id.id)]) + for company in company_ids: + # write account.account translations in the real COA + chart_template_id._process_accounts_translations(company.id, langs, 'name') + # copy account.tax translations + chart_template_id._process_taxes_translations(company.id, langs, 'name') + # copy account.fiscal.position translations + chart_template_id._process_fiscal_pos_translations(company.id, langs, 'name') + return True - obj_multi = self.browse(cr, uid, ids[0], context=context) - company_id = obj_multi.company_id.id + @api.multi + def _process_accounts_translations(self, company_id, langs, field): + in_ids = self.env['account.account.template'].search([('chart_template_id', '=', self.id)], order='id') + out_ids = self.env['account.account'].search([('company_id', '=', company_id)], order='id') + return self.process_translations(langs, field, in_ids, out_ids) - # load languages - langs = [] - res_lang_obj = self.pool.get('res.lang') - installed_lang_ids = res_lang_obj.search(cr, uid, []) - installed_langs = [x.code for x in res_lang_obj.browse(cr, uid, installed_lang_ids, context=context)] - if obj_multi.chart_template_id.spoken_languages: - for lang in obj_multi.chart_template_id.spoken_languages.split(';'): - if lang not in installed_langs: - # the language is not installed, so we don't need to load its translations - continue - else: - # the language was already installed, so the po files have been loaded at the installation time - # and now we need to copy the translations of templates to the right objects - langs.append(lang) - if langs: - # write account.account translations in the real COA - self._process_accounts_translations(cr, uid, obj_multi, company_id, langs, 'name', context=context) + @api.multi + def _process_taxes_translations(self, company_id, langs, field): + in_ids = self.env['account.tax.template'].search([('chart_template_id', '=', self.id)], order='id') + out_ids = self.env['account.tax'].search([('company_id', '=', company_id)], order='id') + return self.process_translations(langs, field, in_ids, out_ids) - # copy account.tax.code translations - self._process_tax_codes_translations(cr, uid, obj_multi, company_id, langs, 'name', context=context) - - # copy account.tax translations - self._process_taxes_translations(cr, uid, obj_multi, company_id, langs, 'name', context=context) - - # copy account.fiscal.position translations - self._process_fiscal_pos_translations(cr, uid, obj_multi, company_id, langs, 'name', context=context) - - return res - - def _process_accounts_translations(self, cr, uid, obj_multi, company_id, langs, field, context=None): - obj_acc_template = self.pool.get('account.account.template') - obj_acc = self.pool.get('account.account') - acc_template_root_id = obj_multi.chart_template_id.account_root_id.id - acc_root_id = obj_acc.search(cr, uid, [('company_id', '=', company_id), ('parent_id', '=', None)])[0] - in_ids = obj_acc_template.search(cr, uid, [('id', 'child_of', [acc_template_root_id])], order='id')[1:] - out_ids = obj_acc.search(cr, uid, [('id', 'child_of', [acc_root_id])], order='id')[1:] - return self.process_translations(cr, uid, langs, obj_acc_template, field, in_ids, obj_acc, out_ids, context=context) - - def _process_tax_codes_translations(self, cr, uid, obj_multi, company_id, langs, field, context=None): - obj_tax_code_template = self.pool.get('account.tax.code.template') - obj_tax_code = self.pool.get('account.tax.code') - tax_code_template_root_id = obj_multi.chart_template_id.tax_code_root_id.id - tax_code_root_id = obj_tax_code.search(cr, uid, [('company_id', '=', company_id), ('parent_id', '=', None)])[0] - in_ids = obj_tax_code_template.search(cr, uid, [('id', 'child_of', [tax_code_template_root_id])], order='id')[1:] - out_ids = obj_tax_code.search(cr, uid, [('id', 'child_of', [tax_code_root_id])], order='id')[1:] - return self.process_translations(cr, uid, langs, obj_tax_code_template, field, in_ids, obj_tax_code, out_ids, context=context) - - def _process_taxes_translations(self, cr, uid, obj_multi, company_id, langs, field, context=None): - obj_tax_template = self.pool.get('account.tax.template') - obj_tax = self.pool.get('account.tax') - in_ids = [x.id for x in obj_multi.chart_template_id.tax_template_ids] - out_ids = obj_tax.search(cr, uid, [('company_id', '=', company_id)], order='id') - return self.process_translations(cr, uid, langs, obj_tax_template, field, in_ids, obj_tax, out_ids, context=context) - - def _process_fiscal_pos_translations(self, cr, uid, obj_multi, company_id, langs, field, context=None): - obj_fiscal_position_template = self.pool.get('account.fiscal.position.template') - obj_fiscal_position = self.pool.get('account.fiscal.position') - in_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.chart_template_id.id)], order='id') - out_ids = obj_fiscal_position.search(cr, uid, [('company_id', '=', company_id)], order='id') - return self.process_translations(cr, uid, langs, obj_fiscal_position_template, field, in_ids, obj_fiscal_position, out_ids, context=context) + @api.multi + def _process_fiscal_pos_translations(self, company_id, langs, field): + in_ids = self.env['account.fiscal.position.template'].search([('chart_template_id', '=', self.id)], order='id') + out_ids = self.env['account.fiscal.position'].search([('company_id', '=', company_id)], order='id') + return self.process_translations(langs, field, in_ids, out_ids) diff --git a/addons/l10n_sa/__init__.py b/addons/l10n_sa/__init__.py index 57d631c3f00..924ad495ebb 100644 --- a/addons/l10n_sa/__init__.py +++ b/addons/l10n_sa/__init__.py @@ -1 +1,7 @@ # coding: utf-8 + +from openerp import SUPERUSER_ID + +def load_translations(cr, registry): + chart_template = registry['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'l10n_sa.account_arabic_coa_general') + chart_template.process_coa_translations() \ No newline at end of file diff --git a/addons/l10n_sa/__openerp__.py b/addons/l10n_sa/__openerp__.py index aa293fdc63b..4c6926cbc7d 100644 --- a/addons/l10n_sa/__openerp__.py +++ b/addons/l10n_sa/__openerp__.py @@ -13,7 +13,7 @@ This initially includes chart of accounts of USA translated to Arabic. In future this module will include some payroll rules for ME . """, 'website': 'http://www.dvit.me', - 'depends': ['account'], # TODO: should also depend on multilang + 'depends': ['account', 'l10n_multilang'], 'data': [ 'account.chart.template.xml', 'account.account.template.csv', @@ -24,4 +24,5 @@ In future this module will include some payroll rules for ME . 'test': [], 'installable': True, 'auto_install': False, + 'post_init_hook': 'load_translations', }