Skip to content

Commit c995965

Browse files
odooNextevstenext
authored andcommitted
[IMP] l10n_it_edi_doi_extension: add migration scripts
1 parent 1430f13 commit c995965

File tree

12 files changed

+1175
-59
lines changed

12 files changed

+1175
-59
lines changed

l10n_it_edi_doi_extension/README.rst

Lines changed: 209 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
=====================================
62
Declaration of Intent for Italy (OCA)
73
=====================================
@@ -17,7 +13,7 @@ Declaration of Intent for Italy (OCA)
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
@@ -40,11 +36,11 @@ vendor bills and purchase orders.
4036

4137
Key features:
4238

43-
- Support for multiple Declarations of Intent per invoice
44-
- Dedicated tab in invoice form for managing DOI associations
45-
- Automatic validation of DOI amounts and available thresholds
46-
- Smart warnings when invoice amounts don't match DOI coverage
47-
- Backward compatibility with single-declaration workflow
39+
- Support for multiple Declarations of Intent per invoice
40+
- Dedicated tab in invoice form for managing DOI associations
41+
- Automatic validation of DOI amounts and available thresholds
42+
- Smart warnings when invoice amounts don't match DOI coverage
43+
- Backward compatibility with single-declaration workflow
4844

4945
**Italiano**
5046

@@ -54,17 +50,200 @@ ingresso e gli ordini di acquisto.
5450

5551
Caratteristiche principali:
5652

57-
- Supporto per dichiarazioni di intento multiple per fattura
58-
- Tab dedicato nel form fattura per gestire le associazioni DOI
59-
- Validazione automatica degli importi e soglie disponibili
60-
- Avvisi intelligenti quando gli importi non corrispondono
61-
- Retrocompatibilità con il flusso a dichiarazione singola
53+
- Supporto per dichiarazioni di intento multiple per fattura
54+
- Tab dedicato nel form fattura per gestire le associazioni DOI
55+
- Validazione automatica degli importi e soglie disponibili
56+
- Avvisi intelligenti quando gli importi non corrispondono
57+
- Retrocompatibilità con il flusso a dichiarazione singola
6258

6359
**Table of contents**
6460

6561
.. contents::
6662
:local:
6763

