From 358b10dda2a87845fdf1ecf0ac8ec40d80879105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 20 Nov 2008 19:35:06 +0100 Subject: [PATCH] Add update_account_taxes when creating account chart from template --- account.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/account.py b/account.py index f4df7752e4..49553f7bc2 100644 --- a/account.py +++ b/account.py @@ -326,7 +326,6 @@ class AccountTemplate(OSV): res['kind'] = template.kind res['reconcile'] = template.reconcile res['deferral'] = template.deferral - res['taxes'] = [('add', x.id) for x in template.taxes] return res def create_account(self, cursor, user, template, company_id, context=None, @@ -380,6 +379,47 @@ class AccountTemplate(OSV): template2type=template2type, parent_id=new_id)) return new_id + def update_account_taxes(self, cursor, user, template, template2account, + template2tax, context=None, template_done=None): + ''' + Update recursively account taxes based on template. + + :param cursor: the database cursor + :param user: the user id + :param template: the template id or the BrowseRecord of template + used for account creation + :param template2account: a dictionary with template id as key + and account id as value, used to convert template id into + account. + :param template2tax: a dictionary with tax template id as key + and tax id as value, used to convert tax template id into + tax. + :param context: the context + :param template_done: a list of template id already updated. + The list is filled. + ''' + account_obj = self.pool.get('account.account') + + if template2account is None: + template2account = {} + if template2tax is None: + template2tax = {} + if template_done is None: + template_done = [] + + if isinstance(template, (int, long)): + template = self.browse(cursor, user, template, context=context) + + if template.id not in template_done: + account_obj.write(cursor, user, template2account[template.id], { + 'taxes': [('add', template2tax[x.id]) for x in template.taxes], + }, context=context) + template_done.append(template.id) + + for child in template.childs: + self.update_account_taxes(cursor, user, child, template2account, + template2tax, context=context, template_done=template_done) + AccountTemplate() @@ -1570,6 +1610,9 @@ class CreateChartAccount(Wizard): template2account=template2account, context=context, template2tax=template2tax) + account_template_obj.update_account_taxes(cursor, user, + account_template, template2account, template2tax, context=context) + return {'company': datas['form']['company']} def _action_create_properties(self, cursor, user, datas, context=None):