From e4daa3df406edcbf040de3f792bbadba7f0cba51 Mon Sep 17 00:00:00 2001 From: Rohan Patel Date: Fri, 10 Jun 2016 11:56:17 +0530 Subject: [MOV] l10n_multilang : Re-organized directory structure. --- addons/l10n_multilang/__init__.py | 3 +- addons/l10n_multilang/account.py | 74 ---------------- addons/l10n_multilang/l10n_multilang.py | 114 ------------------------- addons/l10n_multilang/models/__init__.py | 5 ++ addons/l10n_multilang/models/account.py | 74 ++++++++++++++++ addons/l10n_multilang/models/l10n_multilang.py | 114 +++++++++++++++++++++++++ 6 files changed, 194 insertions(+), 190 deletions(-) delete mode 100644 addons/l10n_multilang/account.py delete mode 100644 addons/l10n_multilang/l10n_multilang.py create mode 100644 addons/l10n_multilang/models/__init__.py create mode 100644 addons/l10n_multilang/models/account.py create mode 100644 addons/l10n_multilang/models/l10n_multilang.py diff --git a/addons/l10n_multilang/__init__.py b/addons/l10n_multilang/__init__.py index 7e333946a66..81fc81d29c9 100644 --- a/addons/l10n_multilang/__init__.py +++ b/addons/l10n_multilang/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import account -import l10n_multilang \ No newline at end of file +import models diff --git a/addons/l10n_multilang/account.py b/addons/l10n_multilang/account.py deleted file mode 100644 index b34c3c28c58..00000000000 --- a/addons/l10n_multilang/account.py +++ /dev/null @@ -1,74 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - - -from openerp.osv import fields, osv -from openerp.tools.translate import _ - - -#in this file, we mostly add the tag translate=True on existing fields that we now want to be translated - -class account_account_template(osv.osv): - _inherit = 'account.account.template' - _columns = { - 'name': fields.char('Name', required=True, select=True, translate=True), - } - -class account_account(osv.osv): - _inherit = 'account.account' - _columns = { - 'name': fields.char('Name', required=True, select=True, translate=True), - } - -class account_tax(osv.osv): - _inherit = 'account.tax' - _columns = { - 'name': fields.char('Tax Name', required=True, select=True, translate=True), - } - - -class account_tax_template(osv.osv): - _inherit = 'account.tax.template' - _columns = { - 'name': fields.char('Tax Name', required=True, select=True, translate=True), - } - - -class account_chart_template(osv.osv): - _inherit = 'account.chart.template' - _columns={ - 'name': fields.char('Name', required=True, translate=True), - 'spoken_languages': fields.char('Spoken Languages', help="State here the languages for which the translations of templates could be loaded at the time of installation of this localization module and copied in the final object when generating them from templates. You must provide the language codes separated by ';'"), - } - _order = 'name' - - -class account_fiscal_position(osv.osv): - _inherit = 'account.fiscal.position' - _columns = { - 'name': fields.char('Fiscal Position', required=True, translate=True), - 'note': fields.text('Notes', translate=True), - } - - -class account_fiscal_position_template(osv.osv): - _inherit = 'account.fiscal.position.template' - _columns = { - 'name': fields.char('Fiscal Position Template', required=True, translate=True), - 'note': fields.text('Notes', translate=True), - } - - -class account_journal(osv.osv): - _inherit = 'account.journal' - _columns = { - 'name': fields.char('Journal Name', required=True, translate=True), - } - - -class account_analytic_account(osv.osv): - _inherit = 'account.analytic.account' - _columns = { - 'name': fields.char('Account Name', required=True, translate=True), - } - diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py deleted file mode 100644 index fd2900dcbb8..00000000000 --- a/addons/l10n_multilang/l10n_multilang.py +++ /dev/null @@ -1,114 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from openerp import api, models, SUPERUSER_ID -import logging -_logger = logging.getLogger(__name__) - -class AccountChartTemplate(models.Model): - _inherit = 'account.chart.template' - - @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 langs: List of languages to load for new records - :param in_field: Name of the translatable field of source templates - :param in_ids: Recordset of ids of source object - :param out_ids: Recordset of ids of destination object - - :return: True - """ - xlat_obj = self.env['ir.translation'] - #find the source from Account Template - for lang in langs: - #find the value from Translation - value = xlat_obj._get_ids(in_ids._name + ',' + in_field, 'model', lang, in_ids.ids) - counter = 0 - for element in in_ids.with_context(lang=None): - if value[element.id]: - #copy Translation from Source to Destination object - xlat_obj.create({ - 'name': out_ids._name + ',' + in_field, - 'type': 'model', - 'res_id': out_ids[counter].id, - 'lang': lang, - 'src': element.name, - 'value': value[element.id], - }) - else: - _logger.info('Language: %s. Translation from template: there is no translation available for %s!' %(lang, element.name)) - counter += 1 - return True - - @api.multi - def process_coa_translations(self): - installed_langs = dict(self.env['res.lang'].get_installed()) - 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 - - @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) - - @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) - - @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) - - -class base_language_install(models.TransientModel): - """ Install Language""" - - _inherit = "base.language.install" - - @api.multi - def lang_install(self): - self.ensure_one() - already_installed = self.env['res.lang'].search_count([('code', '=', self.lang)]) - res = super(base_language_install, self).lang_install() - if already_installed: - # update of translations instead of new installation - # skip to avoid duplicating the translations - return res - - # CoA in multilang mode - for coa in self.env['account.chart.template'].search([('spoken_languages', '!=', False)]): - if self.lang in coa.spoken_languages.split(';'): - # companies on which it is installed - for company in self.env['res.company'].search([('chart_template_id', '=', coa.id)]): - # write account.account translations in the real COA - coa._process_accounts_translations(company.id, [self.lang], 'name') - # copy account.tax translations - coa._process_taxes_translations(company.id, [self.lang], 'name') - # copy account.fiscal.position translations - coa._process_fiscal_pos_translations(company.id, [self.lang], 'name') - return res diff --git a/addons/l10n_multilang/models/__init__.py b/addons/l10n_multilang/models/__init__.py new file mode 100644 index 00000000000..e2616196f9e --- /dev/null +++ b/addons/l10n_multilang/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import account +import l10n_multilang diff --git a/addons/l10n_multilang/models/account.py b/addons/l10n_multilang/models/account.py new file mode 100644 index 00000000000..b34c3c28c58 --- /dev/null +++ b/addons/l10n_multilang/models/account.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from openerp.osv import fields, osv +from openerp.tools.translate import _ + + +#in this file, we mostly add the tag translate=True on existing fields that we now want to be translated + +class account_account_template(osv.osv): + _inherit = 'account.account.template' + _columns = { + 'name': fields.char('Name', required=True, select=True, translate=True), + } + +class account_account(osv.osv): + _inherit = 'account.account' + _columns = { + 'name': fields.char('Name', required=True, select=True, translate=True), + } + +class account_tax(osv.osv): + _inherit = 'account.tax' + _columns = { + 'name': fields.char('Tax Name', required=True, select=True, translate=True), + } + + +class account_tax_template(osv.osv): + _inherit = 'account.tax.template' + _columns = { + 'name': fields.char('Tax Name', required=True, select=True, translate=True), + } + + +class account_chart_template(osv.osv): + _inherit = 'account.chart.template' + _columns={ + 'name': fields.char('Name', required=True, translate=True), + 'spoken_languages': fields.char('Spoken Languages', help="State here the languages for which the translations of templates could be loaded at the time of installation of this localization module and copied in the final object when generating them from templates. You must provide the language codes separated by ';'"), + } + _order = 'name' + + +class account_fiscal_position(osv.osv): + _inherit = 'account.fiscal.position' + _columns = { + 'name': fields.char('Fiscal Position', required=True, translate=True), + 'note': fields.text('Notes', translate=True), + } + + +class account_fiscal_position_template(osv.osv): + _inherit = 'account.fiscal.position.template' + _columns = { + 'name': fields.char('Fiscal Position Template', required=True, translate=True), + 'note': fields.text('Notes', translate=True), + } + + +class account_journal(osv.osv): + _inherit = 'account.journal' + _columns = { + 'name': fields.char('Journal Name', required=True, translate=True), + } + + +class account_analytic_account(osv.osv): + _inherit = 'account.analytic.account' + _columns = { + 'name': fields.char('Account Name', required=True, translate=True), + } + diff --git a/addons/l10n_multilang/models/l10n_multilang.py b/addons/l10n_multilang/models/l10n_multilang.py new file mode 100644 index 00000000000..fd2900dcbb8 --- /dev/null +++ b/addons/l10n_multilang/models/l10n_multilang.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp import api, models, SUPERUSER_ID +import logging +_logger = logging.getLogger(__name__) + +class AccountChartTemplate(models.Model): + _inherit = 'account.chart.template' + + @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 langs: List of languages to load for new records + :param in_field: Name of the translatable field of source templates + :param in_ids: Recordset of ids of source object + :param out_ids: Recordset of ids of destination object + + :return: True + """ + xlat_obj = self.env['ir.translation'] + #find the source from Account Template + for lang in langs: + #find the value from Translation + value = xlat_obj._get_ids(in_ids._name + ',' + in_field, 'model', lang, in_ids.ids) + counter = 0 + for element in in_ids.with_context(lang=None): + if value[element.id]: + #copy Translation from Source to Destination object + xlat_obj.create({ + 'name': out_ids._name + ',' + in_field, + 'type': 'model', + 'res_id': out_ids[counter].id, + 'lang': lang, + 'src': element.name, + 'value': value[element.id], + }) + else: + _logger.info('Language: %s. Translation from template: there is no translation available for %s!' %(lang, element.name)) + counter += 1 + return True + + @api.multi + def process_coa_translations(self): + installed_langs = dict(self.env['res.lang'].get_installed()) + 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 + + @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) + + @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) + + @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) + + +class base_language_install(models.TransientModel): + """ Install Language""" + + _inherit = "base.language.install" + + @api.multi + def lang_install(self): + self.ensure_one() + already_installed = self.env['res.lang'].search_count([('code', '=', self.lang)]) + res = super(base_language_install, self).lang_install() + if already_installed: + # update of translations instead of new installation + # skip to avoid duplicating the translations + return res + + # CoA in multilang mode + for coa in self.env['account.chart.template'].search([('spoken_languages', '!=', False)]): + if self.lang in coa.spoken_languages.split(';'): + # companies on which it is installed + for company in self.env['res.company'].search([('chart_template_id', '=', coa.id)]): + # write account.account translations in the real COA + coa._process_accounts_translations(company.id, [self.lang], 'name') + # copy account.tax translations + coa._process_taxes_translations(company.id, [self.lang], 'name') + # copy account.fiscal.position translations + coa._process_fiscal_pos_translations(company.id, [self.lang], 'name') + return res -- cgit v1.2.3