64+
Installation
65+
============
66+
67+
**English**
68+
69+
**Migration from l10n_it_declaration_of_intent (Odoo 16)**
70+
71+
If the module ``l10n_it_declaration_of_intent`` is installed, the
72+
migration runs automatically when installing
73+
``l10n_it_edi_doi_extension``. No manual SQL or scripts are required.
74+
75+
Prerequisites:
76+
77+
- Back up the database before starting
78+
- The ``openupgradelib`` Python library must be installed in the Odoo
79+
environment
80+
81+
Steps:
82+
83+
1. **Back up the database.**
84+
85+
2. **Install the module:**
86+
87+
The pre-init hook runs automatically and handles:
88+
89+
- Renaming of the old table and model
90+
- Splitting ``telematic_protocol`` into ``protocol_number_part1`` /
91+
``protocol_number_part2``
92+
- Renaming fields (``date`` → ``issue_date``, ``date_start`` →
93+
``start_date``, etc.)
94+
- Mapping states (``valid`` → ``active``, ``expired`` →
95+
``terminated``, ``close`` → ``revoked``)
96+
- Removing old views incompatible with Odoo 18
97+
98+
The post-init hook:
99+
100+
- Creates ``account.move.doi`` bridge records from the old many2many
101+
relations
102+
- Populates ``l10n_it_edi_doi_amount`` on invoices that had no DOI
103+
tax lines
104+
- Cleans up residual metadata from the old module
105+
106+
3. **Verify the migrated data:**
107+
108+
- Declarations appear in the new menu with correct protocol numbers
109+
- States are correctly mapped
110+
- Invoice links are working
111+
- Computed amounts (invoiced, remaining) are shown correctly
112+
- **For invoices that had multiple declarations in v16: check the**
113+
**"Declarations of Intent" tab and assign the correct amount to
114+
each entry** **(they are migrated with ``amount = 0``)**
115+
116+
4. **Uninstall the old module** once everything is verified:
117+
118+
Go to *Settings → Technical → Modules*, search for
119+
``l10n_it_declaration_of_intent`` and click **Uninstall**.
120+
121+
⚠️ Do not uninstall it before verifying the data — the module must
122+
remain present during migration.
123+
124+
**Data that is NOT migrated** (no equivalent in v18):
125+
126+
- ``partner_document_number``, ``partner_document_date``
127+
- ``taxes_ids``, ``fiscal_position_id``
128+
- Declaration lines (``declaration_line`` model)
129+
- Yearly limits (``yearly_limit`` model) — adjust individual
130+
declaration thresholds manually
131+
132+
**Troubleshooting:**
133+
134+
- *ValidationError about repartition lines during installation*: the
135+
migration script automatically adds missing repartition lines to
136+
split payment group taxes. If the error persists, check that
137+
``openupgradelib`` is installed correctly.
138+
139+
- *Duplicate key error on fiscal positions or taxes during
140+
l10n_it_edi_doi installation*: this can happen when the old module
141+
had already created the same fiscal position data. The installation
142+
of ``l10n_it_edi_doi`` may fail or show a warning. Remove the
143+
duplicate fiscal position tax mappings manually and retry.
144+
145+
- *Invoices with multiple DOIs show amount = 0*: expected behaviour.
146+
The old many2many relation did not store per-declaration amounts.
147+
Open each affected invoice and assign the correct amount in the
148+
"Declarations of Intent" tab.
149+
150+
- *Yearly limits not migrated*: the concept no longer exists in v18.
151+
Review each declaration and set the ``threshold`` field to the
152+
appropriate value.
153+
154+
**Italiano**
155+
156+
**Migrazione da l10n_it_declaration_of_intent (Odoo 16)**
157+
158+
Se il modulo ``l10n_it_declaration_of_intent`` è installato, la
159+
migrazione avviene automaticamente durante l'installazione di
160+
``l10n_it_edi_doi_extension``. Non è necessario eseguire script o SQL
161+
manualmente.
162+
163+
Prerequisiti:
164+
165+
- Eseguire un backup del database prima di iniziare
166+
- La libreria Python ``openupgradelib`` deve essere installata
167+
nell'ambiente Odoo
168+
169+
Passi:
170+
171+
1. **Eseguire un backup del database.**
172+
173+
2. **Installare il modulo:**
174+
175+
L'hook pre-init viene eseguito automaticamente e gestisce:
176+
177+
- Rinomina della tabella e del modello
178+
- Split di ``telematic_protocol`` in ``protocol_number_part1`` /
179+
``protocol_number_part2``
180+
- Rinomina dei campi (``date`` → ``issue_date``, ``date_start`` →
181+
``start_date``, ecc.)
182+
- Mappatura degli stati (``valid`` → ``active``, ``expired`` →
183+
``terminated``, ``close`` → ``revoked``)
184+
- Rimozione delle view del vecchio modulo incompatibili con Odoo 18
185+
186+
L'hook post-init:
187+
188+
- Crea i record bridge ``account.move.doi`` dalle vecchie relazioni
189+
many2many
190+
- Popola ``l10n_it_edi_doi_amount`` sulle fatture prive di righe con
191+
imposta DOI
192+
- Pulisce i metadati residui del vecchio modulo
193+
194+
3. **Verificare i dati migrati:**
195+
196+
- Le dichiarazioni compaiono nel nuovo menu con i numeri di
197+
protocollo corretti
198+
- Gli stati sono correttamente mappati
199+
- I collegamenti alle fatture funzionano
200+
- Gli importi calcolati (fatturato, residuo) sono visualizzati
201+
correttamente
202+
- **Per le fatture che avevano più dichiarazioni in v16: controllare
203+
il tab** **"Dichiarazioni di Intento" e assegnare l'importo
204+
corretto a ciascuna voce** **(vengono migrate con
205+
``amount = 0``)**
206+
207+
4. **Disinstallare il vecchio modulo** una volta verificati i dati:
208+
209+
Andare in *Impostazioni → Tecnico → Moduli*, cercare
210+
``l10n_it_declaration_of_intent`` e fare clic su **Disinstalla**.
211+
212+
⚠️ Non disinstallarlo prima di aver verificato i dati — il modulo
213+
deve rimanere presente durante la migrazione.
214+
215+
**Dati NON migrati** (nessun equivalente in v18):
216+
217+
- ``partner_document_number``, ``partner_document_date``
218+
- ``taxes_ids``, ``fiscal_position_id``
219+
- Righe della dichiarazione (modello ``declaration_line``)
220+
- Limiti annuali (modello ``yearly_limit``) — aggiustare manualmente la
221+
soglia delle singole dichiarazioni
222+
223+
**Risoluzione dei problemi:**
224+
225+
- *ValidationError sulle repartition lines durante l'installazione*: lo
226+
script di migrazione aggiunge automaticamente le repartition lines
227+
mancanti sulle imposte di gruppo per lo split payment. Se l'errore
228+
persiste, verificare che ``openupgradelib`` sia installato
229+
correttamente.
230+
231+
- *Errore di chiave duplicata su posizioni fiscali o imposte durante
232+
l'installazione di l10n_it_edi_doi*: può accadere se il vecchio
233+
modulo aveva già creato gli stessi dati di posizione fiscale.
234+
L'installazione di ``l10n_it_edi_doi`` può fallire o mostrare un
235+
avviso. Rimuovere manualmente le mappature di posizione fiscale
236+
duplicate e riprovare.
237+
238+
- *Fatture con più DI mostrano importo = 0*: comportamento atteso. La
239+
vecchia relazione many2many non memorizzava gli importi per
240+
dichiarazione. Aprire le fatture interessate e assegnare l'importo
241+
corretto nel tab "Dichiarazioni di Intento".
242+
243+
- *Limiti annuali non migrati*: il concetto non esiste in v18. Rivedere
244+
ogni dichiarazione e impostare il campo ``threshold`` con il valore
245+
appropriato.
246+
68247
Usage
69248
=====
70249

@@ -76,8 +255,8 @@ for the Declaration of Intent for incoming vendor bills.
76255
In the contacts, you can create a Declaration of Intent by choosing
77256
between two types:
78257

79-
- "Issued from company": for declarations issued by the company.
80-
- "Received from customer": for declarations received from suppliers.
258+
- "Issued from company": for declarations issued by the company.
259+
- "Received from customers": for declarations received from suppliers.
81260

82261
**Multiple Declarations of Intent:**
83262

@@ -89,10 +268,10 @@ Declarations of Intent:
89268
3. For each declaration, specify the amount to be covered
90269
4. The module will automatically:
91270

92-
- Validate that amounts don't exceed available thresholds
93-
- Show a warning if total DOI amounts don't match invoice amount
94-
- Update the invoiced amounts on each declaration
95-
- Generate protocol numbers in the XML export
271+
- Validate that amounts don't exceed available thresholds
272+
- Show a warning if total DOI amounts don't match invoice amount
273+
- Update the invoiced amounts on each declaration
274+
- Generate protocol numbers in the XML export
96275

97276
You can also use the traditional single-declaration field for backward
98277
compatibility, or mix both approaches for different invoices.
@@ -104,8 +283,9 @@ dedicata alla Dichiarazione di Intento per le fatture in ingresso. Nei
104283
contatti è possibile creare una Dichiarazione di Intento scegliendo tra
105284
due tipologie:
106285

107-
- "Issued from company": per le dichiarazioni emesse dall'azienda.
108-
- "Received from customer": per le dichiarazioni ricevute dai fornitori.
286+
- "Issued from company": per le dichiarazioni emesse dall'azienda.
287+
- "Received from customers": per le dichiarazioni ricevute dai
288+
fornitori.
109289

110290
**Dichiarazioni di Intento Multiple:**
111291

@@ -117,11 +297,11 @@ possibile associare più Dichiarazioni di Intento:
117297
3. Per ogni dichiarazione, specifica l'importo da coprire
118298
4. Il modulo automaticamente:
119299

120-
- Valida che gli importi non superino le soglie disponibili
121-
- Mostra un avviso se il totale DOI non corrisponde all'importo
122-
fattura
123-
- Aggiorna gli importi fatturati su ogni dichiarazione
124-
- Genera i numeri di protocollo nell'esportazione XML
300+
- Valida che gli importi non superino le soglie disponibili
301+
- Mostra un avviso se il totale DOI non corrisponde all'importo
302+
fattura
303+
- Aggiorna gli importi fatturati su ogni dichiarazione
304+
- Genera i numeri di protocollo nell'esportazione XML
125305

126306
È possibile continuare ad usare il campo tradizionale a dichiarazione
127307
singola per retrocompatibilità, o combinare entrambi gli approcci per
@@ -148,7 +328,7 @@ Authors
148328
Contributors
149329
------------
150330

151-
- Nextev Srl<odoo@nextev.it>
331+
- Nextev Srl <odoo@nextev.it>
152332

153333
Maintainers
154334
-----------
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
# Copyright 2026 Nextev Srl
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
14
from . import models
5+
from .hooks import (
6+
_l10n_it_edi_doi_extension_pre_init_hook,
7+
_l10n_it_edi_doi_extension_post_init_hook,
8+
)

l10n_it_edi_doi_extension/__manifest__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@
1717
"views/account_move_views.xml",
1818
],
1919
"installable": True,
20+
"pre_init_hook": "_l10n_it_edi_doi_extension_pre_init_hook",
21+
"post_init_hook": "_l10n_it_edi_doi_extension_post_init_hook",
22+
"external_dependencies": {
23+
"python": [
24+
"openupgradelib",
25+
],
26+
},
2027
}

0 commit comments

Comments
 (0)