Skip to content

Commit 46373a4

Browse files
NextEvTeoNextEvTeo
authored andcommitted
[IMP] l10n_it_delivery_note: electronic invoicing DatiDdt
1 parent 1ee966e commit 46373a4

10 files changed

Lines changed: 481 additions & 61 deletions

File tree

l10n_it_delivery_note/README.rst

Lines changed: 76 additions & 37 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
ITA - Documento di trasporto
73
============================
@@ -11,13 +7,13 @@ ITA - Documento di trasporto
117
!! This file is generated by oca-gen-addon-readme !!
128
!! changes will be overwritten. !!
139
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14-
!! source digest: sha256:dfdd6f11110f3e834e26048a8e73d0e41a5d20f09ec6b2fdd529821fc0c6d38d
10+
!! source digest: sha256:7e407a63e5642e24e05e9d2b3c84749acf0f77abf7825e750f7b1d84cccddd54
1511
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1612
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
@@ -48,8 +44,28 @@ installed together.
4844

4945
There are two available settings:
5046

51-
- Base (default): one picking, one DN.
52-
- Advanced: more picking in one DN.
47+
- Base (default): one picking, one DN.
48+
- Advanced: more picking in one DN.
49+
50+
**Electronic Invoicing Integration**
51+
52+
This module integrates with Italian electronic invoicing
53+
(``l10n_it_stock_ddt``).
54+
55+
It automatically adds Delivery Note references to the FatturaPA XML,
56+
including:
57+
58+
- DDT Number
59+
- DDT Date
60+
- Line references
61+
62+
The module also handles the distinction between immediate and deferred
63+
invoices:
64+
65+
- **TD01 (Immediate invoice)**: when the invoice has the same date as
66+
the linked DDTs
67+
- **TD24 (Deferred invoice)**: when the invoice is issued on a
68+
different day than the DDTs
5369

5470
**Italiano**
5571

@@ -66,8 +82,28 @@ Non è possibile avere installati contemporaneamente ``l10n_it_ddt`` e
6682

6783
Ci sono due impostazioni possibili.
6884

69-
- Base (predefinita): un prelievo, un DDT.
70-
- Avanzata: più prelievi in un DDT.
85+
- Base (predefinita): un prelievo, un DDT.
86+
- Avanzata: più prelievi in un DDT.
87+
88+
**Integrazione Fatturazione Elettronica**
89+
90+
Questo modulo si integra con la fatturazione elettronica italiana
91+
(``l10n_it_stock_ddt``).
92+
93+
Aggiunge automaticamente i riferimenti ai DDT nell'XML della FatturaPA,
94+
includendo:
95+
96+
- Numero del DDT
97+
- Data del DDT
98+
- Riferimenti alle righe
99+
100+
Il modulo gestisce anche la distinzione tra fatture immediate e
101+
differite:
102+
103+
- **TD01 (Fattura immediata)**: quando la fattura ha la stessa data dei
104+
DDT collegati
105+
- **TD24 (Fattura differita)**: quando la fattura è emessa in un giorno
106+
diverso rispetto ai DDT
71107

72108
**Table of contents**
73109

@@ -100,11 +136,14 @@ To configure this module, go to:
100136
In delivery note type you can specify if the product price have to be
101137
printed in the delivery note report/slip.
102138

103-
- *Inventory → Configuration → Delivery Notes → Conditions of
104-
Transport*
105-
- *Inventory → Configuration → Delivery Notes → Appearances of Goods*
106-
- *Inventory → Configuration → Delivery Notes → Reasons of Transport*
107-
- *Inventory → Configuration → Delivery Notes → Methods of Transport*
139+
- *Inventory → Configuration → Delivery Notes → Conditions of
140+
Transport*
141+
- *Inventory → Configuration → Delivery Notes → Appearances of
142+
Goods*
143+
- *Inventory → Configuration → Delivery Notes → Reasons of
144+
Transport*
145+
- *Inventory → Configuration → Delivery Notes → Methods of
146+
Transport*
108147

109148
3. *Settings → User & Companies → Users*
110149

@@ -142,10 +181,10 @@ Funzionalità avanzata
142181

143182
Vengono attivate varie funzionalità aggiuntive:
144183

145-
- più prelievi per un DDT
146-
- selezione multipla di prelievi e generazione dei DDT
147-
- aggiunta righe nota e righe sezione descrittive.
148-
- lista dei DDT.
184+
- più prelievi per un DDT
185+
- selezione multipla di prelievi e generazione dei DDT
186+
- aggiunta righe nota e righe sezione descrittive.
187+
- lista dei DDT.
149188

150189
Il report DDT stampa in righe aggiuntive i lotti/seriali e le scadenze
151190
del prodotto.
@@ -187,39 +226,39 @@ Authors
187226
Contributors
188227
------------
189228

190-
- Riccardo Bellanova <r.bellanova@apuliasoftware.it>
229+
- Riccardo Bellanova <r.bellanova@apuliasoftware.it>
191230

192-
- Matteo Bilotta <mbilotta@linkeurope.it>
231+
- Matteo Bilotta <mbilotta@linkeurope.it>
193232

