Skip to content

Commit

Permalink
[MIG] l10n_it_fatturapa_out_welfare: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev committed Oct 18, 2024
1 parent 3ff6c15 commit cd41d67
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 167 deletions.
9 changes: 4 additions & 5 deletions l10n_it_fatturapa_out_welfare/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
"name": "ITA - Fattura elettronica - Cassa previdenziale",
"summary": "Registrazione della cassa previdenziale "
"nelle fatture elettroniche in uscita",
"version": "12.0.1.0.1",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Localization/Italy",
"website": "https://github.com/OCA/l10n-italy",
"author": "TAKOBI, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"account",
"l10n_it_fatturapa",
"l10n_it_fatturapa_out",
"l10n_it_fatturapa_out_wt",
"l10n_it_payment_reason",
],
"data": [
"security/ir.model.access.csv",
"views/account_invoice_line_views.xml",
"views/account_invoice_views.xml",
"views/account_move_views.xml",
"views/invoice_it_template.xml",
"views/welfare_fund_type_amount_views.xml",
],
}
4 changes: 2 additions & 2 deletions l10n_it_fatturapa_out_welfare/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_invoice
from . import account_invoice_line
from . import account_move
from . import account_move_line
from . import welfare_fund_type_amount
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from odoo.exceptions import UserError


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

should_regenerate_welfare_lines = fields.Boolean(
compute="_compute_should_regenerate_welfare_lines",
Expand Down Expand Up @@ -51,10 +51,9 @@ def button_regenerate_welfare_lines(self):
welfare_grouping_lines = self.env[invoice_lines._name].create(
welfare_grouping_lines_values,
)
self.compute_taxes()
return welfare_grouping_lines

def action_invoice_open(self):
def action_post(self):
need_welfare_invoices = self.filtered("should_regenerate_welfare_lines")
if need_welfare_invoices:
raise UserError(
Expand All @@ -64,4 +63,4 @@ def action_invoice_open(self):
)
)
)
return super().action_invoice_open()
return super().action_post()
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from odoo import fields, models


class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

