13
13
# This program is distributed in the hope that it will be useful,
14
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
16
# GNU Affero General Public License for more details.
18
18
# You should have received a copy of the GNU Affero General Public License
19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
124
124
base_amount += self._get_line_amount_with_sign(line)
125
125
# calcolo % indetraibile
126
126
actual_tax_amount = base_amount * main_tax.amount
127
actual_tax_amount = cur_pool.round(self.cr, self.uid, move.company_id.currency_id, actual_tax_amount)
127
actual_tax_amount = cur_pool.round(
128
self.cr, self.uid, move.company_id.currency_id,
128
130
non_deductible = 0.0
129
131
if abs(actual_tax_amount) != abs(move_line.tax_amount):
130
132
non_deductible = 100
131
133
if move_line.tax_amount:
132
non_deductible = 100 - abs((move_line.tax_amount * 100.0) / actual_tax_amount)
133
non_deductible = cur_pool.round(self.cr, self.uid, move.company_id.currency_id, non_deductible)
134
non_deductible = 100 - abs((
135
move_line.tax_amount * 100.0) / actual_tax_amount)
136
non_deductible = cur_pool.round(
137
self.cr, self.uid, move.company_id.currency_id,
134
139
# calcolo il totale dell'operazione
135
140
invoice_amount_total = self._move_total(move_line)
136
141
if self._is_refund(move_line):
138
143
str_non_deductible = str(non_deductible).split('.')[0]
140
145
'tax_percentage': main_tax.amount and str(
141
main_tax.amount * 100).split('.')[0] or move_line.tax_code_id.name,
146
main_tax.amount * 100).split('.')[0] or
147
move_line.tax_code_id.name,
142
148
'tax_code_name': move_line.tax_code_id.name,
143
149
'base': base_amount,
144
150
'amount': actual_tax_amount,
145
'non_deductible': str_non_deductible != '0' and str_non_deductible or '',
151
'non_deductible': str_non_deductible != '0' and
152
str_non_deductible or '',
147
154
'amount_total': invoice_amount_total,
149
156
res.append(tax_item)
150
totale_iva += cur_pool.round(self.cr, self.uid, move.company_id.currency_id,
157
totale_iva += cur_pool.round(
158
self.cr, self.uid, move.company_id.currency_id,
151
159
(actual_tax_amount * (100 - non_deductible) * 0.01))
152
160
invoice_amount_untaxed += base_amount
153
totale_iva_inded += cur_pool.round(self.cr, self.uid, move.company_id.currency_id,
161
totale_iva_inded += cur_pool.round(
162
self.cr, self.uid, move.company_id.currency_id,
154
163
(actual_tax_amount * non_deductible * 0.01))
158
if tax_item['tax_code_name'] not in self.localcontext['tax_codes']:
159
self.localcontext['tax_codes'][tax_item['tax_code_name']] = {
167
if tax_item['tax_code_name'] not in self.localcontext[
169
self.localcontext['tax_codes'][tax_item[
170
'tax_code_name']] = {
160
171
'base': tax_item['base'],
161
172
'amount': tax_item['amount'],
164
self.localcontext['tax_codes'][tax_item['tax_code_name']]['base'] += tax_item['base']
165
self.localcontext['tax_codes'][tax_item['tax_code_name']]['amount'] += tax_item['amount']
175
self.localcontext['tax_codes'][tax_item[
176
'tax_code_name']]['base'] += tax_item['base']
177
self.localcontext['tax_codes'][tax_item[
178
'tax_code_name']]['amount'] += tax_item['amount']
167
self.localcontext['totali']['totale_operazioni'] += invoice_amount_total
168
self.localcontext['totali']['totale_imponibili'] += invoice_amount_untaxed
180
self.localcontext['totali'][
181
'totale_operazioni'] += invoice_amount_total
182
self.localcontext['totali'][
183
'totale_imponibili'] += invoice_amount_untaxed
169
184
self.localcontext['totali']['totale_iva'] += totale_iva
170
185
self.localcontext['totali']['totale_iva_inded'] += totale_iva_inded
185
200
if inv_tax.base_code_id and inv_tax.tax_code_id:
186
201
account_tax = tax_obj.get_account_tax(inv_tax)
187
202
if account_tax.exclude_from_registries:
188
self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
189
_('The tax %s is excluded from registries') % account_tax.name)
203
self.logger.notifyChannel("l10n_it_vat_registries",
205
'The tax %s is excluded from registries')
191
208
account_tax_amount = account_tax.amount
192
209
invoice_amount_total = self._get_invoice_amount_total(invoice)
193
invoice_amount_untaxed = self._get_invoice_amount_untaxed(invoice)
194
amount = self._get_amount_with_sign(inv_tax.tax_amount, inv_tax.amount)
195
base = self._get_amount_with_sign(inv_tax.base_amount, inv_tax.base)
210
invoice_amount_untaxed = self._get_invoice_amount_untaxed(
212
amount = self._get_amount_with_sign(inv_tax.tax_amount,
214
base = self._get_amount_with_sign(inv_tax.base_amount,
196
216
# calcolo le note di credito con segno invertito
197
217
if invoice.type in ('in_refund', 'out_refund'):
201
221
invoice_amount_total = -invoice_amount_total
203
223
'tax_percentage': account_tax_amount and str(
204
account_tax_amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
224
account_tax_amount * 100).split('.')[0] or
225
inv_tax.tax_code_id.name,
206
'amount': amount, #in valuta base
227
'amount': amount, # in valuta base
207
228
'non_deductible': 0.0,
209
230
'amount_total': invoice_amount_total,
215
236
elif inv_tax.tax_code_id:
216
237
tax = tax_obj.get_main_tax(tax_obj.get_account_tax(inv_tax))
217
238
if tax.exclude_from_registries:
218
self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
239
self.logger.notifyChannel("l10n_it_vat_registries",
219
241
_('The tax %s is excluded from registries') % tax.name)
221
243
for inv_tax_2 in invoice.tax_line:
222
244
if inv_tax_2.base_code_id and not inv_tax_2.tax_code_id:
223
base_tax = tax_obj.get_main_tax(tax_obj.get_account_tax(inv_tax_2))
245
base_tax = tax_obj.get_main_tax(
246
tax_obj.get_account_tax(inv_tax_2))
224
247
# Se hanno la stessa tassa
225
248
if base_tax.id == tax.id:
226
249
# Uso il valore assoluto perchè riferendosi
227
250
# alla stessa imposta non ci possono essere
228
251
# segni differenti
229
252
non_deductible = (abs(inv_tax_2.base_amount) /
230
(abs(inv_tax.base_amount) + abs(inv_tax_2.base_amount)) * 100)
231
invoice_amount_total = self._get_invoice_amount_total(invoice)
232
invoice_amount_untaxed = self._get_invoice_amount_untaxed(invoice)
233
amount = self._get_amount_with_sign(inv_tax.tax_amount, inv_tax.amount)
234
base = self._get_amount_with_sign(inv_tax.base_amount, inv_tax.base)
235
amount2 = self._get_amount_with_sign(inv_tax_2.tax_amount, inv_tax_2.amount)
236
base2 = self._get_amount_with_sign(inv_tax_2.base_amount, inv_tax_2.base)
253
(abs(inv_tax.base_amount) + abs(
254
inv_tax_2.base_amount)) * 100)
255
invoice_amount_total = \
256
self._get_invoice_amount_total(invoice)
257
invoice_amount_untaxed = \
258
self._get_invoice_amount_untaxed(invoice)
259
amount = self._get_amount_with_sign(
260
inv_tax.tax_amount, inv_tax.amount)
261
base = self._get_amount_with_sign(
262
inv_tax.base_amount, inv_tax.base)
263
amount2 = self._get_amount_with_sign(
264
inv_tax_2.tax_amount, inv_tax_2.amount)
265
base2 = self._get_amount_with_sign(
266
inv_tax_2.base_amount, inv_tax_2.base)
237
267
# calcolo le note di credito con segno invertito
238
268
if invoice.type in ('in_refund', 'out_refund'):
241
271
amount2 = -amount2
243
invoice_amount_untaxed = -invoice_amount_untaxed
273
invoice_amount_untaxed = \
274
-invoice_amount_untaxed
244
275
invoice_amount_total = -invoice_amount_total
246
277
'tax_percentage': base_tax.amount and str(
247
base_tax.amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
278
base_tax.amount * 100).split('.')[0] or
279
inv_tax.tax_code_id.name,
248
280
'base': base + base2,
249
281
'amount': amount + amount2,
250
'non_deductible': non_deductible and str(non_deductible).split('.')[0] or '',
282
'non_deductible': non_deductible and str(
283
non_deductible).split('.')[0] or '',
252
285
'amount_total': invoice_amount_total,
259
292
elif not inv_tax.tax_code_id and not inv_tax.base_code_id:
260
self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
293
self.logger.notifyChannel("l10n_it_vat_registries",
261
295
_('The tax %s has no tax codes') % inv_tax.name)
264
if tax_item['tax_percentage'] not in self.localcontext['tax_codes']:
265
self.localcontext['tax_codes'][tax_item['tax_percentage']] = {
298
if tax_item['tax_percentage'] not in self.localcontext[
300
self.localcontext['tax_codes'][tax_item[
301
'tax_percentage']] = {
266
302
'base': tax_item['base'],
267
303
'amount': tax_item['amount'],
270
self.localcontext['tax_codes'][tax_item['tax_percentage']]['base'] += tax_item['base']
271
self.localcontext['tax_codes'][tax_item['tax_percentage']]['amount'] += tax_item['amount']
306
self.localcontext['tax_codes'][tax_item[
307
'tax_percentage']]['base'] += tax_item['base']
308
self.localcontext['tax_codes'][tax_item[
309
'tax_percentage']]['amount'] += tax_item['amount']
273
self.localcontext['totali']['totale_operazioni'] += invoice_amount_total
274
self.localcontext['totali']['totale_imponibili'] += invoice_amount_untaxed
311
self.localcontext['totali'][
312
'totale_operazioni'] += invoice_amount_total
313
self.localcontext['totali'][
314
'totale_imponibili'] += invoice_amount_untaxed
275
315
# da analizzare self.totale_variazioni += invoice.amount_total
276
316
self.localcontext['totali']['totale_iva'] += totale_iva
277
317
self.localcontext['totali']['totale_iva_inded'] += totale_iva_inded