Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] [MIG] l10n_it_fatturapa_out_welfare #4410

Open
wants to merge 5 commits into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions l10n_it_fatturapa_out_welfare/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
===============================================
ITA - Fattura elettronica - Cassa previdenziale
===============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:39c47c12e384ba9f8bdfce9c52ff9edc83401c89607db51ba5d36b480121add3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_fatturapa_out_welfare
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-l10n_it_fatturapa_out_welfare
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

**Italiano**

Aggiungere la cassa previdenziale alla fattura e alla fattura
elettronica.

**English**

Add Welfare Amount to Invoice and Electronic Invoice.

**Table of contents**

.. contents::
:local:

Configuration
=============

**Italiano**

In Fatturazione > Configurazione > Contabilità > Fiscalità italiana >
Fatturazione elettronica > Importi cassa previdenziale, creare le casse
previdenziali.

**English**

In Accounting > Configuration > Accounting > Italian Localization >
Electronic invoicing > Welfare Fund Type Amounts, create the welfare
amounts.

Usage
=====

**Italiano**

Nella fattura, impostare le casse previdenziali configurate e cliccare
su "Genera righe cassa previdenziale".

**English**

In the invoice, set the configured welfares and click on "Generate
Welfare Lines".

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_fatturapa_out_welfare%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* TAKOBI

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_fatturapa_out_welfare>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions l10n_it_fatturapa_out_welfare/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizards
24 changes: 24 additions & 0 deletions l10n_it_fatturapa_out_welfare/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "ITA - Fattura elettronica - Cassa previdenziale",
"summary": "Registrazione della cassa previdenziale "
"nelle fatture elettroniche in uscita",
"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_out_wt",
"l10n_it_payment_reason",
],
"data": [
"security/ir.model.access.csv",
"views/account_move_views.xml",
"views/invoice_it_template.xml",
"views/welfare_fund_type_amount_views.xml",
],
}
177 changes: 177 additions & 0 deletions l10n_it_fatturapa_out_welfare/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_it_fatturapa_out_welfare
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-08-19 13:06+0000\n"
"PO-Revision-Date: 2023-04-26 16:05+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: \n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.14.1\n"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__administration_reference
msgid "Administration Reference"
msgstr "Riferimento amministrativo"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__amount
msgid "Amount"
msgstr "Importo"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__create_uid
msgid "Created by"
msgstr "Creato da"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__create_date
msgid "Created on"
msgstr "Creato il"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: l10n_it_fatturapa_out_welfare
#: model_terms:ir.ui.view,arch_db:l10n_it_fatturapa_out_welfare.invoice_form
msgid ""
"Existing Grouping Welfare Invoice Lines will be deleted, and new ones will "
"be created."
msgstr ""
"Le righe fattura che raggruppano per cassa previdenziale esistenti saranno "
"eliminate, e ne saranno create di nuove."

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_wizard_export_fatturapa
msgid "Export E-invoice"
msgstr "Esporta e-fattura"

#. module: l10n_it_fatturapa_out_welfare
#: model_terms:ir.ui.view,arch_db:l10n_it_fatturapa_out_welfare.invoice_form
msgid "Generate Welfare Lines"
msgstr "Genera righe cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_fund_type_amount_id
msgid "Grouped Welfare Amount"
msgstr "Importo cassa previdenziale raggruppato"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouped_invoice_line_ids
msgid "Grouped Welfare Invoice Lines"
msgstr "Righe fattura raggruppate per cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_invoice_line_ids
msgid "Grouping Welfare Invoice Lines"
msgstr "Righe fattura che raggruppano per cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__id
msgid "ID"
msgstr "ID"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_account_invoice
msgid "Invoice"
msgstr "Fattura"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_account_invoice_line
msgid "Invoice Line"
msgstr "Riga fattura"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_invoice_line_ids
msgid "Invoice Lines that represent this Line's Welfare Amount."
msgstr ""
"Righe fattura che rappresentano l'importo della cassa previdenziale di "
"questa riga."

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouped_invoice_line_ids
msgid "Invoice Lines whose Welfare Amount is represented by this Line."
msgstr ""
"Righe fattura il cui importo di cassa previdenziale è rappresentato da "
"questa riga."

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__write_uid
msgid "Last Updated by"
msgstr "Ultimo aggiornamento di"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__write_date
msgid "Last Updated on"
msgstr "Ultimo aggiornamento il"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__name
msgid "Name"
msgstr "Nome"