194-
- Giuseppe Borruso <gborruso@dinamicheaziendali.it>
233+
- Giuseppe Borruso <gborruso@dinamicheaziendali.it>
195234

196-
- Marco Calcagni <mcalcagni@dinamicheaziendali.it>
235+
- Marco Calcagni <mcalcagni@dinamicheaziendali.it>
197236

198-
- Marco Colombo <marco.colombo@gmail.com>
237+
- Marco Colombo <marco.colombo@gmail.com>
199238

200-
- Gianmarco Conte <gconte@dinamicheaziendali.it>
239+
- Gianmarco Conte <gconte@dinamicheaziendali.it>
201240

202-
- Letizia Freda <letizia.freda@netfarm.it>
241+
- Letizia Freda <letizia.freda@netfarm.it>
203242

204-
- Andrea Piovesana <andrea.m.piovesana@gmail.com>
243+
- Andrea Piovesana <andrea.m.piovesana@gmail.com>
205244

206-
- Alex Comba <alex.comba@agilebg.com>
245+
- Alex Comba <alex.comba@agilebg.com>
207246

208-
- `Ooops <https://www.ooops404.com>`__:
247+
- `Ooops <https://www.ooops404.com>`__:
209248

210-
- Giovanni Serra <giovanni@gslab.it>
211-
- Foresti Francesco <francesco.foresti@ooops404.com>
249+
- Giovanni Serra <giovanni@gslab.it>
250+
- Foresti Francesco <francesco.foresti@ooops404.com>
212251

213-
- Nextev Srl <odoo@nextev.it>
252+
- Nextev Srl <odoo@nextev.it>
214253

215-
- `PyTech-SRL <https://www.pytech.it>`__:
254+
- `PyTech-SRL <https://www.pytech.it>`__:
216255

217-
- Alessandro Uffreduzzi <alessandro.uffreduzzi@pytech.it>
218-
- Sebastiano Picchi <sebastiano.picchi@pytech.it>
256+
- Alessandro Uffreduzzi <alessandro.uffreduzzi@pytech.it>
257+
- Sebastiano Picchi <sebastiano.picchi@pytech.it>
219258

220-
- `Aion Tech <https://aiontech.company/>`__:
259+
- `Aion Tech <https://aiontech.company/>`__:
221260

222-
- Simone Rubino <simone.rubino@aion-tech.it>
261+
- Simone Rubino <simone.rubino@aion-tech.it>
223262

224263
Maintainers
225264
-----------

