From 41a2986d8829935e53eed6c325df2601fa6ffbbc Mon Sep 17 00:00:00 2001 From: Korbinian Preisler Date: Thu, 14 May 2009 07:49:56 +0200 Subject: [PATCH] copy translation from template for issue1025 --- account.py | 47 ++++++++++++++++++++++++++++++++++ tax.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 118 insertions(+), 4 deletions(-) diff --git a/account.py b/account.py index e716744a7f..5fcb1fdaaf 100644 --- a/account.py +++ b/account.py @@ -99,6 +99,7 @@ class TypeTemplate(ModelSQL, ModelView): :return: id of the type created ''' type_obj = self.pool.get('account.account.type') + lang_obj = self.pool.get('ir.lang') if template2type is None: template2type = {} @@ -112,6 +113,17 @@ class TypeTemplate(ModelSQL, ModelView): vals['parent'] = parent_id new_id = type_obj.create(cursor, user, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + template.setLang(lang) + data = {} + for field in template._columns.keys(): + if template._columns[field].translate: + data.update({field: template[field]}) + if data: + type_obj.write(cursor, user, new_id, data, context=ctx) template2type[template.id] = new_id else: new_id = template2type[template.id] @@ -240,6 +252,7 @@ class Type(ModelSQL, ModelView): into type. The dictionary is filled with new types ''' template_obj = self.pool.get('account.account.type.template') + lang_obj = self.pool.get('ir.lang') if template2type is None: template2type = {} @@ -252,6 +265,15 @@ class Type(ModelSQL, ModelView): context=context, type=type) if vals: self.write(cursor, user, type.id, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + type.setLang(lang) + data = template_obj._get_type_value(cursor, user, + type.template, context=ctx, type=type) + if data: + self.write(cursor, user, type.id, data, context=ctx) template2type[type.template.id] = type.id for child in type.childs: @@ -389,6 +411,7 @@ class AccountTemplate(ModelSQL, ModelView): :return: id of the account created ''' account_obj = self.pool.get('account.account') + lang_obj = self.pool.get('ir.lang') if template2account is None: template2account = {} @@ -406,6 +429,17 @@ class AccountTemplate(ModelSQL, ModelView): vals['type'] = template2type.get(template.type.id, False) new_id = account_obj.create(cursor, user, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + template.setLang(lang) + data = {} + for field in template._columns.keys(): + if template._columns[field].translate: + data.update({field: template[field]}) + if data: + account_obj.write(cursor, user, new_id, data, context=ctx) template2account[template.id] = new_id else: new_id = template2account[template.id] @@ -872,6 +906,7 @@ class Account(ModelSQL, ModelView): into type. ''' template_obj = self.pool.get('account.account.template') + lang_obj = self.pool.get('ir.lang') if template2account is None: template2account = {} @@ -891,6 +926,15 @@ class Account(ModelSQL, ModelView): False) if vals: self.write(cursor, user, account.id, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + account.setLang(lang) + data = template_obj._get_account_value(cursor, user, + account.template, context=ctx, account=account) + if data: + self.write(cursor, user, account.id, data, context=ctx) template2account[account.template.id] = account.id for child in account.childs: @@ -1747,6 +1791,9 @@ class CreateChartAccount(Wizard): tax_rule_line_template_obj = \ self.pool.get('account.tax.rule.line.template') + context=context.copy() + context['language'] = 'en_US' + account_template = account_template_obj.browse(cursor, user, datas['form']['account_template'], context=context) diff --git a/tax.py b/tax.py index b25b941c59..80a7473da0 100644 --- a/tax.py +++ b/tax.py @@ -30,7 +30,7 @@ class CodeTemplate(ModelSQL, ModelView): _name = 'account.tax.code.template' _description = __doc__ - name = fields.Char('Name', required=True) + name = fields.Char('Name', required=True, translate=True) code = fields.Char('Code') parent = fields.Many2One('account.tax.code.template', 'Parent') childs = fields.One2Many('account.tax.code.template', 'parent', 'Children') @@ -89,6 +89,7 @@ class CodeTemplate(ModelSQL, ModelView): :return: id of the tax code created ''' tax_code_obj = self.pool.get('account.tax.code') + lang_obj = self.pool.get('ir.lang') if template2tax_code is None: template2tax_code = {} @@ -103,6 +104,17 @@ class CodeTemplate(ModelSQL, ModelView): vals['parent'] = parent_id new_id = tax_code_obj.create(cursor, user, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + template.setLang(lang) + data = {} + for field in template._columns.keys(): + if template._columns[field].translate: + data.update({field: template[field]}) + if data: + tax_code_obj.write(cursor, user, new_id, data, context=ctx) template2tax_code[template.id] = new_id else: new_id = template2tax_code[template.id] @@ -122,7 +134,8 @@ class Code(ModelSQL, ModelView): _name = 'account.tax.code' _description = __doc__ - name = fields.Char('Name', size=None, required=True, select=1) + name = fields.Char('Name', size=None, required=True, select=1, + translate=True) code = fields.Char('Code', size=None, select=1) active = fields.Boolean('Active', select=2) company = fields.Many2One('company.company', 'Company', required=True) @@ -257,6 +270,7 @@ class Code(ModelSQL, ModelView): tax code. The dictionary is filled with new tax codes ''' template_obj = self.pool.get('account.tax.code.template') + lang_obj = self.pool.get('ir.lang') if template2tax_code is None: template2tax_code = {} @@ -269,6 +283,15 @@ class Code(ModelSQL, ModelView): code.template, context=context, code=code) if vals: self.write(cursor, user, code.id, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + code.setLang(lang) + data = template_obj._get_tax_code_value(cursor, user, + code.template, context=ctx, code=code) + if data: + self.write(cursor, user, code.id, data, context=ctx) template2tax_code[code.template.id] = code.id for child in code.childs: @@ -466,6 +489,7 @@ class TaxTemplate(ModelSQL, ModelView): :return: id of the tax created ''' tax_obj = self.pool.get('account.tax') + lang_obj = self.pool.get('ir.lang') if template2tax is None: template2tax = {} @@ -509,6 +533,17 @@ class TaxTemplate(ModelSQL, ModelView): vals['credit_note_tax_code'] = False new_id = tax_obj.create(cursor, user, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + template.setLang(lang) + data = {} + for field in template._columns.keys(): + if template._columns[field].translate: + data.update({field: template[field]}) + if data: + tax_obj.write(cursor, user, new_id, data, context=ctx) template2tax[template.id] = new_id else: new_id = template2tax[template.id] @@ -755,6 +790,7 @@ class Tax(ModelSQL, ModelView): The dictionary is filled with new taxes ''' template_obj = self.pool.get('account.tax.template') + lang_obj = self.pool.get('ir.lang') if template2tax is None: template2tax = {} @@ -828,6 +864,15 @@ class Tax(ModelSQL, ModelView): if vals: self.write(cursor, user, tax.id, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + tax.setLang(lang) + data = template_obj._get_tax_value(cursor, user, tax.template, + context=ctx, tax=tax) + if data: + self.write(cursor, user, tax.id, data, context=ctx) template2tax[tax.template.id] = tax.id for child in tax.childs: @@ -855,7 +900,7 @@ class RuleTemplate(ModelSQL, ModelView): 'Tax Rule Template' _name = 'account.tax.rule.template' _description = __doc__ - name = fields.Char('Name', required=True) + name = fields.Char('Name', required=True, translate=True) lines = fields.One2Many('account.tax.rule.line.template', 'rule', 'Lines') account = fields.Many2One('account.account.template', 'Account Template', domain=[('parent', '=', False)], required=True) @@ -897,6 +942,7 @@ class RuleTemplate(ModelSQL, ModelView): :return: id of the tax rule created ''' rule_obj = self.pool.get('account.tax.rule') + lang_obj = self.pool.get('ir.lang') if template2rule is None: template2rule = {} @@ -909,6 +955,17 @@ class RuleTemplate(ModelSQL, ModelView): context=context) vals['company'] = company_id new_id = rule_obj.create(cursor, user, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + template.setLang(lang) + data = {} + for field in template._columns.keys(): + if template._columns[field].translate: + data.update({field: template[field]}) + if data: + rule_obj.write(cursor, user, new_id, data, context=ctx) template2rule[template.id] = new_id else: new_id = template2rule[template.id] @@ -921,7 +978,7 @@ class Rule(ModelSQL, ModelView): 'Tax Rule' _name = 'account.tax.rule' _description = __doc__ - name = fields.Char('Name', required=True) + name = fields.Char('Name', required=True, translate=True) company = fields.Many2One('company.company', 'Company', required=True, select=1, domain="[('id', '=', context.get('company', 0))]") lines = fields.One2Many('account.tax.rule.line', 'rule', 'Lines') @@ -972,6 +1029,7 @@ class Rule(ModelSQL, ModelView): tax rule. The dictionary is filled with new tax rules ''' template_obj = self.pool.get('account.tax.rule.template') + lang_obj = self.pool.get('ir.lang') if template2rule is None: template2rule = {} @@ -984,6 +1042,15 @@ class Rule(ModelSQL, ModelView): rule.template, context=context, rule=rule) if vals: self.write(cursor, user, rule.id, vals, context=context) + ctx = context.copy() + for lang in lang_obj.get_translatable_languages(cursor, user, + context=context): + ctx['language'] = lang + rule.setLang(lang) + data = template_obj._get_tax_rule_value(cursor, user, + rule.template, context=ctx, rule=rule) + if data: + self.write(cursor, user, rule.id, data, context=ctx) template2rule[rule.template.id] = rule.id Rule()