#. module: l10n_it_fatturapa_out_welfare
#: code:addons/l10n_it_fatturapa_out_welfare/models/account_invoice.py:62
#, python-format
msgid "Please regenerate Welfare Lines for invoices: {invoices}"
msgstr "Rigenerare le righe di cassa previdenziale per le fatture: {invoices}"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice__should_regenerate_welfare_lines
msgid "Should Regenerate Welfare Lines"
msgstr "Deve rigenerare le righe di cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: code:addons/l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py:55
#, python-format
msgid "Welfare '{welfare}' should be present in Invoice Line '{line}'"
msgstr ""
"La cassa previdenziale '{welfare}' deve essere presente nella riga fattura "
"'{line}'"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_fund_type_amount_id
msgid "Welfare Amount represented by this Invoice Line."
msgstr "Importo di cassa previdenziale rappresentato da questa riga fattura."

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_fund_type_amount_ids
msgid "Welfare Amounts to be applied on this Invoice Line."
msgstr "Importi di cassa previdenziale da applicare a questa riga fattura."

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__welfare_fund_type_id
msgid "Welfare Fund Type"
msgstr "Tipo cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_welfare_fund_type_amount
msgid "Welfare Fund Type Amount"
msgstr "Importo di cassa previdenziale"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.actions.act_window,name:l10n_it_fatturapa_out_welfare.welfare_fund_type_amount_action
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_fund_type_amount_ids
#: model:ir.ui.menu,name:l10n_it_fatturapa_out_welfare.welfare_fund_type_amount_menu
msgid "Welfare Fund Type Amounts"
msgstr "Casse previdenziali"

#. module: l10n_it_fatturapa_out_welfare
#: sql_constraint:welfare.fund.type.amount:0
msgid "Welfare Type and amount must be unique."
msgstr "Il tipo di cassa previdenziale e l'importo devono essere univoci."
164 changes: 164 additions & 0 deletions l10n_it_fatturapa_out_welfare/i18n/l10n_it_fatturapa_out_welfare.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_it_fatturapa_out_welfare
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__administration_reference
msgid "Administration Reference"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__amount
msgid "Amount"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__create_uid
msgid "Created by"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__create_date
msgid "Created on"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__display_name
msgid "Display Name"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model_terms:ir.ui.view,arch_db:l10n_it_fatturapa_out_welfare.invoice_form
msgid "Existing Grouping Welfare Invoice Lines will be deleted, and new ones will be created."
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_wizard_export_fatturapa
msgid "Export E-invoice"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model_terms:ir.ui.view,arch_db:l10n_it_fatturapa_out_welfare.invoice_form
msgid "Generate Welfare Lines"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_fund_type_amount_id
msgid "Grouped Welfare Amount"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouped_invoice_line_ids
msgid "Grouped Welfare Invoice Lines"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_invoice_line_ids
msgid "Grouping Welfare Invoice Lines"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__id
msgid "ID"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_account_invoice
msgid "Invoice"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_account_invoice_line
msgid "Invoice Line"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_invoice_line_ids
msgid "Invoice Lines that represent this Line's Welfare Amount."
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouped_invoice_line_ids
msgid "Invoice Lines whose Welfare Amount is represented by this Line."
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount____last_update
msgid "Last Modified on"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__write_uid
msgid "Last Updated by"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__write_date
msgid "Last Updated on"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__name
msgid "Name"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: code:addons/l10n_it_fatturapa_out_welfare/models/account_invoice.py:62
#, python-format
msgid "Please regenerate Welfare Lines for invoices: {invoices}"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice__should_regenerate_welfare_lines
msgid "Should Regenerate Welfare Lines"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: code:addons/l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py:55
#, python-format
msgid "Welfare '{welfare}' should be present in Invoice Line '{line}'"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_grouping_fund_type_amount_id
msgid "Welfare Amount represented by this Invoice Line."
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,help:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_fund_type_amount_ids
msgid "Welfare Amounts to be applied on this Invoice Line."
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_welfare_fund_type_amount__welfare_fund_type_id
msgid "Welfare Fund Type"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.model,name:l10n_it_fatturapa_out_welfare.model_welfare_fund_type_amount
msgid "Welfare Fund Type Amount"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: model:ir.actions.act_window,name:l10n_it_fatturapa_out_welfare.welfare_fund_type_amount_action
#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_welfare.field_account_invoice_line__welfare_fund_type_amount_ids
#: model:ir.ui.menu,name:l10n_it_fatturapa_out_welfare.welfare_fund_type_amount_menu
msgid "Welfare Fund Type Amounts"
msgstr ""

