Skip to content

Commit

Permalink
[12.0][IMP] l10n_fatturapa_in, arrotondamento per aliquota iva.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSLabIt authored and TheMule71 committed Jun 9, 2021
1 parent 7e020f2 commit fadb5a0
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 49 deletions.
73 changes: 63 additions & 10 deletions l10n_it_fatturapa_in/models/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
from odoo.exceptions import ValidationError, UserError
from odoo.tools import float_compare
import odoo.addons.decimal_precision as dp

Expand Down Expand Up @@ -43,6 +43,56 @@ class AccountInvoice(models.Model):
e_invoice_received_date = fields.Date(
string='E-Bill Received Date')

@api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount',
'tax_line_ids.amount_rounding', 'currency_id', 'company_id',
'date_invoice', 'type', 'efatt_rounding')
def _compute_amount(self):
super(AccountInvoice, self)._compute_amount()
if self.efatt_rounding != 0:
self.amount_total += self.efatt_rounding
amount_total_company_signed = self.amount_total
if self.currency_id and self.company_id and self.currency_id !=\
self.company_id.currency_id:
currency_id = self.currency_id
amount_total_company_signed = currency_id._convert(
self.amount_total, self.company_id.currency_id,
self.company_id, self.date_invoice or fields.Date.today())
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1
self.amount_total_company_signed = amount_total_company_signed * sign
self.amount_total_signed = self.amount_total * sign

@api.model
def invoice_line_move_line_get(self):
"""Append global rounding move lines"""
res = super().invoice_line_move_line_get()

if self.efatt_rounding != 0:
if self.efatt_rounding > 0:
arrotondamenti_account_id = self.env.user.company_id.\
arrotondamenti_passivi_account_id
if not arrotondamenti_account_id:
raise UserError(_("Round down account is not set "
"in Accounting Settings"))
name = _("Rounding down")
else:
arrotondamenti_account_id = self.env.user.company_id.\
arrotondamenti_attivi_account_id
if not arrotondamenti_account_id:
raise UserError(_("Round up account is not set "
"in Accounting Settings"))
name = _("Rounding up")

res.append({
'type': 'global_rounding',
'name': name,
'price_unit': self.efatt_rounding,
'quantity': 1,
'price': self.efatt_rounding,
'account_id': arrotondamenti_account_id.id,
'invoice_id': self.id,
})
return res

@api.multi
def invoice_validate(self):
for invoice in self:
Expand Down Expand Up @@ -208,29 +258,32 @@ def remove_attachment_link(self):

@api.model
def compute_xml_amount_untaxed(self, FatturaBody):
amount_untaxed = float(
FatturaBody.DatiGenerali.DatiGeneraliDocumento.Arrotondamento
or 0.0)
amount_untaxed = 0.0
for Riepilogo in FatturaBody.DatiBeniServizi.DatiRiepilogo:
rounding = float(Riepilogo.Arrotondamento or 0.0)
amount_untaxed += float(Riepilogo.ImponibileImporto) + rounding
amount_untaxed += float(Riepilogo.ImponibileImporto or 0.0)
return amount_untaxed

@api.model
def compute_xml_amount_total(self, FatturaBody, amount_untaxed, amount_tax):
rounding = float(
FatturaBody.DatiGenerali.DatiGeneraliDocumento.Arrotondamento
or 0.0)
return amount_untaxed + amount_tax + rounding

@api.model
def compute_xml_amount_tax(self, DatiRiepilogo):
amount_tax = 0.0
for Riepilogo in DatiRiepilogo:
amount_tax += float(Riepilogo.Imposta)
amount_tax += float(Riepilogo.Imposta or 0.0)
return amount_tax

