diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index 85a19c9fd08..ff2fd541bcb 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -21,17 +21,108 @@ from osv import fields, osv import os +from tools.translate import _ + + +class translate_message(osv.osv_memory): + _name = "translate.message" + _description = "Translation Message" + + _columns = { + 'message' : fields.text('Message', readonly=True), + } + +translate_message() + class wizard_multi_charts_accounts(osv.osv_memory): """ Change wizard that a new account chart for a company. - * load Default languages - * Replace creation of financial accounts by copy from template. - This change results in adherence to Belgian MAR numbering scheme for cash accounts. - * Create financial journals for each account of type liquidity + * 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' + def copy_translations(self, cr, uid, langs, in_obj, in_field, in_ids, out_obj, out_ids): + """ + * langs: Loaded languages + * in_field: 'name' field + * in_obj, in_ids: Source object and params. + * out_obj, out_ids: Destination object and params. + * Return: Translation message. + """ + src = {} + xlat_obj = self.pool.get('ir.translation') + #find the source from Account Template + for x in in_obj.browse(cr, uid, in_ids): + src.update({x.id: x.name}) + message = '' + for lang in langs: + notdone = [] + #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 not value[in_id]: + # if source have no translation available + notdone.append(src[in_id]) + else: + #copy Translation from Source to Destination object + xlat_obj.create(cr, uid, { + 'name': out_obj._name + ',' + in_field, + 'type': 'model', + 'res_id': out_ids[j], + 'lang': lang, + 'src': src[in_id], + 'value': value[in_id], + }) + if notdone: + message += '\nLanguage: %s \n\tThere is no translation available for following %s(s): \n\t%s '\ + % (lang, (out_obj._name[8:].replace('.',' ')).title(), '\n\t'.join(notdone)) + else: + message += '\nLanguage: %s \n\tTranslation successfully done for %s(s) .' % (lang, (out_obj._name[8:].replace('.',' ')).title()) + + return message + + def execute(self, cr, uid, ids, context=None): + res = super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context=context) + obj_multi = self.browse(cr, uid, ids[0], context=context) + obj_mod = self.pool.get('ir.module.module') + obj_acc_template = self.pool.get('account.account.template') + obj_acc = self.pool.get('account.account') + resource_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'l10n_multilang', 'view_translate_message_wizard') + + company_id = obj_multi.company_id.id + 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] + + # load languages + langs = [] + installed_mids = obj_mod.search(cr, uid, [('state', '=', 'installed')]) + for lang in obj_multi.lang_ids: + langs.append(lang.code) + obj_mod.update_translations(cr, uid, installed_mids, lang.code) + + warn_msg = '' + + # copy account.account translations + 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:] + warn_msg += self.copy_translations(cr, uid, langs, obj_acc_template, 'name', in_ids, obj_acc, out_ids) + + #open new wizard its for displaying warning message + if warn_msg: + res_id = self.pool.get('translate.message').create(cr, uid, {'message': warn_msg}) + return { + 'res_id': res_id, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'translate.message', + 'views': [(resource_id and resource_id[1] or False,'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + } + def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None): res = super(wizard_multi_charts_accounts, self).onchange_chart_template_id(cr, uid, ids, chart_template_id, context=context) installed_lang = self.get_lang(cr, uid, chart_template_id, context=context) diff --git a/addons/l10n_multilang/l10n_multilang.xml b/addons/l10n_multilang/l10n_multilang.xml index 7ad10f487db..008a16cbfb1 100644 --- a/addons/l10n_multilang/l10n_multilang.xml +++ b/addons/l10n_multilang/l10n_multilang.xml @@ -1,6 +1,11 @@ + + + 25 + onskip + view.wizard.multi.chart @@ -22,6 +27,23 @@ + + + Translation Process + translate.message + form + +
+ + + + + +