#. module: l10n_it_fatturapa_out_welfare
#: sql_constraint:welfare.fund.type.amount:0
msgid "Welfare Type and amount must be unique."
msgstr ""

5 changes: 5 additions & 0 deletions l10n_it_fatturapa_out_welfare/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_move
from . import account_move_line
from . import welfare_fund_type_amount
66 changes: 66 additions & 0 deletions l10n_it_fatturapa_out_welfare/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError


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

should_regenerate_welfare_lines = fields.Boolean(
compute="_compute_should_regenerate_welfare_lines",
store=True,
)

@api.depends(
"invoice_line_ids.welfare_grouped_invoice_line_ids",
"invoice_line_ids.welfare_fund_type_amount_ids",
)
def _compute_should_regenerate_welfare_lines(self):
for invoice in self:
lines = invoice.invoice_line_ids
# Show the button if some lines have yet to be grouped
to_be_grouped_lines = lines._get_to_be_grouped_welfare_lines()
invoice.should_regenerate_welfare_lines = to_be_grouped_lines

def button_regenerate_welfare_lines(self):
"""
Delete existing grouping Welfare Lines and create new ones.
"""
self.ensure_one()
invoice_lines = self.invoice_line_ids
# Remove previous grouping lines
grouping_lines = invoice_lines.filtered("welfare_grouping_fund_type_amount_id")
grouping_lines.unlink()
invoice_lines = invoice_lines.exists()

# Create new grouping lines
welfare_grouped_lines = invoice_lines.welfare_group_lines()
grouping_lines_sequence = max(invoice_lines.mapped("sequence")) + 1
welfare_grouping_lines_values = list()
for welfare_amount, welfare_lines in welfare_grouped_lines.items():
welfare_grouping_line_values = (
welfare_amount._prepare_grouping_invoice_line(welfare_lines)
)
welfare_grouping_line_values.update(
sequence=grouping_lines_sequence,
)
welfare_grouping_lines_values.append(welfare_grouping_line_values)

welfare_grouping_lines = self.env[invoice_lines._name].create(
welfare_grouping_lines_values,
)
return welfare_grouping_lines

def action_post(self):
need_welfare_invoices = self.filtered("should_regenerate_welfare_lines")
if need_welfare_invoices:
raise UserError(
_("Please regenerate Welfare Lines for invoices: {invoices}").format(
invoices=", ".join(
need_welfare_invoices.mapped("display_name"),
)
)
)
return super().action_post()
60 changes: 60 additions & 0 deletions l10n_it_fatturapa_out_welfare/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

welfare_fund_type_amount_ids = fields.Many2many(
comodel_name="welfare.fund.type.amount",
string="Welfare Fund Type Amounts",
help="Welfare Amounts to be applied on this Invoice Line.",
)
welfare_grouping_fund_type_amount_id = fields.Many2one(
comodel_name="welfare.fund.type.amount",
string="Grouped Welfare Amount",
help="Welfare Amount represented by this Invoice Line.",
)
welfare_grouping_invoice_line_ids = fields.Many2many(
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.move.line",
relation="welfare_group_invoice_line_rel",
column1="grouped_line",
column2="grouping_line",
string="Grouped Welfare Invoice Lines",
help="Invoice Lines whose Welfare Amount is represented by this Line.",
)

def welfare_group_lines(self):
"""
Group Invoice Lines in `self` based on their Welfare Amount.
"""
grouped_lines = dict()
for line in self:
welfare_amounts = line.welfare_fund_type_amount_ids
for welfare_amount in welfare_amounts:
if welfare_amount not in grouped_lines:
grouped_lines[welfare_amount] = line
else:
grouped_lines[welfare_amount] |= line
return grouped_lines

def _get_to_be_grouped_welfare_lines(self):
"""
Get invoice lines of `self` whose Welfare Amount
has to be represented by another invoice line.
"""
grouped_lines = self.mapped("welfare_grouped_invoice_line_ids")
welfare_lines = self.filtered("welfare_fund_type_amount_ids")

to_be_grouped_lines = welfare_lines - grouped_lines
return to_be_grouped_lines
85 changes: 85 additions & 0 deletions l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.fields import first


class WelfareFundTypeAmount(models.Model):
_name = "welfare.fund.type.amount"
_description = "Welfare Fund Type Amount"

name = fields.Char(
compute="_compute_name",
store=True,
)
welfare_fund_type_id = fields.Many2one(
comodel_name="welfare.fund.type",
required=True,
)
amount = fields.Float(
required=True,
)
administration_reference = fields.Char()

_sql_constraints = [
(
"welfare_amount_unique",
"UNIQUE(welfare_fund_type_id, amount)",
"Welfare Type and amount must be unique.",
),
]

@api.depends(
"welfare_fund_type_id.name",
"amount",
)
def _compute_name(self):
for welfare_amount in self:
name = "[{welfare_code}]: {amount}%".format(
welfare_code=welfare_amount.welfare_fund_type_id.name,
amount=welfare_amount.amount,
)
welfare_amount.name = name

def _prepare_grouping_invoice_line(self, invoice_lines):
"""
Get the values of the Invoice Line
that represents the Welfare Amount of `invoice_lines`.
"""
self.ensure_one()
for invoice_line in invoice_lines:
if self not in invoice_line.welfare_fund_type_amount_ids:
raise UserError(

Check warning on line 54 in l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py#L54

Added line #L54 was not covered by tests
_(
"Welfare '{welfare}' should be present "
"in Invoice Line '{line}'"
).format(
welfare=self.display_name,
line=invoice_line.display_name,
)
)

first_line = first(invoice_lines)
return {
"name": self.display_name,
"account_id": first_line.account_id.id,
"tax_ids": [
(6, 0, first_line.tax_ids.ids),
],
"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),
],
"price_unit": self._get_welfare_amount(invoice_lines),
}

def _get_welfare_amount(self, invoice_lines):
"""
Calculate the Welfare Amount of invoice_lines`.
"""
self.ensure_one()
lines_subtotal = sum(invoice_lines.mapped("price_subtotal"))
return self.amount * lines_subtotal / 100
3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_welfare/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
11 changes: 11 additions & 0 deletions l10n_it_fatturapa_out_welfare/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**Italiano**

In Fatturazione \> Configurazione \> Contabilità \> Fiscalità italiana
\> Fatturazione elettronica \> Importi cassa previdenziale, creare le
casse previdenziali.

**English**

In Accounting \> Configuration \> Accounting \> Italian Localization \>
Electronic invoicing \> Welfare Fund Type Amounts, create the welfare
amounts.
8 changes: 8 additions & 0 deletions l10n_it_fatturapa_out_welfare/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Italiano**

Aggiungere la cassa previdenziale alla fattura e alla fattura
elettronica.

**English**

Add Welfare Amount to Invoice and Electronic Invoice.
9 changes: 9 additions & 0 deletions l10n_it_fatturapa_out_welfare/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Italiano**

Nella fattura, impostare le casse previdenziali configurate e cliccare
su "Genera righe cassa previdenziale".

**English**

