diff --git a/addons/account/account.py b/addons/account/account.py index f7301e0b983..e3406aa83a5 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2719,7 +2719,67 @@ class wizard_multi_charts_accounts(osv.osv_memory): res['fields'][field]['selection'] = template_select return res + def generate_tax(self, cr, uid, ids, tax_templates_load, tax_code_template_ref, context=None): + if context is None: + context = {} + res = {} + todo_dict = {} + tax_template_ref = {} + tax_template_to_tax = {} + company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + if not context.get('false_tax_template'): + obj_multi = self.browse(cr, uid, ids[0]) + company_id = obj_multi.company_id.id + ir_values_obj = self.pool.get('ir.values') + for tax in tax_templates_load: +# #create it + vals_tax = { + 'name':tax.name, + 'sequence': tax.sequence, + 'amount':tax.amount, + 'type':tax.type, + 'applicable_type': tax.applicable_type, + 'domain':tax.domain, + 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, + 'child_depend': tax.child_depend, + 'python_compute': tax.python_compute, + 'python_compute_inv': tax.python_compute_inv, + 'python_applicable': tax.python_applicable, + 'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False, + 'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False, + 'base_sign': tax.base_sign, + 'tax_sign': tax.tax_sign, + 'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False, + 'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False, + 'ref_base_sign': tax.ref_base_sign, + 'ref_tax_sign': tax.ref_tax_sign, + 'include_base_amount': tax.include_base_amount, + 'description':tax.description, + 'company_id': self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id, + 'type_tax_use': tax.type_tax_use, + 'price_include': tax.price_include + } + new_tax = self.pool.get('account.tax').create(cr, uid, vals_tax) + tax_template_to_tax[tax.id] = new_tax + #as the accounts have not been created yet, we have to wait before filling these fields + todo_dict[new_tax] = { + 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False, + 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False, + } + tax_template_ref[tax.id] = new_tax + if not context.get('false_tax_template'): + if obj_multi.sale_tax and tax_template_to_tax: + ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id, + models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]]) + if obj_multi.purchase_tax and tax_template_to_tax: + ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id, + models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]]) + res.update({'taxes_id': tax_template_to_tax, 'account_dict': todo_dict, 'tax_template_ref': tax_template_ref}) + return res + def execute(self, cr, uid, ids, context=None): + if context is None: + context = {} obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') obj_acc_tax = self.pool.get('account.tax') @@ -2732,7 +2792,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): analytic_journal_obj = self.pool.get('account.analytic.journal') obj_tax_code = self.pool.get('account.tax.code') obj_tax_code_template = self.pool.get('account.tax.code.template') - ir_values_obj = self.pool.get('ir.values') # Creating Account obj_acc_root = obj_multi.chart_template_id.account_root_id tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id @@ -2740,9 +2799,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #new code acc_template_ref = {} - tax_template_ref = {} tax_code_template_ref = {} - todo_dict = {} # create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields if not obj_multi.complete_tax: @@ -2786,44 +2843,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): #create all the tax tax_template_to_tax = {} + context.update({'false_tax_template': False}) tax_templates_load = [x for x in obj_multi.chart_template_id.tax_template_ids if x.installable] - #Tax template must be installable True to create Tax object - for tax in tax_templates_load: - #create it - vals_tax = { - 'name':tax.name, - 'sequence': tax.sequence, - 'amount':tax.amount, - 'type':tax.type, - 'applicable_type': tax.applicable_type, - 'domain':tax.domain, - 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, - 'child_depend': tax.child_depend, - 'python_compute': tax.python_compute, - 'python_compute_inv': tax.python_compute_inv, - 'python_applicable': tax.python_applicable, - 'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False, - 'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False, - 'base_sign': tax.base_sign, - 'tax_sign': tax.tax_sign, - 'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False, - 'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'include_base_amount': tax.include_base_amount, - 'description':tax.description, - 'company_id': company_id, - 'type_tax_use': tax.type_tax_use, - 'price_include': tax.price_include - } - new_tax = obj_acc_tax.create(cr, uid, vals_tax) - tax_template_to_tax[tax.id] = new_tax - #as the accounts have not been created yet, we have to wait before filling these fields - todo_dict[new_tax] = { - 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False, - 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False, - } - tax_template_ref[tax.id] = new_tax + taxes_ids = self.generate_tax(cr, uid, ids, tax_templates_load, tax_code_template_ref, context=context) #deactivate the parent_store functionnality on account_account for rapidity purpose ctx = context and context.copy() or {} ctx['defer_parent_store_computation'] = True @@ -2861,7 +2883,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #reactivate the parent_store functionnality on account_account obj_acc._parent_store_compute(cr) - for key,value in todo_dict.items(): + for key,value in taxes_ids['account_dict'].items(): if value['account_collected_id'] or value['account_paid_id']: obj_acc_tax.write(cr, uid, [key], { 'account_collected_id': acc_template_ref.get(value['account_collected_id'], False), @@ -3085,8 +3107,8 @@ class wizard_multi_charts_accounts(osv.osv_memory): for tax in position.tax_ids: vals_tax = { - 'tax_src_id': tax_template_ref[tax.tax_src_id.id], - 'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False, + 'tax_src_id': taxes_ids['tax_template_ref'][tax.tax_src_id.id], + 'tax_dest_id': tax.tax_dest_id and taxes_ids['tax_template_ref'][tax.tax_dest_id.id] or False, 'position_id': new_fp, } obj_tax_fp.create(cr, uid, vals_tax) @@ -3098,12 +3120,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'position_id': new_fp, } obj_ac_fp.create(cr, uid, vals_acc) - if obj_multi.sale_tax and tax_template_to_tax: - ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id, - models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]]) - if obj_multi.purchase_tax and tax_template_to_tax: - ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id, - models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]]) wizard_multi_charts_accounts() diff --git a/addons/account/wizard/account_tax_generate.py b/addons/account/wizard/account_tax_generate.py index 2ce7f82f471..8daa8cb4320 100644 --- a/addons/account/wizard/account_tax_generate.py +++ b/addons/account/wizard/account_tax_generate.py @@ -37,35 +37,10 @@ class account_tax_generate(osv.osv_memory): } def tax_generate(self, cr, uid, ids, context=None): - for tax in self.browse(cr, uid, ids, context=context)[0].template_ids: - vals_tax = { - 'name':tax.name, - 'sequence': tax.sequence, - 'amount':tax.amount, - 'type':tax.type, - 'applicable_type': tax.applicable_type, - 'domain':tax.domain, - 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, - 'child_depend': tax.child_depend, - 'python_compute': tax.python_compute, - 'python_compute_inv': tax.python_compute_inv, - 'python_applicable': tax.python_applicable, - 'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False, - 'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False, - 'base_sign': tax.base_sign, - 'tax_sign': tax.tax_sign, - 'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False, - 'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'include_base_amount': tax.include_base_amount, - 'description':tax.description, - 'company_id': self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id, - 'type_tax_use': tax.type_tax_use, - 'price_include': tax.price_include - } - new_tax = self.pool.get('account.tax').create(cr, uid, vals_tax) - self.pool.get('account.tax.template').write(cr, uid , [tax.id], {'installable': True}) + context.update({'false_tax_template': True}) + tax_templates_load = [x for x in self.browse(cr, uid, ids, context=context)[0].template_ids] + taxes_ids = self.pool.get('wizard.multi.charts.accounts').generate_tax(cr, uid, ids, tax_templates_load, {}, context=context) + self.pool.get('account.tax.template').write(cr, uid , taxes_ids['taxes_id'].keys(), {'installable': True}) return {} account_tax_generate()