1 # -*- encoding: utf-8 -*-
2 #################################################################################
4 # Copyright (C) 2009 Renato Lima - Akretion #
6 #This program is free software: you can redistribute it and/or modify #
7 #it under the terms of the GNU Affero General Public License as published by #
8 #the Free Software Foundation, either version 3 of the License, or #
9 #(at your option) any later version. #
11 #This program is distributed in the hope that it will be useful, #
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 #GNU General Public License for more details. #
16 #You should have received a copy of the GNU General Public License #
17 #along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 #################################################################################
21 from datetime import datetime, timedelta
22 from dateutil.relativedelta import relativedelta
23 from operator import itemgetter
27 from osv import fields, osv
28 import decimal_precision as dp
29 from tools.misc import currency
30 from tools.translate import _
31 from tools import config
33 class account_tax_code_template(osv.osv):
35 _inherit = 'account.tax.code.template'
37 'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developers to create specific taxes in a custom domain."),
38 'tax_discount': fields.boolean('Discount this Tax in Prince', help="Mark it for (ICMS, PIS e etc.)."),
40 account_tax_code_template()
42 class account_tax_code(osv.osv):
44 _inherit = 'account.tax.code'
46 'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developers to create specific taxes in a custom domain."),
47 'tax_discount': fields.boolean('Discount this Tax in Prince', help="Mark it for (ICMS, PIS e etc.)."),
51 class account_tax_template(osv.osv):
52 _inherit = 'account.tax.template'
54 def get_precision_tax():
55 def change_digit_tax(cr):
56 res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, 1, 'Account')
58 return change_digit_tax
61 'tax_discount': fields.boolean('Discount this Tax in Prince', help="Mark it for (ICMS, PIS e etc.)."),
62 'base_reduction': fields.float('Redution', required=True, digits_compute=get_precision_tax(), help="For taxes of type percentage, enter % ratio between 0-1."),
63 'amount_mva': fields.float('MVA Percent', required=True, digits_compute=get_precision_tax(), help="For taxes of type percentage, enter % ratio between 0-1."),
64 'type': fields.selection( [('percent','Percentage'), ('fixed','Fixed Amount'), ('none','None'), ('code','Python Code'), ('balance','Balance'), ('quantity','Quantity')], 'Tax Type', required=True,
65 help="The computation method for the tax amount."),
72 def onchange_tax_code_id(self, cr, uid, ids, tax_code_id, context=None):
74 result = {'value': {}}
79 obj_tax_code = self.pool.get('account.tax.code.template').browse(cr, uid, tax_code_id)
82 result['value']['tax_discount'] = obj_tax_code.tax_discount
83 result['value']['domain'] = obj_tax_code.domain
87 account_tax_template()
89 class account_tax(osv.osv):
90 _inherit = 'account.tax'
92 def get_precision_tax():
93 def change_digit_tax(cr):
94 res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, 1, 'Account')
96 return change_digit_tax
99 'tax_discount': fields.boolean('Discount this Tax in Prince', help="Mark it for (ICMS, PIS e etc.)."),
100 'base_reduction': fields.float('Redution', required=True, digits_compute=get_precision_tax(), help="Um percentual decimal em % entre 0-1."),
101 'amount_mva': fields.float('MVA Percent', required=True, digits_compute=get_precision_tax(), help="Um percentual decimal em % entre 0-1."),
102 'type': fields.selection( [('percent','Percentage'), ('fixed','Fixed Amount'), ('none','None'), ('code','Python Code'), ('balance','Balance'), ('quantity','Quantity')], 'Tax Type', required=True,
103 help="The computation method for the tax amount."),
110 def onchange_tax_code_id(self, cr, uid, ids, tax_code_id, context=None):
112 result = {'value': {}}
117 obj_tax_code = self.pool.get('account.tax.code').browse(cr, uid, tax_code_id)
120 result['value']['tax_discount'] = obj_tax_code.tax_discount
121 result['value']['domain'] = obj_tax_code.domain
127 class wizard_multi_charts_accounts(osv.osv_memory):
129 _inherit = 'wizard.multi.charts.accounts'
131 def execute(self, cr, uid, ids, context=None):
133 super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context)
135 obj_multi = self.browse(cr, uid, ids[0])
136 obj_acc_tax = self.pool.get('account.tax')
137 obj_acc_tax_tmp = self.pool.get('account.tax.template')
138 obj_acc_cst = self.pool.get('l10n_br_account.cst')
139 obj_acc_cst_tmp = self.pool.get('l10n_br_account.cst.template')
140 obj_tax_code = self.pool.get('account.tax.code')
141 obj_tax_code_tmp = self.pool.get('account.tax.code.template')
144 obj_acc_root = obj_multi.chart_template_id.account_root_id
145 tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id
146 company_id = obj_multi.company_id.id
148 children_tax_code_template = self.pool.get('account.tax.code.template').search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
149 children_tax_code_template.sort()
150 for tax_code_template in self.pool.get('account.tax.code.template').browse(cr, uid, children_tax_code_template, context=context):
151 tax_code_id = self.pool.get('account.tax.code').search(cr, uid, [('code','=',tax_code_template.code),('company_id','=',company_id)])
153 obj_tax_code.write(cr, uid, tax_code_id, {'domain': tax_code_template.domain,'tax_discount': tax_code_template.tax_discount})
155 cst_tmp_ids = self.pool.get('l10n_br_account.cst.template').search(cr, uid, [('tax_code_template_id','=',tax_code_template.id)], order='id')
156 for cst_tmp in self.pool.get('l10n_br_account.cst.template').browse(cr, uid, cst_tmp_ids, context=context):
157 obj_acc_cst.create(cr, uid, {
158 'code': cst_tmp.code,
159 'name': cst_tmp.name,
160 'tax_code_id': tax_code_id[0],
163 tax_ids = self.pool.get('account.tax').search(cr, uid, [('company_id','=',company_id)])
164 for tax in self.pool.get('account.tax').browse(cr, uid, tax_ids, context=context):
166 obj_acc_tax.write(cr, uid, tax.id, {'domain': tax.tax_code_id.domain,'tax_discount': tax.tax_code_id.tax_discount})
168 wizard_multi_charts_accounts()
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: