Metadata-Version: 2.1
Name: odoo-addon-l10n_it_edi_pec
Version: 18.0.1.0.0.2
Requires-Python: >=3.10
Requires-Dist: odoo-addon-l10n_it_edi_sdi==18.0.*
Requires-Dist: odoo==18.0.*
Requires-Dist: openupgradelib
Summary: Invio e ricezione fatture elettroniche tramite PEC
Home-page: https://github.com/OCA/l10n-italy
License: AGPL-3
Author: Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

========================================
ITA - Fattura elettronica - Supporto PEC
========================================

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

.. |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/license-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/18.0/l10n_it_edi_pec
    :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-18-0/l10n-italy-18-0-l10n_it_edi_pec
    :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=18.0
    :alt: Try me on Runboat

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

**Italiano**

Questo modulo implementa il canale PEC (Posta Elettronica Certificata)
per la comunicazione con il Sistema di Interscambio (SdI), in
alternativa al proxy IAP standard di Odoo.

Si basa su ``l10n_it_edi_sdi`` per la logica condivisa di elaborazione
delle notifiche e ricezione delle fatture, aggiungendo il trasporto
specifico via PEC.

Funzionalità principali:

- Invio fatture elettroniche via PEC al SdI
- Ricezione email PEC dal SdI e instradamento ai gestori appropriati
- Gestione errori PEC con notifica automatica ai contatti configurati e
  disabilitazione del server dopo ripetuti fallimenti
- Configurazione server SMTP e IMAP/POP3 dedicati alla PEC

**English**

This module implements the PEC (Certified Email) transport channel for
communication with the Italian Exchange System (SdI), as an alternative
to Odoo's standard IAP proxy.

It builds on ``l10n_it_edi_sdi`` for the shared notification processing
and invoice reception logic, adding PEC-specific transport.

Main features:

- Send electronic invoices to SdI via PEC
- Receive PEC emails from SdI and route to appropriate handlers
- PEC error handling with automatic notification to configured contacts
  and server auto-disable after repeated failures
- Dedicated SMTP and IMAP/POP3 server configuration for PEC

**Table of contents**

.. contents::
   :local:

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

**Italiano**

1. Configurare un server SMTP in uscita per la PEC:

   - Andare in *Impostazioni → Tecnico → Server di posta in uscita*
   - Creare un nuovo server con i parametri del provider PEC
   - Spuntare "E-invoice PEC server"
   - Inserire l'indirizzo email PEC mittente

2. Configurare un server di posta in ingresso per la PEC:

   - Andare in *Impostazioni → Tecnico → Server di posta in ingresso*
   - Creare un nuovo server IMAP o POP3 con i parametri del provider PEC
   - Spuntare "E-invoice PEC server"
   - Configurare i contatti da notificare in caso di errore

3. Abilitare il canale PEC per l'azienda:

   - Andare in *Impostazioni → Contabilità → Fatturazione elettronica*
   - Spuntare "Use PEC for e-invoicing"
   - Selezionare i server PEC in uscita e in ingresso
   - Inserire l'indirizzo PEC del SdI

4. Il parametro di sistema ``fetchmail.pec.max.retry`` (default: 5)
   controlla il numero massimo di errori consecutivi prima che il server
   di posta in ingresso venga disabilitato automaticamente. Modificare
   il valore in *Impostazioni → Tecnico → Parametri → Parametri di
   sistema* se necessario.

**English**

1. Configure an outgoing PEC SMTP server:

   - Go to *Settings → Technical → Outgoing Mail Servers*
   - Create a new server with your PEC provider parameters
   - Check "E-invoice PEC server"
   - Enter the PEC sender email address

2. Configure an incoming PEC mail server:

   - Go to *Settings → Technical → Incoming Mail Servers*
   - Create a new IMAP or POP3 server with your PEC provider parameters
   - Check "E-invoice PEC server"
   - Configure contacts to notify on errors

3. Enable PEC channel for the company:

   - Go to *Settings → Accounting → Italian Electronic Invoicing*
   - Check "Use PEC for e-invoicing"
   - Select the outgoing and incoming PEC servers
   - Enter the SdI PEC email address

