Skip to content

Commit 5afe790

Browse files
committed
[IMP] l10n_it_edi_doi_extension: add migration scripts
1 parent f9ecb9e commit 5afe790

File tree

8 files changed

+1548
-51
lines changed

8 files changed

+1548
-51
lines changed

l10n_it_edi_doi_extension/README.rst

Lines changed: 208 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,11 +50,11 @@ 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

@@ -76,8 +72,8 @@ for the Declaration of Intent for incoming vendor bills.
7672
In the contacts, you can create a Declaration of Intent by choosing
7773
between two types:
7874

79-
- "Issued from company": for declarations issued by the company.
80-
- "Received from customer": for declarations received from suppliers.
75+
- "Issued from company": for declarations issued by the company.
76+
- "Received from customers": for declarations received from suppliers.
8177

8278
**Multiple Declarations of Intent:**
8379

@@ -89,23 +85,113 @@ Declarations of Intent:
8985
3. For each declaration, specify the amount to be covered
9086
4. The module will automatically:
9187

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
88+
- Validate that amounts don't exceed available thresholds
89+
- Show a warning if total DOI amounts don't match invoice amount
90+
- Update the invoiced amounts on each declaration
91+
- Generate protocol numbers in the XML export
9692

9793
You can also use the traditional single-declaration field for backward
9894
compatibility, or mix both approaches for different invoices.
9995

96+
--------------
97+
98+
**Migration from l10n_it_declaration_of_intent (Odoo 16)**
99+
100+
If the module ``l10n_it_declaration_of_intent`` is installed, the
101+
migration runs automatically when installing
102+
``l10n_it_edi_doi_extension``. No manual SQL or scripts are required.
103+
104+
Prerequisites:
105+
106+
- Back up the database before starting
107+
- The ``openupgradelib`` Python library must be installed in the Odoo
108+
environment
109+
110+
Steps:
111+
112+
1. **Back up the database.**
113+
114+
2. **Install the module:**
115+
116+
The pre-init hook runs automatically and handles:
117+
118+
- Renaming of the old table and model
119+
- Splitting ``telematic_protocol`` into ``protocol_number_part1`` /
120+
``protocol_number_part2``
121+
- Renaming fields (``date`` → ``issue_date``, ``date_start`` →
122+
``start_date``, etc.)
123+
- Mapping states (``valid`` → ``active``, ``expired`` →
124+
``terminated``, ``close`` → ``revoked``)
125+
- Removing old views incompatible with Odoo 18
126+
127+
The post-init hook:
128+
129+
- Creates ``account.move.doi`` bridge records from the old many2many
130+
relations
131+
- Populates ``l10n_it_edi_doi_amount`` on invoices that had no DOI
132+
tax lines
133+
- Cleans up residual metadata from the old module
134+
135+
3. **Verify the migrated data:**
136+
137+
- Declarations appear in the new menu with correct protocol numbers
138+
- States are correctly mapped
139+
- Invoice links are working
140+
- Computed amounts (invoiced, remaining) are shown correctly
141+
- **For invoices that had multiple declarations in v16: check the**
142+
**"Declarations of Intent" tab and assign the correct amount to
143+
each entry** **(they are migrated with ``amount = 0``)**
144+
145+
4. **Uninstall the old module** once everything is verified:
146+
147+
Go to *Settings → Technical → Modules*, search for
148+
``l10n_it_declaration_of_intent`` and click **Uninstall**.
149+
150+
⚠️ Do not uninstall it before verifying the data — the module must
151+
remain present during migration.
152+
153+
**Data that is NOT migrated** (no equivalent in v18):
154+
155+
- ``partner_document_number``, ``partner_document_date``
156+
- ``taxes_ids``, ``fiscal_position_id``
157+
- Declaration lines (``declaration_line`` model)
158+
- Yearly limits (``yearly_limit`` model) — adjust individual
159+
declaration thresholds manually
160+
161+
**Troubleshooting:**
162+
163+
- *ValidationError about repartition lines during installation*: the
164+
migration script automatically adds missing repartition lines to
165+
split payment group taxes. If the error persists, check that
166+
``openupgradelib`` is installed correctly.
167+
168+
- *Duplicate key error on fiscal positions or taxes during
169+
l10n_it_edi_doi installation*: this can happen when the old module
170+
had already created the same fiscal position data. The installation
171+
of ``l10n_it_edi_doi`` may fail or show a warning. Remove the
172+
duplicate fiscal position tax mappings manually and retry.
173+
174+
- *Invoices with multiple DOIs show amount = 0*: expected behaviour.
175+
The old many2many relation did not store per-declaration amounts.
176+
Open each affected invoice and assign the correct amount in the
177+
"Declarations of Intent" tab.
178+
179+
- *Yearly limits not migrated*: the concept no longer exists in v18.
180+
Review each declaration and set the ``threshold`` field to the
181+
appropriate value.
182+
183+
--------------
184+
100185
**Italiano**
101186

102187
Nella configurazione dell'azienda è necessario definire un'imposta
103188
dedicata alla Dichiarazione di Intento per le fatture in ingresso. Nei
104189
contatti è possibile creare una Dichiarazione di Intento scegliendo tra
105190
due tipologie:
106191

107-
- "Issued from company": per le dichiarazioni emesse dall'azienda.
108-
- "Received from customer": per le dichiarazioni ricevute dai fornitori.
192+
- "Issued from company": per le dichiarazioni emesse dall'azienda.
193+
- "Received from customers": per le dichiarazioni ricevute dai
194+
fornitori.
109195