In the invoice, set the configured welfares and click on "Generate
Welfare Lines".
3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_welfare/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_welfare_fund_type_amount_manager,Welfare Fund Type Amount Manager,model_welfare_fund_type_amount,account.group_account_manager,1,1,1,1
access_welfare_fund_type_amount_user,Welfare Fund Type Amount Manager User,model_welfare_fund_type_amount,account.group_account_invoice,1,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
439 changes: 439 additions & 0 deletions l10n_it_fatturapa_out_welfare/static/description/index.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_welfare/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_fatturapa_out_welfare
138 changes: 138 additions & 0 deletions l10n_it_fatturapa_out_welfare/tests/data/IT06363391001_random.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<ns1:FatturaElettronica
xmlns:ns1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
versione="FPA12"
>
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
<IdPaese>IT</IdPaese>
<IdCodice>06363391001</IdCodice>
</IdTrasmittente>
<ProgressivoInvio>random</ProgressivoInvio>
<FormatoTrasmissione>FPA12</FormatoTrasmissione>
<CodiceDestinatario>UFPQ1O</CodiceDestinatario>
<ContattiTrasmittente>
<Telefono>06543534343</Telefono>
<Email>info@yourcompany.example.com</Email>
</ContattiTrasmittente>
</DatiTrasmissione>
<CedentePrestatore>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>06363391001</IdCodice>
</IdFiscaleIVA>
<Anagrafica>
<Denominazione>YourCompany</Denominazione>
</Anagrafica>
<RegimeFiscale>RF01</RegimeFiscale>
</DatiAnagrafici>
<Sede>
<Indirizzo>Via Milano, 1</Indirizzo>
<CAP>00100</CAP>
<Comune>Roma</Comune>
<Provincia>AK</Provincia>
<Nazione>IT</Nazione>
</Sede>
<Contatti>
<Telefono>06543534343</Telefono>
<Email>info@yourcompany.example.com</Email>
</Contatti>
</CedentePrestatore>
<CessionarioCommittente>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>06363391001</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>06363391001</CodiceFiscale>
<Anagrafica>
<Denominazione>Public Administration</Denominazione>
</Anagrafica>
</DatiAnagrafici>
<Sede>
<Indirizzo>Via Roma, 1</Indirizzo>
<CAP>10100</CAP>
<Comune>Torino</Comune>
<Provincia>AK</Provincia>
<Nazione>IT</Nazione>
</Sede>
</CessionarioCommittente>
</FatturaElettronicaHeader>
<FatturaElettronicaBody>
<DatiGenerali>
<DatiGeneraliDocumento>
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2024-01-01</Data>
<Numero>INV/2024/00001</Numero>
<DatiRitenuta>
<TipoRitenuta>RT02</TipoRitenuta>
<ImportoRitenuta>40.00</ImportoRitenuta>
<AliquotaRitenuta>20.00</AliquotaRitenuta>
<CausalePagamento>A</CausalePagamento>
</DatiRitenuta>
<DatiCassaPrevidenziale>
<TipoCassa>TC22</TipoCassa>
<AlCassa>10.00</AlCassa>
<ImportoContributoCassa>20.00</ImportoContributoCassa>
<ImponibileCassa>200.00</ImponibileCassa>
<AliquotaIVA>22.00</AliquotaIVA>
</DatiCassaPrevidenziale>
<DatiCassaPrevidenziale>
<TipoCassa>TC09</TipoCassa>
<AlCassa>20.00</AlCassa>
<ImportoContributoCassa>20.00</ImportoContributoCassa>
<ImponibileCassa>100.00</ImponibileCassa>
<AliquotaIVA>22.00</AliquotaIVA>
</DatiCassaPrevidenziale>
<ImportoTotaleDocumento>414.80</ImportoTotaleDocumento>
<Art73>SI</Art73>
</DatiGeneraliDocumento>
</DatiGenerali>
<DatiBeniServizi>
<DettaglioLinee>
<NumeroLinea>1</NumeroLinea>
<Descrizione>Cabinet with Doors</Descrizione>
<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.00</Quantita>
<UnitaMisura>Units</UnitaMisura>
<PrezzoUnitario>100.00000</PrezzoUnitario>
<PrezzoTotale>100.00</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
<Ritenuta>SI</Ritenuta>
</DettaglioLinee>
<DettaglioLinee>
<NumeroLinea>3</NumeroLinea>
<Descrizione>Cabinet with Doors</Descrizione>
<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>
202 changes: 202 additions & 0 deletions l10n_it_fatturapa_out_welfare/tests/test_fatturapa_out_welfare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64