def set_einvoice_data(self, fattura):
self.ensure_one()
amount_untaxed = self.compute_xml_amount_untaxed(fattura)
amount_tax = self.compute_xml_amount_tax(
fattura.DatiBeniServizi.DatiRiepilogo)
amount_total = float(
fattura.DatiGenerali.DatiGeneraliDocumento.
ImportoTotaleDocumento or 0.0)
amount_total = self.compute_xml_amount_total(
fattura, amount_untaxed, amount_tax)
reference = fattura.DatiGenerali.DatiGeneraliDocumento.Numero
date_invoice = fields.Date.from_string(
fattura.DatiGenerali.DatiGeneraliDocumento.Data)
Expand Down
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* Roberto Onnis
* Alessio Gerace
* Sergio Zanchetta <https://github.com/primes2h>
* Giovanni Serra <[email protected]>
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ la visibilità delle sezioni ``FatturaElettronicaBody.DatiBeniServizi.DatiRiepil

Pertanto, al fine di ottenere il corretto valore del totale imponibile, i moduli che
avessero ridefinito il metodo ``compute_xml_amount_untaxed`` nel modello ``account.invoice``
dovranno adeguare la chiamata al metodo stesso preoccupandosi di utilizzare come primo parametro l'oggetto ``FatturaElettronicaBody``.
dovranno adeguare la chiamata al metodo stesso preoccupandosi di utilizzare come primo parametro l'oggetto ``FatturaElettronicaBody``.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/tests/data/IT05979361218_013.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2019-05-11</Data>
<Numero>852S1</Numero>
<Numero>A852S1</Numero>
<ImportoTotaleDocumento>34.32</ImportoTotaleDocumento>
<Arrotondamento>-0.35</Arrotondamento>
<Causale>Rif ordine 908</Causale>
Expand Down
94 changes: 94 additions & 0 deletions l10n_it_fatturapa_in/tests/data/IT05979361218_015.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<p:FatturaElettronica versione="FPA12" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd">
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
<IdPaese>IT</IdPaese>
<IdCodice>05979361218</IdCodice>
</IdTrasmittente>
<ProgressivoInvio>006</ProgressivoInvio>
<FormatoTrasmissione>FPA12</FormatoTrasmissione>
<CodiceDestinatario>UFPQ1O</CodiceDestinatario>
</DatiTrasmissione>
<CedentePrestatore>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>05979361218</IdCodice>
</IdFiscaleIVA>
<Anagrafica>
<Denominazione>SOCIETA' ALPHA BETA SRL</Denominazione>
</Anagrafica>
<RegimeFiscale>RF02</RegimeFiscale>
</DatiAnagrafici>
<Sede>
<Indirizzo>VIALE ROMA 543B</Indirizzo>
<CAP>07100</CAP>
<Comune>SASSARI</Comune>
<Provincia>SS</Provincia>
<Nazione>IT</Nazione>
</Sede>
</CedentePrestatore>
<CessionarioCommittente>
<DatiAnagrafici>
<CodiceFiscale>80213330584</CodiceFiscale>
<Anagrafica>
<Denominazione>AMMINISTRAZIONE BETA</Denominazione>
</Anagrafica>
</DatiAnagrafici>
<Sede>
<Indirizzo>VIA TORINO 38-B</Indirizzo>
<CAP>00145</CAP>
<Comune>ROMA</Comune>
<Provincia>RM</Provincia>
<Nazione>IT</Nazione>
</Sede>
</CessionarioCommittente>
</FatturaElettronicaHeader>
<FatturaElettronicaBody xmlns="">
<DatiGenerali>
<DatiGeneraliDocumento>
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2019-05-11</Data>
<Numero>852S1</Numero>
<ImportoTotaleDocumento>34.32</ImportoTotaleDocumento>
<Causale>Rif ordine 908</Causale>
</DatiGeneraliDocumento>
</DatiGenerali>
<DatiBeniServizi>
<DettaglioLinee>
<NumeroLinea>1</NumeroLinea>
<Descrizione>USB4</Descrizione>
<Quantita>1.00</Quantita>
<UnitaMisura>Pz.</UnitaMisura>
<PrezzoUnitario>18.07</PrezzoUnitario>
<PrezzoTotale>18.07</PrezzoTotale>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
</DettaglioLinee>
<DettaglioLinee>
<NumeroLinea>2</NumeroLinea>
<Descrizione>USB</Descrizione>
<Quantita>1.00</Quantita>
<UnitaMisura>Pz.</UnitaMisura>
<PrezzoUnitario>16.60</PrezzoUnitario>
<PrezzoTotale>16.60</PrezzoTotale>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
</DettaglioLinee>
<DatiRiepilogo>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
<Arrotondamento>-0.35</Arrotondamento>
<ImponibileImporto>34.32</ImponibileImporto>
<Imposta>0.00</Imposta>
<EsigibilitaIVA>I</EsigibilitaIVA>
<RiferimentoNormativo>Esenzione Art.8 comma 1 DPR 633/72</RiferimentoNormativo>
</DatiRiepilogo>
</DatiBeniServizi>
</FatturaElettronicaBody>
</p:FatturaElettronica>
2 changes: 0 additions & 2 deletions l10n_it_fatturapa_in/tests/fatturapa_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import base64
import tempfile
from odoo.modules import get_module_resource
Expand Down
23 changes: 20 additions & 3 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,31 @@ def test_24_xml_import(self):
res = self.run_wizard('test24', 'IT05979361218_012.xml')
invoice_id = res.get('domain')[0][2][0]
invoice = self.invoice_model.browse(invoice_id)
self.assertAlmostEqual(invoice.e_invoice_amount_untaxed, 34.32)
self.assertEqual(invoice.e_invoice_amount_tax, 0.0)
self.assertEqual(invoice.e_invoice_amount_total, 34.32)
self.assertEqual(
invoice.inconsistencies,
'Computed amount untaxed 34.32 is different from'
' summary data 34.67')