110196
**Dichiarazioni di Intento Multiple:**
111197

@@ -117,16 +203,109 @@ possibile associare più Dichiarazioni di Intento:
117203
3. Per ogni dichiarazione, specifica l'importo da coprire
118204
4. Il modulo automaticamente:
119205

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
206+
- Valida che gli importi non superino le soglie disponibili
207+
- Mostra un avviso se il totale DOI non corrisponde all'importo
208+
fattura
209+
- Aggiorna gli importi fatturati su ogni dichiarazione
210+
- Genera i numeri di protocollo nell'esportazione XML
125211

126212
È possibile continuare ad usare il campo tradizionale a dichiarazione
127213
singola per retrocompatibilità, o combinare entrambi gli approcci per
128214
fatture diverse.
129215

216+
--------------
217+
218+
**Migrazione da l10n_it_declaration_of_intent (Odoo 16)**
219+
220+
Se il modulo ``l10n_it_declaration_of_intent`` è installato, la
221+
migrazione avviene automaticamente durante l'installazione di
222+
``l10n_it_edi_doi_extension``. Non è necessario eseguire script o SQL
223+
manualmente.
224+
225+
Prerequisiti:
226+
227+
- Eseguire un backup del database prima di iniziare
228+
- La libreria Python ``openupgradelib`` deve essere installata
229+
nell'ambiente Odoo
230+
231+
Passi:
232+
233+
1. **Eseguire un backup del database.**
234+
235+
2. **Installare il modulo:**
236+
237+
L'hook pre-init viene eseguito automaticamente e gestisce:
238+
239+
- Rinomina della tabella e del modello
240+
- Split di ``telematic_protocol`` in ``protocol_number_part1`` /
241+
``protocol_number_part2``
242+
- Rinomina dei campi (``date`` → ``issue_date``, ``date_start`` →
243+
``start_date``, ecc.)
244+
- Mappatura degli stati (``valid`` → ``active``, ``expired`` →
245+
``terminated``, ``close`` → ``revoked``)
246+
- Rimozione delle view del vecchio modulo incompatibili con Odoo 18
247+
248+
L'hook post-init:
249+
250+
- Crea i record bridge ``account.move.doi`` dalle vecchie relazioni
251+
many2many
252+
- Popola ``l10n_it_edi_doi_amount`` sulle fatture prive di righe con
253+
imposta DOI
254+
- Pulisce i metadati residui del vecchio modulo
255+
256+
3. **Verificare i dati migrati:**
257+
258+
- Le dichiarazioni compaiono nel nuovo menu con i numeri di
259+
protocollo corretti
260+
- Gli stati sono correttamente mappati
261+
- I collegamenti alle fatture funzionano
262+
- Gli importi calcolati (fatturato, residuo) sono visualizzati
263+
correttamente
264+
- **Per le fatture che avevano più dichiarazioni in v16: controllare
265+
il tab** **"Dichiarazioni di Intento" e assegnare l'importo
266+
corretto a ciascuna voce** **(vengono migrate con
267+
``amount = 0``)**
268+
269+
4. **Disinstallare il vecchio modulo** una volta verificati i dati:
270+
271+
Andare in *Impostazioni → Tecnico → Moduli*, cercare
272+
``l10n_it_declaration_of_intent`` e fare clic su **Disinstalla**.
273+
274+
⚠️ Non disinstallarlo prima di aver verificato i dati — il modulo
275+
deve rimanere presente durante la migrazione.
276+
277+
**Dati NON migrati** (nessun equivalente in v18):
278+
279+
- ``partner_document_number``, ``partner_document_date``
280+
- ``taxes_ids``, ``fiscal_position_id``
281+
- Righe della dichiarazione (modello ``declaration_line``)
282+
- Limiti annuali (modello ``yearly_limit``) — aggiustare manualmente la
283+
soglia delle singole dichiarazioni
284+
285+
**Risoluzione dei problemi:**
286+
287+
- *ValidationError sulle repartition lines durante l'installazione*: lo
288+
script di migrazione aggiunge automaticamente le repartition lines
289+
mancanti sulle imposte di gruppo per lo split payment. Se l'errore
290+
persiste, verificare che ``openupgradelib`` sia installato
291+
correttamente.
292+
293+
- *Errore di chiave duplicata su posizioni fiscali o imposte durante
294+
l'installazione di l10n_it_edi_doi*: può accadere se il vecchio
295+
modulo aveva già creato gli stessi dati di posizione fiscale.
296+
L'installazione di ``l10n_it_edi_doi`` può fallire o mostrare un
297+
avviso. Rimuovere manualmente le mappature di posizione fiscale
298+
duplicate e riprovare.
299+
300+
- *Fatture con più DI mostrano importo = 0*: comportamento atteso. La
301+
vecchia relazione many2many non memorizzava gli importi per
302+
dichiarazione. Aprire le fatture interessate e assegnare l'importo
303+
corretto nel tab "Dichiarazioni di Intento".
304+
305+
- *Limiti annuali non migrati*: il concetto non esiste in v18. Rivedere
306+
ogni dichiarazione e impostare il campo ``threshold`` con il valore
307+
appropriato.
308+
130309
Bug Tracker
131310
===========
132311

@@ -148,7 +327,7 @@ Authors
148327
Contributors
149328
------------
150329

151-
- Nextev Srl<odoo@nextev.it>
330+
- Nextev Srl<odoo@nextev.it>
152331

153332
Maintainers
154333
-----------

0 commit comments

Comments
 (0)