from odoo.exceptions import UserError
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):
"""
Return a Welfare Amount of type `welfare` and amount `amount`.
"""
welfare_amount_model = self.env["welfare.fund.type.amount"]
welfare_amount_form = Form(welfare_amount_model)
welfare_amount_form.welfare_fund_type_id = welfare
welfare_amount_form.amount = amount
return welfare_amount_form.save()

def _get_payable_account(self):
"""
Return an account of Type Payable.
"""
account_model = self.env["account.account"]
payable_account_form = Form(account_model)
payable_account_form.name = "Withholding Credit"
payable_account_form.code = "WTPAY"
payable_account_form.account_type = "liability_payable"
payable_account = payable_account_form.save()
return payable_account

def _get_withholding_tax(self, payable_account, receivable_account):
"""
Return a 20% Withholding Tax.
"""
withholding_tax_model = self.env["withholding.tax"]
withholding_tax_form = Form(withholding_tax_model)
withholding_tax_form.name = "Test WT"
withholding_tax_form.code = "TWT"
withholding_tax_form.account_receivable_id = receivable_account
withholding_tax_form.account_payable_id = payable_account
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"
)
with withholding_tax_form.rate_ids.new() as rate:
rate.tax = 20
rate.base = 1
withholding_tax = withholding_tax_form.save()
return withholding_tax

def _get_invoice(self):
"""
Return an invoice having 3 lines:
- subtotal 100,
- subtotal 100, with 10% Welfare and 20% Withholding Tax
- subtotal 100, with 10% Welfare and 20% on another Welfare
"""
# Cancel other open invoices to avoid conflict on date or sequence
open_invoices = self.invoice_model.search(
[
("state", "=", "open"),
],
)
open_invoices.button_cancel()

invoice = self.invoice_model.create(
{
"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,
],
)
],
},
),
],
}
)
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,
)

self.welfare_amount_ENPAM_20 = self._get_welfare_amount(
self.env.ref("l10n_it_fatturapa.8"),
20,
)

self.withholding_tax = self._get_withholding_tax(
self._get_payable_account(),
self.a_recv,
)

def test_export_welfare_withholding(self):
"""
Check that an invoice having Welfare Amounts and Withholding Taxes
is correctly converted to an Electronic Invoice.
"""
invoice = self._get_invoice()

# Check that Welfare Lines have to be generated
# before validating the invoice
with self.assertRaises(UserError) as ue:
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_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")

xml_content = base64.decodebytes(attachment.datas)
self.check_content(
xml_content,
"IT06363391001_random.xml",
module_name="l10n_it_fatturapa_out_welfare",
)
59 changes: 59 additions & 0 deletions l10n_it_fatturapa_out_welfare/views/account_move_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2022 Simone Rubino - TAKOBI
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- Views -->
<record id="view_move_welfare_form" model="ir.ui.view">
<field
name="name"
>Add Welfare Fund Type Amount to Invoice Line Form View</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='invoice_line_ids']/tree/field[@name='price_subtotal']"
position="before"
>
<field name="welfare_grouping_fund_type_amount_id" invisible="True" />
<field
name="welfare_fund_type_amount_ids"
widget="many2many_tags"
attrs="{
'readonly': [
('welfare_grouping_fund_type_amount_id', '!=', False),
],
}"
/>
</xpath>
<notebook position="after">
<field name="should_regenerate_welfare_lines" invisible="True" />
<button
name="button_regenerate_welfare_lines"
type="object"
string="Generate Welfare Lines"
help="Existing Grouping Welfare Invoice Lines will be deleted, and new ones will be created."
attrs="{
'invisible': [
('should_regenerate_welfare_lines', '=', False),
],
}"
/>
</notebook>
</field>
</record>

