Skip to content

Commit

Permalink
porting l10n_it_invoices_data_communication to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati committed May 21, 2021
1 parent 00db6b1 commit 7fc1d70
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 288 deletions.
109 changes: 0 additions & 109 deletions l10n_it_invoices_data_communication/README.rst

This file was deleted.

10 changes: 5 additions & 5 deletions l10n_it_invoices_data_communication/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Copyright 2017 Alessandro Camilli - Openforce
# Copyright 2017-2019 Lorenzo Battistini
# Copyright 2017-2021 Lorenzo Battistini
# Copyright 2019 Glauco Prina - Linkit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "ITA - Comunicazione dati fatture",
"summary": 'Comunicazione dati fatture (c.d. "nuovo spesometro" o '
'"esterometro")',
"version": "12.0.1.3.1",
"version": "14.0.1.0.0",
"category": "Account",
"author": "Openforce di Camilli Alessandro, " "Odoo Community Association (OCA)",
"author": "Openforce di Camilli Alessandro, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-italy",
"license": "AGPL-3",
"depends": [
"account",
"l10n_it_fiscal_document_type",
"l10n_it_codici_carica",
"l10n_it_appointment_code",
"l10n_it_fiscalcode",
"l10n_it_esigibilita_iva",
"l10n_it_vat_payability",
"l10n_it_account_tax_kind",
"l10n_it_account",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from openupgradelib import openupgrade
from psycopg2 import sql

invoice_data = ("comunicazione_dati_iva_escludi",)


@openupgrade.migrate()
def migrate(env, version):
if openupgrade.column_exists(env.cr, "account_move", "old_invoice_id"):
openupgrade.logged_query(
env.cr,
sql.SQL(
"""UPDATE account_move m
SET {}
FROM account_invoice i
WHERE m.old_invoice_id = i.id
"""
).format(
sql.SQL(", ").join(
sql.Composed(
[
sql.Identifier(col),
sql.SQL(" = "),
sql.SQL("i."),
sql.Identifier(col),
]
)
for col in invoice_data
)
),
)

elif openupgrade.table_exists(env.cr, "account_invoice"):
openupgrade.logged_query(
env.cr,
sql.SQL(
"""UPDATE account_move m
SET {}
FROM account_invoice i
WHERE i.move_id = m.id
"""
).format(
sql.SQL(", ").join(
sql.Composed(
[
sql.Identifier(col),
sql.SQL(" = "),
sql.SQL("i."),
sql.Identifier(col),
]
)
for col in invoice_data
)
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version='1.0' encoding='utf-8' ?>
<odoo>
<record id="comunucazione_fatture_multi_company" model="ir.rule">
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from openupgradelib import openupgrade # pylint: disable=W7936


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(
env.cr,
"l10n_it_invoices_data_communication",
"migrations/14.0.1.0.0/noupdate_changes.xml",
)
85 changes: 32 additions & 53 deletions l10n_it_invoices_data_communication/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,60 @@
from odoo.exceptions import ValidationError


class AccountInvoice(models.Model):
_inherit = "account.invoice"
class AccountMove(models.Model):
_inherit = "account.move"

comunicazione_dati_iva_escludi = fields.Boolean(
string="Exclude from invoices communication"
)

def _compute_taxes_in_company_currency(self, vals):
try:
exchange_rate = self.amount_total_signed / self.amount_total_company_signed
exchange_rate = self.amount_total / self.amount_total_signed
except ZeroDivisionError:
exchange_rate = 1
vals["ImponibileImporto"] = vals["ImponibileImporto"] / exchange_rate
vals["Imposta"] = vals["Imposta"] / exchange_rate

def _get_tax_comunicazione_dati_iva(self):
self.ensure_one()
fattura = self
tax_model = self.env["account.tax"]

tax_lines = []
tax_grouped = {}
for tax_line in fattura.tax_line_ids:
tax = tax_line.tax_id
for tax in self.line_ids.mapped("tax_ids"):
base_move_lines = self.line_ids.filtered(
lambda line: tax.id in line.tax_ids.ids
)
base = sum(base_move_lines.mapped("price_unit"))
tax_move_lines = self.line_ids.filtered(
lambda line: tax.id == line.tax_line_id.id
)
imposta = sum(tax_move_lines.mapped("price_unit"))
aliquota = tax.amount
parent = tax_model.search([("children_tax_ids", "in", [tax.id])])
if parent:
main_tax = parent
aliquota = parent.amount
if (
tax.cee_type
and tax.amount < 0
and main_tax.kind_id.code.startswith("N6")
):
continue
else:
main_tax = tax
kind_id = main_tax.kind_id.id
payability = main_tax.payability
imposta = tax_line.amount
base = tax_line.base
if main_tax.id not in tax_grouped:
tax_grouped[main_tax.id] = {
"ImponibileImporto": 0,
"Imposta": imposta,
"Aliquota": aliquota,
"Natura_id": kind_id,
"EsigibilitaIVA": payability,
"Detraibile": 0.0,
}
if fattura.type in ("in_invoice", "in_refund"):
tax_grouped[main_tax.id]["Detraibile"] = 100.0
else:
tax_grouped[main_tax.id]["Imposta"] += imposta
if tax.account_id:
# account_id è valorizzato per la parte detraibile dell'imposta
# In questa tax_line è presente il totale dell'imponibile
# per l'imposta corrente
tax_grouped[main_tax.id]["ImponibileImporto"] += base
kind_id = tax.kind_id.id
payability = tax.payability
tax_grouped[tax.id] = {
"ImponibileImporto": base,
"Imposta": imposta,
"Aliquota": aliquota,
"Natura_id": kind_id,
"EsigibilitaIVA": payability,
"Detraibile": 0.0,
}
if self.move_type in ("in_invoice", "in_refund"):
tax_grouped[tax.id]["Detraibile"] = 100.0
partial_tax = tax.invoice_repartition_line_ids.filtered(
lambda line: line.repartition_type == "tax" and line.account_id
)
if partial_tax:
tax_grouped[tax.id]["Detraibile"] = partial_tax.factor_percent

for tax_id in tax_grouped:
tax = tax_model.browse(tax_id)
vals = tax_grouped[tax_id]
if tax.children_tax_ids:
parte_detraibile = 0.0
for child_tax in tax.children_tax_ids:
if child_tax.account_id:
parte_detraibile = child_tax.amount
break
if vals["Aliquota"] and parte_detraibile:
vals["Detraibile"] = 100 / (vals["Aliquota"] / parte_detraibile)
else:
vals["Detraibile"] = 0.0
vals = self._check_tax_comunicazione_dati_iva(tax, vals)
fattura._compute_taxes_in_company_currency(vals)
self._compute_taxes_in_company_currency(vals)
tax_lines.append((0, 0, vals))

return tax_lines
Expand All @@ -87,13 +66,13 @@ def _check_tax_comunicazione_dati_iva(self, tax, val=None):
if val["Aliquota"] == 0 and not val["Natura_id"]:
raise ValidationError(
_("Please specify exemption kind for tax: {} - Invoice {}").format(
tax.name, self.number or False
tax.name, self.name or False
)
)
if not val["EsigibilitaIVA"]:
raise ValidationError(
_("Please specify VAT payability for tax: {} - Invoice {}").format(
tax.name, self.number or False
tax.name, self.name or False
)
)
return val
Loading

0 comments on commit 7fc1d70

Please sign in to comment.