1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2013 Acysos S.L. (http://acysos.com) All Rights Reserved
5
# Ignacio Ibeas Izquierdo <ignacio@acysos.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import osv, fields
23
from tools.translate import _
25
class account_tax_code_template(osv.osv):
27
_inherit = 'account.tax.code.template'
30
'mod340':fields.boolean("Include in mod340"),
33
account_tax_code_template()
35
class account_tax_code(osv.osv):
37
_inherit = 'account.tax.code'
40
'mod340':fields.boolean("Include in mod340"),
45
class wizard_update_charts_accounts(osv.osv_memory):
46
_inherit = 'wizard.update.charts.accounts'
48
def _find_tax_codes(self, cr, uid, wizard, context=None):
50
Search for, and load, tax code templates to create/update.
54
tax_code_template_mapping = {}
56
tax_code_templ_obj = self.pool.get('account.tax.code.template')
57
tax_code_obj = self.pool.get('account.tax.code')
58
wiz_tax_code_obj = self.pool.get('wizard.update.charts.accounts.tax.code')
60
# Remove previous tax codes
61
wiz_tax_code_obj.unlink(cr, uid, wiz_tax_code_obj.search(cr, uid, []))
64
# Search for new / updated tax codes
66
root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id
67
children_tax_code_template = tax_code_templ_obj.search(cr, uid, [('parent_id', 'child_of', [root_tax_code_id])], order='id')
68
for tax_code_template in tax_code_templ_obj.browse(cr, uid, children_tax_code_template):
69
# Ensure the tax code template is on the map (search for the mapped tax code id).
70
self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template, context)
72
tax_code_id = tax_code_template_mapping.get(tax_code_template.id)
75
wiz_tax_code_obj.create(cr, uid, {
76
'tax_code_id': tax_code_template.id,
77
'update_chart_wizard_id': wizard.id,
80
elif wizard.update_tax_code:
82
# Check the tax code for changes.
86
tax_code = tax_code_obj.browse(cr, uid, tax_code_id, context=context)
88
if tax_code.code != tax_code_template.code:
89
notes += _("The code field is different.\n")
91
if tax_code.info != tax_code_template.info:
92
notes += _("The info field is different.\n")
94
if tax_code.sign != tax_code_template.sign:
95
notes += _("The sign field is different.\n")
97
if tax_code.mod340 != tax_code_template.mod340:
98
notes += _("The Mod 340 field is different.\n")
101
# TODO: We could check other account fields for changes...
105
# Tax code to update.
107
updated_tax_codes += 1
108
wiz_tax_code_obj.create(cr, uid, {
109
'tax_code_id': tax_code_template.id,
110
'update_chart_wizard_id': wizard.id,
112
'update_tax_code_id': tax_code_id,
116
return { 'new': new_tax_codes, 'updated': updated_tax_codes, 'mapping': tax_code_template_mapping }
118
def _update_tax_codes(self, cr, uid, wizard, log, context=None):
120
Search for, and load, tax code templates to create/update.
122
tax_code_obj = self.pool.get('account.tax.code')
124
root_tax_code_id = wizard.chart_template_id.tax_code_root_id.id
127
updated_tax_codes = 0
128
tax_code_template_mapping = {}
130
for wiz_tax_code in wizard.tax_code_ids:
131
tax_code_template = wiz_tax_code.tax_code_id
132
tax_code_name = (root_tax_code_id == tax_code_template.id) and wizard.company_id.name or tax_code_template.name
134
# Ensure the parent tax code template is on the map.
135
self._map_tax_code_template(cr, uid, wizard, tax_code_template_mapping, tax_code_template.parent_id, context)
141
'name': tax_code_name,
142
'code': tax_code_template.code,
143
'info': tax_code_template.info,
144
'parent_id': tax_code_template.parent_id and tax_code_template_mapping.get(tax_code_template.parent_id.id),
145
'company_id': wizard.company_id.id,
146
'sign': tax_code_template.sign,
147
'mod340': tax_code_template.mod340
153
if wiz_tax_code.type == 'new':
155
# Create the tax code
157
tax_code_id = tax_code_obj.create(cr, uid, vals)
158
log.add(_("Created tax code %s.\n") % tax_code_name)
161
elif wizard.update_tax_code and wiz_tax_code.update_tax_code_id:
163
# Update the tax code
165
tax_code_id = wiz_tax_code.update_tax_code_id.id
166
tax_code_obj.write(cr, uid, [tax_code_id], vals)
167
log.add(_("Updated tax code %s.\n") % tax_code_name)
168
updated_tax_codes += 1
171
tax_code_id = wiz_tax_code.update_tax_code_id and wiz_tax_code.update_tax_code_id.id
174
# Store the tax codes on the map
175
tax_code_template_mapping[tax_code_template.id] = tax_code_id
181
if tax_code_template.parent_id and not tax_code_template_mapping.get(tax_code_template.parent_id.id):
182
log.add(_("Tax code %s: The parent tax code %s can not be set.\n") % (tax_code_name, tax_code_template.parent_id.name), True)
185
'new': new_tax_codes,
186
'updated': updated_tax_codes,
187
'mapping': tax_code_template_mapping
190
wizard_update_charts_accounts()
b'\\ No newline at end of file'