<record id="view_move_line_welfare_tree" model="ir.ui.view">
<field
name="name"
>Add Welfare Fund Type Amount to Invoice Line Tree View</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree" />
<field name="arch" type="xml">
<field name="tax_ids" position="after">
<field name="welfare_fund_type_amount_ids" widget="many2many_tags" />
</field>
</field>
</record>
</odoo>
52 changes: 52 additions & 0 deletions l10n_it_fatturapa_out_welfare/views/invoice_it_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Alex Comba - Agile Business Group
Copyright 2023 Simone Rubino - TAKOBI
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<template
id="wt_account_invoice_it_dati_cassa_previdenziale"
inherit_id="l10n_it_fatturapa_out_wt.wt_account_invoice_it_dati_cassa_previdenziale"
priority="900"
>
<DatiCassaPrevidenziale position="after">
<!--2.1.1.7-->
<DatiCassaPrevidenziale
t-foreach="set_dati_cassa_previdenziale(record)"
t-as="dc_line"
>
<TipoCassa t-out="dc_line['TipoCassa']" />
<AlCassa t-out="dc_line['AlCassa']" />
<ImportoContributoCassa t-out="dc_line['ImportoContributoCassa']" />
<ImponibileCassa
t-if="dc_line['ImponibileCassa']"
t-out="dc_line['ImponibileCassa']"
/>
<AliquotaIVA
t-if="dc_line['AliquotaIVA']"
t-out="dc_line['AliquotaIVA']"
/>
<Ritenuta t-if="dc_line['Ritenuta']">SI</Ritenuta>
<Natura t-if="dc_line['Natura']" t-out="dc_line['Natura']" />
<RiferimentoAmministrazione
t-if="dc_line['RiferimentoAmministrazione']"
t-out="dc_line['RiferimentoAmministrazione']"
/>
</DatiCassaPrevidenziale>
</DatiCassaPrevidenziale>
</template>

<template
id="account_invoice_it_fattura_elettronica_body_welfare"
inherit_id="l10n_it_fatturapa_out.account_invoice_it_fattura_elettronica_body"
priority="900"
>
<xpath expr="//DatiBeniServizi/t[@t-as='line']" position="attributes">
<attribute
name="t-foreach"
>record.invoice_line_ids.filtered(lambda l: not l.welfare_grouping_fund_type_amount_id).sorted(key=lambda l: (-l.sequence, l.date, l.move_name, -l.id), reverse=True)</attribute>
</xpath>

</template>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2022 Simone Rubino - TAKOBI
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- Views -->
<record id="welfare_fund_type_amount_view_form" model="ir.ui.view">
<field name="name">Form View for Welfare Fund Type Amount</field>
<field name="model">welfare.fund.type.amount</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" />
<field name="welfare_fund_type_id" />
<field name="amount" />
<field name="administration_reference" />
</group>
</sheet>
</form>
</field>
</record>

<record id="welfare_fund_type_amount_view_tree" model="ir.ui.view">
<field name="name">Tree View for Welfare Fund Type Amount</field>
<field name="model">welfare.fund.type.amount</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="welfare_fund_type_id" />
<field name="amount" />
</tree>
</field>
</record>

<record id="welfare_fund_type_amount_view_search" model="ir.ui.view">
<field name="name">Search View for Welfare Fund Type Amount</field>
<field name="model">welfare.fund.type.amount</field>
<field name="arch" type="xml">
<search>
<field name="name" />
<field name="welfare_fund_type_id" />
<field name="amount" />
</search>
</field>
</record>

<!-- Actions -->
<record id="welfare_fund_type_amount_action" model="ir.actions.act_window">
<field name="name">Welfare Fund Type Amounts</field>
<field name="res_model">welfare.fund.type.amount</field>
</record>

<!-- Menus -->
<record id="welfare_fund_type_amount_menu" model="ir.ui.menu">
<field name="name">Welfare Fund Type Amounts</field>
<field name="action" ref="welfare_fund_type_amount_action" />
<field name="parent_id" ref="l10n_it_fatturapa.fatturapa_common_menu" />
</record>
</odoo>
3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_welfare/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import wizard_export_fatturapa
95 changes: 95 additions & 0 deletions l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.fields import first
from odoo.tools.float_utils import float_is_zero, float_round


