From 30b6eea12d8df70bde2e9a396946e1a712bd6974 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 30 Oct 2013 12:13:03 +0100 Subject: [PATCH 1/4] [FIX] l10n_multilang: remove force_write attribute in process_translations When processing a translation, the module used to replace the original term by the translated value for accounts (only object with force_write=True). This lead to only having the translated version for every user, independent of user's language. On new chart of accounts, will have different account names according to the user preference. Keep argument force_write in API for stability reason (will be removed in trunk) bzr revid: mat@openerp.com-20131030111303-ziusplk330oj9wf4 --- addons/l10n_multilang/l10n_multilang.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index 9596b292ff3..a44c9f82fe4 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -65,20 +65,15 @@ class wizard_multi_charts_accounts(osv.osv_memory): for j in range(len(in_ids)): in_id = in_ids[j] if value[in_id]: - if not force_write: - #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], + #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], }) - else: - #replace the value in the destination object only if it's the user lang - if context.get('lang') == lang: - self.pool.get(out_obj._name).write(cr, uid, out_ids[j], {in_field: value[in_id]}) else: _logger.info('Language: %s. Translation from template: there is no translation available for %s!' %(lang, src[in_id]))#out_obj._name)) return True From ea212a166b68608b8816bb4f8a414eb2fbbb3565 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 31 Oct 2013 11:08:09 +0100 Subject: [PATCH 2/4] [FIX] account: generate the accounts based on templates with untranslated terms (so benefit from translation) bzr revid: mat@openerp.com-20131031100809-p0irwjbq3chxjsd9 --- addons/account/account.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 7834fc6ed1b..dfc16a93547 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -3445,6 +3445,10 @@ class wizard_multi_charts_accounts(osv.osv_memory): all the provided information to create the accounts, the banks, the journals, the taxes, the tax codes, the accounting properties... accordingly for the chosen company. ''' + if not context: + context = {} + # remove the lang to get the untranslated value + ctx = dict(context, lang=None) obj_data = self.pool.get('ir.model.data') ir_values_obj = self.pool.get('ir.values') obj_wizard = self.browse(cr, uid, ids[0]) @@ -3465,10 +3469,10 @@ class wizard_multi_charts_accounts(osv.osv_memory): pass # If the floats for sale/purchase rates have been filled, create templates from them - self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context) + self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=ctx) # Install all the templates objects and generate the real objects - acc_template_ref, taxes_ref, tax_code_ref = self._install_template(cr, uid, obj_wizard.chart_template_id.id, company_id, code_digits=obj_wizard.code_digits, obj_wizard=obj_wizard, context=context) + acc_template_ref, taxes_ref, tax_code_ref = self._install_template(cr, uid, obj_wizard.chart_template_id.id, company_id, code_digits=obj_wizard.code_digits, obj_wizard=obj_wizard, context=ctx) # write values of default taxes for product as super user if obj_wizard.sale_tax and taxes_ref: @@ -3477,7 +3481,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): ir_values_obj.set_default(cr, SUPERUSER_ID, 'product.product', "supplier_taxes_id", [taxes_ref[obj_wizard.purchase_tax.id]], for_all_users=True, company_id=company_id) # Create Bank journals - self._create_bank_journals_from_o2m(cr, uid, obj_wizard, company_id, acc_template_ref, context=context) + self._create_bank_journals_from_o2m(cr, uid, obj_wizard, company_id, acc_template_ref, context=ctx) return {} def _prepare_bank_journal(self, cr, uid, line, current_num, default_account_id, company_id, context=None): From 3a103f8dec09e86a5de315dec70020a4a7020ce8 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 31 Oct 2013 11:44:01 +0100 Subject: [PATCH 3/4] [IMP] l10n_multilang: revert previous change and move it to l10n_multilang, the accounts are now translatable and with the correct source value bzr revid: mat@openerp.com-20131031104401-9tgjzs3hohebtit0 --- addons/account/account.py | 10 +++------- addons/l10n_multilang/l10n_multilang.py | 6 +++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index dfc16a93547..7834fc6ed1b 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -3445,10 +3445,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): all the provided information to create the accounts, the banks, the journals, the taxes, the tax codes, the accounting properties... accordingly for the chosen company. ''' - if not context: - context = {} - # remove the lang to get the untranslated value - ctx = dict(context, lang=None) obj_data = self.pool.get('ir.model.data') ir_values_obj = self.pool.get('ir.values') obj_wizard = self.browse(cr, uid, ids[0]) @@ -3469,10 +3465,10 @@ class wizard_multi_charts_accounts(osv.osv_memory): pass # If the floats for sale/purchase rates have been filled, create templates from them - self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=ctx) + self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context) # Install all the templates objects and generate the real objects - acc_template_ref, taxes_ref, tax_code_ref = self._install_template(cr, uid, obj_wizard.chart_template_id.id, company_id, code_digits=obj_wizard.code_digits, obj_wizard=obj_wizard, context=ctx) + acc_template_ref, taxes_ref, tax_code_ref = self._install_template(cr, uid, obj_wizard.chart_template_id.id, company_id, code_digits=obj_wizard.code_digits, obj_wizard=obj_wizard, context=context) # write values of default taxes for product as super user if obj_wizard.sale_tax and taxes_ref: @@ -3481,7 +3477,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): ir_values_obj.set_default(cr, SUPERUSER_ID, 'product.product', "supplier_taxes_id", [taxes_ref[obj_wizard.purchase_tax.id]], for_all_users=True, company_id=company_id) # Create Bank journals - self._create_bank_journals_from_o2m(cr, uid, obj_wizard, company_id, acc_template_ref, context=ctx) + self._create_bank_journals_from_o2m(cr, uid, obj_wizard, company_id, acc_template_ref, context=context) return {} def _prepare_bank_journal(self, cr, uid, line, current_num, default_account_id, company_id, context=None): diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index a44c9f82fe4..1f09a7ad334 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -79,7 +79,11 @@ class wizard_multi_charts_accounts(osv.osv_memory): return True def execute(self, cr, uid, ids, context=None): - res = super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context=context) + 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) obj_multi = self.browse(cr, uid, ids[0], context=context) company_id = obj_multi.company_id.id From 397cebdf4b61f7a9432ede47f22e9593da94b491 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 31 Oct 2013 11:53:18 +0100 Subject: [PATCH 4/4] [IMP] l10n_multilang: remove force_write from function call, mark parameter as deprecated bzr revid: mat@openerp.com-20131031105318-zkzwdrtbvvmxkzv1 --- addons/l10n_multilang/l10n_multilang.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index 1f09a7ad334..18d8b0ebb6c 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -45,8 +45,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): :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: boolean that depicts if we need to create a translation OR simply replace the actual value - with the translation in the uid's language by doing a write (in case it's TRUE) + :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 @@ -124,7 +123,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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, force_write=True, context=context) + 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') @@ -133,21 +132,21 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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, force_write=False, context=context) + 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 = sorted([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, force_write=False, context=context) + 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, force_write=False, context=context) + return self.process_translations(cr, uid, langs, obj_fiscal_position_template, field, in_ids, obj_fiscal_position, out_ids, context=context) wizard_multi_charts_accounts()