From 38a47ab93ebdabee888a06882364591b1f7cafb1 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Tue, 2 Aug 2011 15:42:00 +0530 Subject: [PATCH 1/6] [ADD]: account: l10n fullness and inheritancy: create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields bzr revid: ron@tinyerp.com-20110802101200-n7sngrvbi4ftme12 --- addons/account/account.py | 85 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index 9a8854aac76..1512e7807a6 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -23,9 +23,11 @@ import time from datetime import datetime from dateutil.relativedelta import relativedelta from operator import itemgetter +from os.path import join as opj import netsvc import pooler +import tools from osv import fields, osv import decimal_precision as dp from tools.translate import _ @@ -2684,7 +2686,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): purchase_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id" , "=", ids[0]), ('type_tax_use', 'in', ('purchase','all'))], order="sequence") res.update({'purchase_tax': purchase_tax_ids and purchase_tax_ids[0] or False}) - return res def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): @@ -2717,6 +2718,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') obj_acc_tax = self.pool.get('account.tax') + obj_tax_temp = self.pool.get('account.tax.template') obj_journal = self.pool.get('account.journal') obj_acc_template = self.pool.get('account.account.template') obj_fiscal_position_template = self.pool.get('account.fiscal.position.template') @@ -2737,6 +2739,87 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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: + fp = tools.file_open(opj('account', 'configurable_account_chart.xml')) + tools.convert_xml_import(cr, 'account', fp, {}, 'init', True, None) + fp.close() + s_tax = (obj_multi.sale_tax_rate/100) + p_tax = (obj_multi.purchase_tax_rate/100) + pur_temp_tax = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_base_purchases') + pur_temp_tax_id = pur_temp_tax and pur_temp_tax[1] or False + + pur_temp_tax_paid = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_output') + pur_temp_tax_paid_id = pur_temp_tax_paid and pur_temp_tax_paid[1] or False + + sale_temp_tax = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_base_sales') + sale_temp_tax_id = sale_temp_tax and sale_temp_tax[1] or False + + sale_temp_tax_paid = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_input') + sale_temp_tax_paid_id = sale_temp_tax_paid and sale_temp_tax_paid[1] or False + + chart_temp_id = obj_multi.chart_template_id.id or False + if s_tax * 100 > 0.0: + tax_account_ids = obj_acc_template.search(cr, uid, [('name', '=', 'Tax Received')], context=context) + sales_tax_account_id = tax_account_ids and tax_account_ids[0] or False + vals_tax_code_temp = { + 'name': _('TAX %s%%') % (s_tax*100), + 'code': _('TAX %s%%') % (s_tax*100), + 'parent_id': sale_temp_tax_id + } + new_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_tax_code_temp, context=context) + vals_paid_tax_code_temp = { + 'name': _('TAX Received %s%%') % (s_tax*100), + 'code': _('TAX Received %s%%') % (s_tax*100), + 'parent_id': sale_temp_tax_paid_id + } + new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_paid_tax_code_temp, context=context) + sales_tax_temp = obj_tax_temp.create(cr, uid, { + 'name': _('TAX %s%%') % (s_tax*100), + 'description': _('TAX %s%%') % (s_tax*100), + 'amount': s_tax, + 'base_code_id': new_tax_code_temp, + 'tax_code_id': new_paid_tax_code_temp, + 'ref_base_code_id': new_tax_code_temp, + 'ref_tax_code_id': new_paid_tax_code_temp, + 'type_tax_use': 'sale', + 'type': 'percent', + 'sequence': 0, + 'account_collected_id': sales_tax_account_id, + 'account_paid_id': sales_tax_account_id, + 'chart_template_id': chart_temp_id, + }, context=context) + if p_tax * 100 > 0.0: + tax_account_ids = obj_acc_template.search(cr, uid, [('name', '=', 'Tax Paid')], context=context) + purchase_tax_account_id = tax_account_ids and tax_account_ids[0] or False + vals_tax_code_temp = { + 'name': _('TAX %s%%') % (p_tax*100), + 'code': _('TAX %s%%') % (p_tax*100), + 'parent_id': pur_temp_tax_id + } + new_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_tax_code_temp, context=context) + vals_paid_tax_code_temp = { + 'name': _('TAX Paid %s%%') % (p_tax*100), + 'code': _('TAX Paid %s%%') % (p_tax*100), + 'parent_id': pur_temp_tax_paid_id + } + new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_paid_tax_code_temp, context=context) + purchase_tax_temp = obj_tax_temp.create(cr, uid, { + 'name': _('TAX %s%%') % (p_tax*100), + 'description': _('TAX %s%%') % (p_tax*100), + 'amount': p_tax, + 'base_code_id': new_tax_code_temp, + 'tax_code_id': new_paid_tax_code_temp, + 'ref_base_code_id': new_tax_code_temp, + 'ref_tax_code_id': new_paid_tax_code_temp, + 'type_tax_use': 'purchase', + 'type': 'percent', + 'sequence': 0, + 'account_collected_id': purchase_tax_account_id, + 'account_paid_id': purchase_tax_account_id, + 'chart_template_id': chart_temp_id, + }, context=context) + #create all the tax code children_tax_code_template = obj_tax_code_template.search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id') children_tax_code_template.sort() From 5ad2f2dbb387ca1f10393c4b9fd3bc8a02604d68 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 3 Aug 2011 11:55:49 +0530 Subject: [PATCH 2/6] [IMP]: account: l10n fullness and inheritancy: flexible code to load/create taxes based on value of Complete Set Of Tax bzr revid: ron@tinyerp.com-20110803062549-95hi97dclowu01ev --- addons/account/account.py | 51 +++------------------------------------ 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 1512e7807a6..78b521eea40 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -23,7 +23,6 @@ import time from datetime import datetime from dateutil.relativedelta import relativedelta from operator import itemgetter -from os.path import join as opj import netsvc import pooler @@ -2741,39 +2740,13 @@ class wizard_multi_charts_accounts(osv.osv_memory): # create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields if not obj_multi.complete_tax: - fp = tools.file_open(opj('account', 'configurable_account_chart.xml')) - tools.convert_xml_import(cr, 'account', fp, {}, 'init', True, None) - fp.close() s_tax = (obj_multi.sale_tax_rate/100) p_tax = (obj_multi.purchase_tax_rate/100) - pur_temp_tax = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_base_purchases') - pur_temp_tax_id = pur_temp_tax and pur_temp_tax[1] or False - - pur_temp_tax_paid = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_output') - pur_temp_tax_paid_id = pur_temp_tax_paid and pur_temp_tax_paid[1] or False - - sale_temp_tax = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_base_sales') - sale_temp_tax_id = sale_temp_tax and sale_temp_tax[1] or False - - sale_temp_tax_paid = obj_data.get_object_reference(cr, uid, 'account', 'tax_code_input') - sale_temp_tax_paid_id = sale_temp_tax_paid and sale_temp_tax_paid[1] or False chart_temp_id = obj_multi.chart_template_id.id or False if s_tax * 100 > 0.0: - tax_account_ids = obj_acc_template.search(cr, uid, [('name', '=', 'Tax Received')], context=context) - sales_tax_account_id = tax_account_ids and tax_account_ids[0] or False - vals_tax_code_temp = { - 'name': _('TAX %s%%') % (s_tax*100), - 'code': _('TAX %s%%') % (s_tax*100), - 'parent_id': sale_temp_tax_id - } - new_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_tax_code_temp, context=context) - vals_paid_tax_code_temp = { - 'name': _('TAX Received %s%%') % (s_tax*100), - 'code': _('TAX Received %s%%') % (s_tax*100), - 'parent_id': sale_temp_tax_paid_id - } - new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_paid_tax_code_temp, context=context) + new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (s_tax*100), 'code': _('TAX %s%%') % (s_tax*100)}, context=context) + new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX Received %s%%') % (s_tax*100), 'code': _('TAX Received %s%%') % (s_tax*100)}, context=context) sales_tax_temp = obj_tax_temp.create(cr, uid, { 'name': _('TAX %s%%') % (s_tax*100), 'description': _('TAX %s%%') % (s_tax*100), @@ -2785,25 +2758,11 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type_tax_use': 'sale', 'type': 'percent', 'sequence': 0, - 'account_collected_id': sales_tax_account_id, - 'account_paid_id': sales_tax_account_id, 'chart_template_id': chart_temp_id, }, context=context) if p_tax * 100 > 0.0: - tax_account_ids = obj_acc_template.search(cr, uid, [('name', '=', 'Tax Paid')], context=context) - purchase_tax_account_id = tax_account_ids and tax_account_ids[0] or False - vals_tax_code_temp = { - 'name': _('TAX %s%%') % (p_tax*100), - 'code': _('TAX %s%%') % (p_tax*100), - 'parent_id': pur_temp_tax_id - } - new_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_tax_code_temp, context=context) - vals_paid_tax_code_temp = { - 'name': _('TAX Paid %s%%') % (p_tax*100), - 'code': _('TAX Paid %s%%') % (p_tax*100), - 'parent_id': pur_temp_tax_paid_id - } - new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, vals_paid_tax_code_temp, context=context) + new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (p_tax*100), 'code': _('TAX %s%%') % (p_tax*100)}, context=context) + new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX Paid %s%%') % (p_tax*100), 'code': _('TAX Paid %s%%') % (p_tax*100)}, context=context) purchase_tax_temp = obj_tax_temp.create(cr, uid, { 'name': _('TAX %s%%') % (p_tax*100), 'description': _('TAX %s%%') % (p_tax*100), @@ -2815,8 +2774,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type_tax_use': 'purchase', 'type': 'percent', 'sequence': 0, - 'account_collected_id': purchase_tax_account_id, - 'account_paid_id': purchase_tax_account_id, 'chart_template_id': chart_temp_id, }, context=context) From e79d3ace1a5a9aada227d4333de1c3a19b53b91e Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 3 Aug 2011 16:03:03 +0530 Subject: [PATCH 3/6] [IMP]: account: l10n fullness and inheritancy: Removed duplicate code for loading sales and purchase tax and variables used properly bzr revid: ron@tinyerp.com-20110803103303-r9lxt5hak0ncmcjz --- addons/account/account.py | 56 +++++++++++++++------------------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 78b521eea40..112f60ad4b4 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2740,43 +2740,29 @@ class wizard_multi_charts_accounts(osv.osv_memory): # create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields if not obj_multi.complete_tax: - s_tax = (obj_multi.sale_tax_rate/100) - p_tax = (obj_multi.purchase_tax_rate/100) - + tax_dict = {'sale': obj_multi.sale_tax_rate, 'purchase': obj_multi.purchase_tax_rate} chart_temp_id = obj_multi.chart_template_id.id or False - if s_tax * 100 > 0.0: - new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (s_tax*100), 'code': _('TAX %s%%') % (s_tax*100)}, context=context) - new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX Received %s%%') % (s_tax*100), 'code': _('TAX Received %s%%') % (s_tax*100)}, context=context) - sales_tax_temp = obj_tax_temp.create(cr, uid, { - 'name': _('TAX %s%%') % (s_tax*100), - 'description': _('TAX %s%%') % (s_tax*100), - 'amount': s_tax, - 'base_code_id': new_tax_code_temp, - 'tax_code_id': new_paid_tax_code_temp, - 'ref_base_code_id': new_tax_code_temp, - 'ref_tax_code_id': new_paid_tax_code_temp, - 'type_tax_use': 'sale', - 'type': 'percent', - 'sequence': 0, - 'chart_template_id': chart_temp_id, - }, context=context) - if p_tax * 100 > 0.0: - new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (p_tax*100), 'code': _('TAX %s%%') % (p_tax*100)}, context=context) - new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX Paid %s%%') % (p_tax*100), 'code': _('TAX Paid %s%%') % (p_tax*100)}, context=context) - purchase_tax_temp = obj_tax_temp.create(cr, uid, { - 'name': _('TAX %s%%') % (p_tax*100), - 'description': _('TAX %s%%') % (p_tax*100), - 'amount': p_tax, - 'base_code_id': new_tax_code_temp, - 'tax_code_id': new_paid_tax_code_temp, - 'ref_base_code_id': new_tax_code_temp, - 'ref_tax_code_id': new_paid_tax_code_temp, - 'type_tax_use': 'purchase', - 'type': 'percent', - 'sequence': 0, - 'chart_template_id': chart_temp_id, + for tax_type, value in tax_dict.items(): + tax_name = 'TAX Paid' + if value > 0.0: + if tax_type == 'sale': + tax_name = 'TAX Received' + new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (value), 'code': _('TAX %s%%') % (value)}, context=context) + new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('%s %s%%') % (tax_name, value), 'code': _('%s %s%%') % (tax_name, value)}, context=context) + sales_tax_temp = obj_tax_temp.create(cr, uid, { + 'name': _('TAX %s%%') % (value), + 'description': _('TAX %s%%') % (value), + 'amount': (value/100), + 'base_code_id': new_tax_code_temp, + 'tax_code_id': new_paid_tax_code_temp, + 'ref_base_code_id': new_tax_code_temp, + 'ref_tax_code_id': new_paid_tax_code_temp, + 'type_tax_use': tax_type, + 'type': 'percent', + 'sequence': 0, + 'chart_template_id': chart_temp_id, }, context=context) - + #create all the tax code children_tax_code_template = obj_tax_code_template.search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id') children_tax_code_template.sort() From 64047a7f0799c5ae1609eb7d1a325d809b8d6c8b Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 3 Aug 2011 16:07:51 +0530 Subject: [PATCH 4/6] [IMP]: account: l10n fullness and inheritancy: Removed unnecessary import library and space bzr revid: ron@tinyerp.com-20110803103751-stk3pyd8r5gcu27i --- addons/account/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index 112f60ad4b4..866f3450976 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -26,7 +26,6 @@ from operator import itemgetter import netsvc import pooler -import tools from osv import fields, osv import decimal_precision as dp from tools.translate import _ @@ -2685,6 +2684,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): purchase_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id" , "=", ids[0]), ('type_tax_use', 'in', ('purchase','all'))], order="sequence") res.update({'purchase_tax': purchase_tax_ids and purchase_tax_ids[0] or False}) + return res def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): From 9823ed6a732bc176a018d5907353c7834aeaa18b Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 3 Aug 2011 16:39:10 +0530 Subject: [PATCH 5/6] [IMP]: account: l10n fullness and inheritancy: Improved code bzr revid: ron@tinyerp.com-20110803110910-bw747dlpc74cko1g --- addons/account/account.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 866f3450976..1a8f05546e2 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2741,7 +2741,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): # create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields if not obj_multi.complete_tax: tax_dict = {'sale': obj_multi.sale_tax_rate, 'purchase': obj_multi.purchase_tax_rate} - chart_temp_id = obj_multi.chart_template_id.id or False for tax_type, value in tax_dict.items(): tax_name = 'TAX Paid' if value > 0.0: @@ -2752,7 +2751,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): sales_tax_temp = obj_tax_temp.create(cr, uid, { 'name': _('TAX %s%%') % (value), 'description': _('TAX %s%%') % (value), - 'amount': (value/100), + 'amount': value/100, 'base_code_id': new_tax_code_temp, 'tax_code_id': new_paid_tax_code_temp, 'ref_base_code_id': new_tax_code_temp, @@ -2760,7 +2759,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type_tax_use': tax_type, 'type': 'percent', 'sequence': 0, - 'chart_template_id': chart_temp_id, + 'chart_template_id': obj_multi.chart_template_id.id or False, }, context=context) #create all the tax code From fb3e67988b3d2c426e0046e5adf9dc874de47843 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 3 Aug 2011 17:26:01 +0530 Subject: [PATCH 6/6] [IMP]: account: l10n fullness and inheritancy: Improved code for name bzr revid: ron@tinyerp.com-20110803115601-rw9ri28p3vz6zjmr --- addons/account/account.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 1a8f05546e2..8059d35378a 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2742,10 +2742,8 @@ class wizard_multi_charts_accounts(osv.osv_memory): if not obj_multi.complete_tax: tax_dict = {'sale': obj_multi.sale_tax_rate, 'purchase': obj_multi.purchase_tax_rate} for tax_type, value in tax_dict.items(): - tax_name = 'TAX Paid' + tax_name = tax_type == 'sale' and 'TAX Received' or 'TAX Paid' if value > 0.0: - if tax_type == 'sale': - tax_name = 'TAX Received' new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('TAX %s%%') % (value), 'code': _('TAX %s%%') % (value)}, context=context) new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('%s %s%%') % (tax_name, value), 'code': _('%s %s%%') % (tax_name, value)}, context=context) sales_tax_temp = obj_tax_temp.create(cr, uid, {