welfare_fund_type_amount_ids = fields.Many2many(
comodel_name="welfare.fund.type.amount",
Expand All @@ -18,15 +18,15 @@ class AccountInvoiceLine(models.Model):
help="Welfare Amount represented by this Invoice Line.",
)
welfare_grouping_invoice_line_ids = fields.Many2many(
comodel_name="account.invoice.line",
comodel_name="account.move.line",
relation="welfare_group_invoice_line_rel",
column1="grouping_line",
column2="grouped_line",
string="Grouping Welfare Invoice Lines",
help="Invoice Lines that represent this Line's Welfare Amount.",
)
welfare_grouped_invoice_line_ids = fields.Many2many(
comodel_name="account.invoice.line",
comodel_name="account.move.line",
relation="welfare_group_invoice_line_rel",
column1="grouped_line",
column2="grouping_line",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def _prepare_grouping_invoice_line(self, invoice_lines):
return {
"name": self.display_name,
"account_id": first_line.account_id.id,
"invoice_line_tax_ids": [
(6, 0, first_line.invoice_line_tax_ids.ids),
"tax_ids": [
(6, 0, first_line.tax_ids.ids),
],
"invoice_id": first_line.invoice_id.id,
"move_id": first_line.move_id.id,
"welfare_grouping_fund_type_amount_id": self.id,
"welfare_grouped_invoice_line_ids": [
(6, 0, invoice_lines.ids),
Expand Down
27 changes: 18 additions & 9 deletions l10n_it_fatturapa_out_welfare/tests/data/IT06363391001_random.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
<DatiGeneraliDocumento>
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2023-01-01</Data>
<Numero>INV/2023/0001</Numero>
<Data>2024-01-01</Data>
<Numero>INV/2024/00001</Numero>
<DatiRitenuta>
<TipoRitenuta>RT02</TipoRitenuta>
<ImportoRitenuta>20.00</ImportoRitenuta>
<ImportoRitenuta>40.00</ImportoRitenuta>
<AliquotaRitenuta>20.00</AliquotaRitenuta>
<CausalePagamento>A</CausalePagamento>
</DatiRitenuta>
Expand All @@ -94,17 +94,17 @@
<DettaglioLinee>
<NumeroLinea>1</NumeroLinea>
<Descrizione>Cabinet with Doors</Descrizione>
<Quantita>1.000</Quantita>
<UnitaMisura>Unit(s)</UnitaMisura>
<Quantita>1.00</Quantita>
<UnitaMisura>Units</UnitaMisura>
<PrezzoUnitario>100.00000</PrezzoUnitario>
<PrezzoTotale>100.00</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
</DettaglioLinee>
<DettaglioLinee>
<NumeroLinea>2</NumeroLinea>
<Descrizione>Cabinet with Doors</Descrizione>
<Quantita>1.000</Quantita>
<UnitaMisura>Unit(s)</UnitaMisura>
<Quantita>1.00</Quantita>
<UnitaMisura>Units</UnitaMisura>
<PrezzoUnitario>100.00000</PrezzoUnitario>
<PrezzoTotale>100.00</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
Expand All @@ -113,17 +113,26 @@
<DettaglioLinee>
<NumeroLinea>3</NumeroLinea>
<Descrizione>Cabinet with Doors</Descrizione>
<Quantita>1.000</Quantita>
<UnitaMisura>Unit(s)</UnitaMisura>
<Quantita>1.00</Quantita>
<UnitaMisura>Units</UnitaMisura>
<PrezzoUnitario>100.00000</PrezzoUnitario>
<PrezzoTotale>100.00</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
<Ritenuta>SI</Ritenuta>
</DettaglioLinee>
<DatiRiepilogo>
<AliquotaIVA>22.00</AliquotaIVA>
<ImponibileImporto>340.00</ImponibileImporto>
<Imposta>74.80</Imposta>
</DatiRiepilogo>
</DatiBeniServizi>
<DatiPagamento>
<CondizioniPagamento>TP02</CondizioniPagamento>
<DettaglioPagamento>
<ModalitaPagamento>MP05</ModalitaPagamento>
<DataScadenzaPagamento>2024-02-29</DataScadenzaPagamento>
<ImportoPagamento>374.80</ImportoPagamento>
</DettaglioPagamento>
</DatiPagamento>
</FatturaElettronicaBody>
</ns1:FatturaElettronica>
150 changes: 87 additions & 63 deletions l10n_it_fatturapa_out_welfare/tests/test_fatturapa_out_welfare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import base64

from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests import Form, tagged

from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import (
FatturaPACommon,
)


@tagged("post_install", "-at_install")
class TestFatturaPAOUTWelfare(FatturaPACommon):
def _get_welfare_amount(self, welfare, amount):
"""
Expand All @@ -30,9 +31,7 @@ def _get_payable_account(self):
payable_account_form = Form(account_model)
payable_account_form.name = "Withholding Credit"
payable_account_form.code = "WTPAY"
payable_account_form.user_type_id = self.env.ref(
"account.data_account_type_payable"
)
payable_account_form.account_type = "liability_payable"
payable_account = payable_account_form.save()
return payable_account

Expand All @@ -46,8 +45,8 @@ def _get_withholding_tax(self, payable_account, receivable_account):
withholding_tax_form.code = "TWT"
withholding_tax_form.account_receivable_id = receivable_account
withholding_tax_form.account_payable_id = payable_account
withholding_tax_form.causale_pagamento_id = self.env.ref(
"l10n_it_causali_pagamento.a"
withholding_tax_form.payment_reason_id = self.env.ref(
"l10n_it_payment_reason.a"
)
withholding_tax_form.payment_term = self.env.ref(
"account.account_payment_term_immediate"
Expand All @@ -71,68 +70,92 @@ def _get_invoice(self):
("state", "=", "open"),
],
)
journals = open_invoices.mapped("journal_id")
journals.update(
open_invoices.button_cancel()

invoice = self.invoice_model.create(
{
"update_posted": True,
"invoice_date": "2024-01-01",
"partner_id": self.res_partner_fatturapa_0.id,
"journal_id": self.sales_journal.id,
"invoice_payment_term_id": self.account_payment_term.id,
"user_id": self.user_demo.id,
"move_type": "out_invoice",
"currency_id": self.EUR.id,
"invoice_line_ids": [
(
0,
0,
{
"product_id": self.product_product_10.id,
"price_unit": 100,
"tax_ids": [(6, 0, [self.tax_22.id])],
"welfare_fund_type_amount_ids": [(5, 0, 0)],
},
),
(
0,
0,
{
"product_id": self.product_product_10.id,
"price_unit": 100,
"tax_ids": [(6, 0, [self.tax_22.id])],
"invoice_line_tax_wt_ids": [
(6, 0, [self.withholding_tax.id])
],
"welfare_fund_type_amount_ids": [
(6, 0, [self.welfare_amount_INPS_10.id])
],
},
),
(
0,
0,
{
"product_id": self.product_product_10.id,
"price_unit": 100,
"tax_ids": [(6, 0, [self.tax_22.id])],
"invoice_line_tax_wt_ids": [
(6, 0, [self.withholding_tax.id])
],
"welfare_fund_type_amount_ids": [
(
6,
0,
[
self.welfare_amount_ENPAM_20.id,
self.welfare_amount_INPS_10.id,
],
)
],
},
),
],
}
)
open_invoices.action_cancel()

date_invoice = "2023-01-01"
self.set_sequences(1, date_invoice)
# Explicitly request the customer invoice form view,
# otherwise the supplier form view is automatically picked up
invoice_form = Form(
self.invoice_model,
"account.invoice_form",
)
invoice_form.partner_id = self.res_partner_fatturapa_0
invoice_form.date_invoice = date_invoice
with invoice_form.invoice_line_ids.new() as invoice_line:
invoice_line.product_id = self.product_product_10
invoice_line.price_unit = 100
invoice_line.invoice_line_tax_ids.clear()
invoice_line.invoice_line_tax_ids.add(
self.tax_22,
)
invoice_line.welfare_fund_type_amount_ids.clear()

with invoice_form.invoice_line_ids.new() as invoice_line:
invoice_line.product_id = self.product_product_10
invoice_line.price_unit = 100
invoice_line.invoice_line_tax_ids.clear()
invoice_line.invoice_line_tax_ids.add(
self.tax_22,
)
invoice_line.welfare_fund_type_amount_ids.clear()
invoice_line.welfare_fund_type_amount_ids.add(
self.welfare_amount_INPS_10,
)
invoice_line.invoice_line_tax_wt_ids.clear()
invoice_line.invoice_line_tax_wt_ids.add(
self.withholding_tax,
)

with invoice_form.invoice_line_ids.new() as invoice_line:
invoice_line.product_id = self.product_product_10
invoice_line.price_unit = 100
invoice_line.invoice_line_tax_ids.clear()
invoice_line.invoice_line_tax_ids.add(
self.tax_22,
)
invoice_line.welfare_fund_type_amount_ids.clear()
invoice_line.welfare_fund_type_amount_ids.add(
self.welfare_amount_ENPAM_20,
)
invoice_line.welfare_fund_type_amount_ids.add(
self.welfare_amount_INPS_10,
)
invoice = invoice_form.save()
return invoice

def setUp(self):
super().setUp()
self.company = self.env.company = self.sales_journal.company_id

# XXX - a company named "YourCompany" alread exists
# we move it out of the way but we should do better here
self.env.company.sudo().search([("name", "=", "YourCompany")]).write(
{"name": "YourCompany_"}
)
self.env.company.name = "YourCompany"
self.env.company.vat = "IT06363391001"
self.env.company.fatturapa_art73 = True
self.env.company.partner_id.street = "Via Milano, 1"
self.env.company.partner_id.city = "Roma"
self.env.company.partner_id.state_id = self.env.ref("base.state_us_2").id
self.env.company.partner_id.zip = "00100"
self.env.company.partner_id.phone = "06543534343"
self.env.company.email = "info@yourcompany.example.com"
self.env.company.partner_id.country_id = self.env.ref("base.it").id
self.env.company.fatturapa_fiscal_position_id = self.env.ref(
"l10n_it_fatturapa.fatturapa_RF01"
).id
self.welfare_amount_INPS_10 = self._get_welfare_amount(
self.env.ref("l10n_it_fatturapa.21"),
10,
Expand All @@ -158,14 +181,15 @@ def test_export_welfare_withholding(self):
# Check that Welfare Lines have to be generated
# before validating the invoice
with self.assertRaises(UserError) as ue:
invoice.action_invoice_open()
invoice.action_post()
exc_message = ue.exception.args[0]
self.assertIn("regenerate Welfare Lines", exc_message)
self.assertIn(invoice.display_name, exc_message)

# Export the Electronic Invoice
invoice._onchange_invoice_line_wt_ids()
invoice.button_regenerate_welfare_lines()
invoice.action_invoice_open()
invoice.action_post()
res = self.run_wizard(invoice.id)
attachment = self.attach_model.browse(res["res_id"])
self.set_e_invoice_file_id(attachment, "IT06363391001_random.xml")
Expand Down
Loading

0 comments on commit cd41d67

Please sign in to comment.