def test_25_xml_import(self):
res = self.run_wizard('test25', 'IT05979361218_013.xml')
invoice_id = res.get('domain')[0][2][0]
invoice = self.invoice_model.browse(invoice_id)
self.assertAlmostEqual(invoice.e_invoice_amount_untaxed, 34.67)
self.assertEqual(invoice.e_invoice_amount_tax, 0.0)
self.assertEqual(invoice.e_invoice_amount_total, 34.32)
self.assertEqual(invoice.efatt_rounding, -0.35)
invoice.action_invoice_open()
move_line = False
for line in invoice.move_id.line_ids:
if line.account_id.id == self.env.user.\
company_id.arrotondamenti_attivi_account_id.id:
move_line = True
self.assertTrue(move_line)

def test_26_xml_import(self):
res = self.run_wizard('test26', 'IT05979361218_015.xml')
invoice_id = res.get('domain')[0][2][0]
invoice = self.invoice_model.browse(invoice_id)
self.assertAlmostEqual(invoice.e_invoice_amount_untaxed, 34.32)
self.assertEqual(invoice.e_invoice_amount_tax, 0.0)
self.assertEqual(invoice.e_invoice_amount_total, 34.32)
Expand Down
5 changes: 4 additions & 1 deletion l10n_it_fatturapa_in/views/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<field name="analytic_tag_ids" position="after">
<field name="admin_ref"/>
</field>
<field name="amount_tax" position="after">
<field name="efatt_rounding" widget="monetary" attrs="{'invisible': [('efatt_rounding', '=', 0)]}"/>
</field>
<xpath expr="//notebook" position="inside">
<page string="E-bill Inconsistencies" attrs="{'invisible': [('fatturapa_attachment_in_id', '=', False)]}">
<group>
Expand Down Expand Up @@ -313,7 +316,7 @@
</group>
<group>
<group string="General Data">
<field name="efatt_rounding"/>
<field name="efatt_rounding" widget="monetary"/>
<field name="art73"/>
</group>
</group>
Expand Down
Loading

0 comments on commit fadb5a0

Please sign in to comment.