4. The system parameter ``fetchmail.pec.max.retry`` (default: 5)
   controls the maximum number of consecutive errors before the incoming
   mail server is automatically disabled. Change its value in *Settings
   → Technical → Parameters → System Parameters* if needed.

Usage
=====

**Italiano**

Invio fatture
-------------

Le fatture vengono inviate al SdI tramite PEC quando si utilizza il
normale flusso di invio fattura elettronica di Odoo. Il modulo
intercetta l'invio e usa la PEC al posto del proxy IAP standard.

Ricezione notifiche
-------------------

Le notifiche dal SdI vengono ricevute automaticamente tramite il cron di
fetchmail. Lo stato della fattura viene aggiornato automaticamente in
base alla notifica ricevuta:

- RC (Ricevuta di Consegna) → Inoltrata al destinatario
- NS (Notifica di Scarto) → Rifiutata
- MC (Mancata Consegna) → Inoltro al destinatario fallito
- NE (Notifica Esito) → Accettata/Rifiutata dal partner PA
- DT (Decorrenza Termini) → Accettata per decorrenza termini

Ricezione fatture passive
-------------------------

Le fatture dei fornitori inviate tramite SdI vengono ricevute
automaticamente via PEC e importate come fatture in bozza.

Verifica manuale stato
----------------------

Il pulsante "Verifica stato" sulla fattura inviata avvia una lettura
manuale della casella PEC per recuperare eventuali notifiche in attesa.

**English**

Sending invoices
----------------

Invoices are sent to SdI via PEC when using Odoo's standard electronic
invoice sending flow. The module intercepts the send and uses PEC
instead of the standard IAP proxy.

Receiving notifications
-----------------------

SdI notifications are received automatically via the fetchmail cron. The
invoice state is updated automatically based on the notification
received:

- RC (Delivery Receipt) → Forwarded to recipient
- NS (Rejection) → Rejected
- MC (Failed Delivery) → Forward to recipient failed
- NE (Outcome Notification) → Accepted/Rejected by PA partner
- DT (Deadline Expiry) → Accepted after term expiry

Receiving vendor bills
----------------------

Vendor bills sent through SdI are automatically received via PEC and
imported as draft invoices.

Manual status check
-------------------

The "Check status" button on a sent invoice triggers a manual PEC
mailbox read to retrieve any pending notifications.

Changelog
=========

Migration from 16.0 (l10n_it_fatturapa_pec) to 18.0 (l10n_it_edi_pec)
---------------------------------------------------------------------

This module replaces ``l10n_it_fatturapa_pec`` (Odoo 16) with a complete
rewrite based on Odoo 18's native ``l10n_it_edi`` architecture.

Name change and dependencies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The module was renamed from ``l10n_it_fatturapa_pec`` to
``l10n_it_edi_pec``.

Dependencies were drastically simplified:

- **v16**: ``l10n_it_fatturapa_out``, ``l10n_it_fatturapa_in``,
  ``l10n_it_sdi_channel``, ``mail``
- **v18**: ``l10n_it_edi``, ``mail``

The modules ``l10n_it_fatturapa_out``, ``l10n_it_fatturapa_in`` and
``l10n_it_sdi_channel`` are no longer needed.

Integration with l10n_it_edi core
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The module now extends Odoo 18's ``l10n_it_edi`` core methods instead of
implementing a standalone flow:

- ``_l10n_it_edi_upload()`` on ``account.move``: intercepts sending for
  PEC-enabled companies and sends directly via SMTP, with fallback to
  ``super()`` for the proxy channel
- ``_l10n_it_edi_update_send_state()``: excludes PEC invoices from proxy
  polling
- ``_l10n_it_edi_export_check()``: validates PEC configuration and
  removes the proxy user requirement
- ``action_check_l10n_it_edi()``: triggers PEC fetchmail for manual
  status check

Removed sdi.channel model
~~~~~~~~~~~~~~~~~~~~~~~~~

The ``sdi.channel`` model has been completely removed. PEC configuration
is now managed directly on ``res.company`` through the fields:

- ``l10n_it_edi_use_pec`` (Boolean)
- ``l10n_it_edi_pec_server_id`` (Many2one -> ir.mail_server)
- ``l10n_it_edi_pec_fetch_server_id`` (Many2one -> fetchmail.server)
- ``l10n_it_edi_pec_email_exchange_system`` (Char)

These fields are exposed in Settings via ``res.config.settings``. The
views ``sdi_view.xml`` and ``company_view.xml`` are replaced by
``res_config_settings_views.xml``.

Removed fatturapa.attachment.out model
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In v16, ``fatturapa.attachment.out`` managed the lifecycle of sent
invoices and SdI notification parsing (``_message_type_ns``,
``_message_type_rc``, etc.). In v18, the entire flow is handled directly
on ``account.move`` through the core notification chain:

``_l10n_it_edi_parse_notification()`` ->
``_l10n_it_edi_transform_notification()`` ->
``_l10n_it_edi_get_message()`` -> ``_l10n_it_edi_write_send_state()``

Removed fatturapa.attachment.in model
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Incoming vendor bill reception no longer uses
``fatturapa.attachment.in``. The module now directly creates an empty
``account.move``, attaches the XML file and calls
``move._extend_with_attachments()`` to populate fields from the
electronic invoice.

SdI state mapping
~~~~~~~~~~~~~~~~~

State mapping has changed to align with the ``l10n_it_edi`` core:

+----------------------+----------------------------+----------------------+
| SdI Code             | v16                        | v18 (account.move)   |
|                      | (fatturapa.attachment.out) |                      |
+======================+============================+======================+
| NS (Notifica di      | ``sender_error``           | ``rejected``         |
| Scarto)              |                            |                      |
+----------------------+----------------------------+----------------------+
| RC (Ricevuta di      | ``validated``              | ``forwarded``        |
| Consegna)            |                            |                      |
+----------------------+----------------------------+----------------------+
| MC (Mancata          | ``recipient_error``        | ``forward_failed``   |
| Consegna)            |                            |                      |
+----------------------+----------------------------+----------------------+
| NE (Notifica Esito)  | ``accepted`` /             | ``accepted`` /       |
|                      | ``rejected``               | ``rejected``         |
+----------------------+----------------------------+----------------------+
| DT (Decorrenza       | ``validated``              | ``accepted``         |
| Termini)             |                            |                      |
+----------------------+----------------------------+----------------------+

Removed first_invoice_sent flow
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The first PEC sending management mechanism (``first_invoice_sent`` field
on ``sdi.channel``, initial address ``sdi01@pec.fatturapa.it`` and
automatic address change after first sending) has been removed. The SdI
PEC address must now be configured directly in the
``l10n_it_edi_pec_email_exchange_system`` field.

Simplified sending mechanism
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- **v16**: ``sdi.channel.send_via_pec()`` created ``mail.message`` and
  ``mail.mail`` records, then delegated sending to Odoo's mail system
- **v18**: ``_l10n_it_edi_upload()`` directly builds a Python
  ``EmailMessage`` and sends it via ``ir.mail_server.send_email()``,
  without creating intermediate database records

Field renames
~~~~~~~~~~~~~

============================ ==============================
v16                          v18
============================ ==============================
``is_fatturapa_pec``         ``is_l10n_it_edi_pec``
``email_from_for_fatturaPA`` ``l10n_it_edi_pec_email_from``
============================ ==============================

Tests
~~~~~

The test base class changed from ``FatturaPACommon``
(``l10n_it_fatturapa_out.tests``) to ``TestItEdi``
(``l10n_it_edi.tests.common``), consistent with the new core extension
pattern.

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_edi_pec%0Aversion:%2018.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
=======

Contributors
------------

- Andrea Colangelo (andreacolangelo@openforce.it)
- Sergio Corato https://efatto.it
- Lorenzo Battistini https://github.com/eLBati
- Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo)
- Roberto Fichera https://levelprime.com
- Simone Rubino

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/18.0/l10n_it_edi_pec>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
