diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 2122f988d5d..d83ab6b7851 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -98,6 +98,7 @@ module named account_voucher. 'wizard/account_reconcile_view.xml', 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', + 'wizard/account_tax_generate_view.xml', 'project/wizard/project_account_analytic_line_view.xml', 'account_end_fy.xml', 'account_invoice_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index b86f18e696c..30b095a4f17 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2574,6 +2574,65 @@ class account_tax_template(osv.osv): } _order = 'sequence' + def generate_tax(self, cr, uid, tax_templates, tax_code_template_ref, company_id, context=None): + """ + This method generate taxes from templates. + @param cr: A database cursor. + @param uid: ID of the user currently logged in. + @param tax_templates: Tax templates. + @param tax_code_template_ref: Taxcode templates reference. + @param company_id: if tax generated from account multi wizard at that time company_id is wizard company_id field + or logged user company_id. + @param Return: + {'taxes_id': New generated taxes ids, + 'account_dict': Used this reference value for Account Tax, + 'tax_template_ref': Used this reference value for Fiscal Position + } + """ + if context is None: + context = {} + res = {} + todo_dict = {} + tax_template_ref = {} + tax_template_to_tax = {} + for tax in tax_templates: + 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 = 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 + res.update({'taxes_id': tax_template_to_tax, 'account_dict': todo_dict, 'tax_template_ref': tax_template_ref}) + return res + account_tax_template() # Fiscal Position Templates @@ -2719,6 +2778,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): res['fields'][field]['selection'] = template_select return res + def execute(self, cr, uid, ids, context=None): obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') @@ -2740,9 +2800,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 +2844,8 @@ class wizard_multi_charts_accounts(osv.osv_memory): #create all the tax tax_template_to_tax = {} - 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 + tax_templates = [x for x in obj_multi.chart_template_id.tax_template_ids if x.installable] + taxes_ids = obj_tax_temp.generate_tax(cr, uid, tax_templates, tax_code_template_ref, company_id, 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,12 @@ 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: + if obj_multi.sale_tax and taxes_ids['taxes_id']: 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: + models =[('product.product',False)], value=[taxes_ids['taxes_id'][obj_multi.sale_tax.id]]) + if obj_multi.purchase_tax and taxes_ids['taxes_id']: 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]]) + models =[('product.product',False)], value=[taxes_ids['taxes_id'][obj_multi.purchase_tax.id]]) wizard_multi_charts_accounts() diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index caed6fc3977..d7a66186c1e 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -65,6 +65,8 @@ import account_change_currency import account_report_balance_sheet import account_report_profit_loss +import account_tax_generate + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/account_tax_generate.py b/addons/account/wizard/account_tax_generate.py new file mode 100644 index 00000000000..0c3cc0b6857 --- /dev/null +++ b/addons/account/wizard/account_tax_generate.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import osv, fields + +class account_tax_generate(osv.osv_memory): + _name = 'account.tax.generate' + _description = 'Tax Generate' + + def _get_templates(self, cr, uid, context=None): + company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + cr.execute("SELECT description from account_tax where company_id=%s" % (company_id)) + taxes = cr.fetchall() + tax_names = [x[0] for x in taxes] + return self.pool.get('account.tax.template').search(cr, uid, [('installable', '=', False), ('description', 'not in', tax_names)], context=context) + + _columns = { + 'template_ids': fields.many2many('account.tax.template', 'tax_template_rel', 'wizard_id', 'template_id', 'Taxes Template', domain = [('installable','=',False)]), + } + + _defaults = { + 'template_ids': _get_templates, + } + + def tax_generate(self, cr, uid, ids, context=None): + company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + obj_tax_temp = self.pool.get('account.tax.template') + tax_templates = [x for x in self.browse(cr, uid, ids, context=context)[0].template_ids] + taxes_ids = obj_tax_temp.generate_tax(cr, uid, tax_templates, {}, company_id, context=context) + return {} + +account_tax_generate() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/account_tax_generate_view.xml b/addons/account/wizard/account_tax_generate_view.xml new file mode 100644 index 00000000000..180dd79a941 --- /dev/null +++ b/addons/account/wizard/account_tax_generate_view.xml @@ -0,0 +1,37 @@ + + + + + + account.tax.generate.form + account.tax.generate + form + +
+ + + + + +