def formatRateType(amount):
return "%.2f" % float_round(abs(amount), 2)


def formatAmount2DecimalType(amount):
return "%.2f" % float_round(amount, 2)


class WizardExportFatturapa(models.TransientModel):
_inherit = "wizard.export.fatturapa"

def get_dati_cassa_previdenziale(self, invoice_line):
"""
Return node DatiCassaPrevidenziale,
its values are based on `invoice_line`.
"""
DatiCassaPrevidenziale = False
welfare_amount = invoice_line.welfare_grouping_fund_type_amount_id
if welfare_amount:
# Mandatory fields
tax = first(invoice_line.tax_ids)
DatiCassaPrevidenziale = {
"TipoCassa": welfare_amount.welfare_fund_type_id.name,
"AlCassa": formatRateType(welfare_amount.amount),
"ImportoContributoCassa": formatAmount2DecimalType(
invoice_line.price_subtotal,
),
"AliquotaIVA": formatRateType(tax.amount),
}

# Optional fields
grouped_lines = invoice_line.welfare_grouped_invoice_line_ids
grouped_lines_subtotal = sum(grouped_lines.mapped("price_subtotal"))
DatiCassaPrevidenziale["ImponibileCassa"] = False
if not float_is_zero(grouped_lines_subtotal, 2):
grouped_lines_subtotal = formatAmount2DecimalType(
grouped_lines_subtotal
)
DatiCassaPrevidenziale["ImponibileCassa"] = grouped_lines_subtotal

DatiCassaPrevidenziale["Ritenuta"] = False
withholding_taxes = invoice_line.invoice_line_tax_wt_ids
if withholding_taxes:
DatiCassaPrevidenziale["Ritenuta"] = True

Check warning on line 52 in l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py#L52

Added line #L52 was not covered by tests

DatiCassaPrevidenziale["Natura"] = False
tax_kind = tax.kind_id
if tax_kind:
DatiCassaPrevidenziale["Natura"] = tax_kind.code

Check warning on line 57 in l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py#L57

Added line #L57 was not covered by tests

DatiCassaPrevidenziale["RiferimentoAmministrazione"] = False
administration_reference = welfare_amount.administration_reference
if administration_reference:
DatiCassaPrevidenziale[

Check warning on line 62 in l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py#L62

Added line #L62 was not covered by tests
"RiferimentoAmministrazione"
] = administration_reference

return DatiCassaPrevidenziale

@api.model
def getTemplateValues(self, template_values):
def set_dati_cassa_previdenziale(invoice):
"""
Set in `body` and return all the nodes DatiCassaPrevidenziale,
their values are based on `invoice`.
"""
DatiCassaPrevidenziale_list = list()
for invoice_line in invoice.invoice_line_ids:
DatiCassaPrevidenziale = self.get_dati_cassa_previdenziale(
invoice_line,
)
if DatiCassaPrevidenziale:
DatiCassaPrevidenziale_list.append(DatiCassaPrevidenziale)
return DatiCassaPrevidenziale_list

template_values = super().getTemplateValues(template_values)
template_values["set_dati_cassa_previdenziale"] = set_dati_cassa_previdenziale
return template_values

@api.model
def _get_e_invoice_lines(self, invoice):
invoice_lines = super()._get_e_invoice_lines(invoice)

Check warning on line 90 in l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py#L90

Added line #L90 was not covered by tests
# Exclude Welfare Grouping Lines
# from the Invoice Lines
# that will become Electronic Invoice Lines
welfare_lines = invoice_lines.filtered("welfare_grouping_fund_type_amount_id")
return invoice_lines - welfare_lines

Check warning on line 95 in l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py

Codecov / codecov/patch

l10n_it_fatturapa_out_welfare/wizards/wizard_export_fatturapa.py#L94-L95

Added lines #L94 - L95 were not covered by tests