l10n_it_delivery_note/__manifest__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"maintainers": ["MarcoCalcagni", "aleuffre", "renda-dev"],
2020
"depends": [
2121
"delivery_carrier_partner",
22+
"l10n_it_stock_ddt",
2223
"mail",
2324
"sale",
2425
"sale_stock",
@@ -34,6 +35,7 @@
3435
"security/res_groups.xml",
3536
"security/res_users.xml",
3637
"data/delivery_note_data.xml",
38+
"data/l10n_it_delivery_note_template.xml",
3739
"report/delivery_data.xml",
3840
"report/report_delivery_note.xml",
3941
"views/account_move.xml",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<template
4+
id="l10n_it_delivery_note_data"
5+
inherit_id="l10n_it_edi.account_invoice_it_FatturaPA_export"
6+
priority="99"
7+
>
8+
<!-- Replace the DatiDDT block with l10n_it_ddt_id condition -->
9+
<xpath expr='//DatiDDT[@t-if="record.l10n_it_ddt_id"]' position="replace">
10+
<t t-if="dati_ddt_list" t-foreach="dati_ddt_list" t-as="ddt_data">
11+
<DatiDDT>
12+
<NumeroDDT
13+
t-if="ddt_data.get('NumeroDDT')"
14+
t-esc="format_alphanumeric(ddt_data['NumeroDDT'][-20:])"
15+
/>
16+
<DataDDT t-esc="format_date(ddt_data['DataDDT'])" />
17+
<t
18+
t-if="ddt_data.get('RiferimentoNumeroLinea') and len(dati_ddt_list) > 1"
19+
t-foreach="ddt_data.get('RiferimentoNumeroLinea')"
20+
t-as="NumeroLinea"
21+
>
22+
<RiferimentoNumeroLinea t-esc="NumeroLinea" />
23+
</t>
24+
</DatiDDT>
25+
</t>
26+
</xpath>
27+
<!-- Replace the DatiDDT block with ddt_dict condition -->
28+
<xpath
29+
expr='//t[@t-if="ddt_dict and not record.l10n_it_ddt_id"]'
30+
position="replace"
31+
>
32+
<!-- Do nothing - we only want delivery note DDTs, not picking DDTs -->
33+
</xpath>
34+
</template>
35+
</odoo>

l10n_it_delivery_note/models/account_invoice.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,85 @@ def button_cancel(self): # pylint: disable=missing-return
167167
dn_lines.sync_invoice_status()
168168
dn_lines.delivery_note_id._compute_invoice_status()
169169
dn_lines.delivery_note_id.state = "confirm"
170+
171+
def _l10n_it_edi_invoice_is_direct(self):
172+
"""An invoice is direct if ddt are all done the same day as the invoice."""
173+
if self.delivery_note_ids:
174+
return all(
175+
ddt.date and ddt.date == self.invoice_date
176+
for ddt in self.delivery_note_ids
177+
)
178+
return super()._l10n_it_edi_invoice_is_direct()
179+
180+
def _l10n_it_edi_get_values(self, pdf_values=None):
181+
"""Extend to add dati_ddt_list for delivery notes."""
182+
values = super()._l10n_it_edi_get_values(pdf_values)
183+
values["dati_ddt_list"] = self._get_dati_ddt()
184+
return values
185+
186+
def _get_dati_ddt(self):
187+
"""
188+
Get the data for rendering DatiDDT.
189+
190+
:return: a list of dictionaries, with one dictionary per involved DdT.
191+
Each dictionary has shape:
192+
{
193+
'_delivery_note': <stock.delivery.note record of the involved the DdT>,
194+
'NumeroDDT': <string representing the DdT>,
195+
'DataDDT': <date of the DdT>,
196+
'_invoice_lines': (optional)
197+
<account.move.line records of invoice lines involved in the DdT>,
198+
'RiferimentoNumeroLinea': (optional)
199+
<list of integers representing invoice line numbers>,
200+
}
201+
"""
202+
self.ensure_one()
203+
dati_ddt_list = []
204+
205+
if not self.delivery_note_ids:
206+
return dati_ddt_list
207+
208+
e_invoice_lines = self.line_ids.filtered(
209+
lambda x: x.display_type == "product"
210+
).sorted(lambda line: line.sequence)
211+
e_invoice_lines_list = list(e_invoice_lines)
212+
213+
for delivery_note in self.delivery_note_ids:
214+
ddt_data = {
215+
"_delivery_note": delivery_note,
216+
"NumeroDDT": delivery_note.name,
217+
"DataDDT": delivery_note.date,
218+
}
219+
220+
# Find invoice lines linked to this delivery note
221+
e_invoice_delivery_note_lines = e_invoice_lines.filtered(
222+
lambda line, dn=delivery_note: line.delivery_note_id == dn
223+
)
224+
225+
if e_invoice_delivery_note_lines:
226+
# RiferimentoNumeroLinea contains 1-based line numbers
227+
lines_refs_list = [
228+
e_invoice_lines_list.index(line) + 1
229+
for line in e_invoice_delivery_note_lines
230+
]
231+
ddt_data.update(
232+
{
233+
"_invoice_lines": e_invoice_delivery_note_lines,
234+
"RiferimentoNumeroLinea": lines_refs_list,
235+
}
236+
)
237+
elif len(self.delivery_note_ids) == 1:
238+
# If there's only one DDT and no lines are linked, include all lines
239+
# This handles the case where update_delivery_note_lines() wasn't called
240+
ddt_data.update(
241+
{
242+
"_invoice_lines": e_invoice_lines,
243+
"RiferimentoNumeroLinea": list(
244+
range(1, len(e_invoice_lines_list) + 1)
245+
),
246+
}
247+
)
248+
249+
dati_ddt_list.append(ddt_data)
250+
251+
return dati_ddt_list

l10n_it_delivery_note/readme/DESCRIPTION.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ There are two available settings:
1717
- Base (default): one picking, one DN.
1818
- Advanced: more picking in one DN.
1919

20+
**Electronic Invoicing Integration**
21+
22+
This module integrates with Italian electronic invoicing (`l10n_it_stock_ddt`).
23+
24+
It automatically adds Delivery Note references to the FatturaPA XML, including:
25+
- DDT Number
26+
- DDT Date
27+
- Line references
28+
29+
The module also handles the distinction between immediate and deferred invoices:
30+
- **TD01 (Immediate invoice)**: when the invoice has the same date as the linked DDTs
31+
- **TD24 (Deferred invoice)**: when the invoice is issued on a different day than the DDTs
32+
2033
**Italiano**
2134

2235
Questo modulo consente di gestire i DDT.
@@ -34,3 +47,16 @@ Ci sono due impostazioni possibili.
3447

3548
- Base (predefinita): un prelievo, un DDT.
3649
- Avanzata: più prelievi in un DDT.
50+
51+
**Integrazione Fatturazione Elettronica**
52+
53+
Questo modulo si integra con la fatturazione elettronica italiana (`l10n_it_stock_ddt`).
54+
55+
Aggiunge automaticamente i riferimenti ai DDT nell'XML della FatturaPA, includendo:
56+
- Numero del DDT
57+
- Data del DDT
58+
- Riferimenti alle righe
59+
60+
Il modulo gestisce anche la distinzione tra fatture immediate e differite:
61+
- **TD01 (Fattura immediata)**: quando la fattura ha la stessa data dei DDT collegati
62+
- **TD24 (Fattura differita)**: quando la fattura è emessa in un giorno diverso rispetto ai DDT

0 commit comments

Comments
 (0)