odoo-addon-l10n-it-edi-extension 18.0.1.0.0.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odoo/addons/l10n_it_edi_extension/README.rst +493 -0
- odoo/addons/l10n_it_edi_extension/__init__.py +951 -0
- odoo/addons/l10n_it_edi_extension/__manifest__.py +37 -0
- odoo/addons/l10n_it_edi_extension/controllers/__init__.py +1 -0
- odoo/addons/l10n_it_edi_extension/controllers/portal.py +27 -0
- odoo/addons/l10n_it_edi_extension/data/FoglioStileAssoSoftware.xsl +3150 -0
- odoo/addons/l10n_it_edi_extension/data/invoice_it_template.xml +50 -0
- odoo/addons/l10n_it_edi_extension/data/res.city.it.code.csv +13898 -0
- odoo/addons/l10n_it_edi_extension/i18n/l10n_it_edi_extension.pot +1167 -0
- odoo/addons/l10n_it_edi_extension/i18n/l10n_it_edi_fatturapa.pot +44 -0
- odoo/addons/l10n_it_edi_extension/models/__init__.py +15 -0
- odoo/addons/l10n_it_edi_extension/models/account_journal.py +152 -0
- odoo/addons/l10n_it_edi_extension/models/account_move.py +765 -0
- odoo/addons/l10n_it_edi_extension/models/account_move_line.py +10 -0
- odoo/addons/l10n_it_edi_extension/models/ir_attachment.py +37 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_activity_progress.py +14 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_article_code.py +15 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_discount_rise_price.py +25 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_line.py +48 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_line_other_data.py +17 -0
- odoo/addons/l10n_it_edi_extension/models/l10n_it_edi_summary_data.py +77 -0
- odoo/addons/l10n_it_edi_extension/models/res_city_it_code.py +83 -0
- odoo/addons/l10n_it_edi_extension/models/res_company.py +62 -0
- odoo/addons/l10n_it_edi_extension/models/res_partner.py +64 -0
- odoo/addons/l10n_it_edi_extension/readme/CONFIGURE.md +45 -0
- odoo/addons/l10n_it_edi_extension/readme/CONTRIBUTORS.md +5 -0
- odoo/addons/l10n_it_edi_extension/readme/DESCRIPTION.md +160 -0
- odoo/addons/l10n_it_edi_extension/security/ir.model.access.csv +14 -0
- odoo/addons/l10n_it_edi_extension/static/description/icon.png +0 -0
- odoo/addons/l10n_it_edi_extension/static/description/index.html +832 -0
- odoo/addons/l10n_it_edi_extension/tests/__init__.py +2 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/IT01234567890_FPR03.xml +166 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/IT02780790107_11004.xml +216 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/IT02780790107_11005.xml +224 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/IT05979361218_003.xml +107 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/test.png +0 -0
- odoo/addons/l10n_it_edi_extension/tests/import_xmls/xml_import.zip +0 -0
- odoo/addons/l10n_it_edi_extension/tests/test_fiscalcode.py +126 -0
- odoo/addons/l10n_it_edi_extension/tests/test_import_edi_extension_xml.py +350 -0
- odoo/addons/l10n_it_edi_extension/views/company_view.xml +41 -0
- odoo/addons/l10n_it_edi_extension/views/l10n_it_view.xml +164 -0
- odoo/addons/l10n_it_edi_extension/views/res_partner_view.xml +19 -0
- odoo/addons/l10n_it_edi_extension/wizards/__init__.py +2 -0
- odoo/addons/l10n_it_edi_extension/wizards/compute_fc.py +176 -0
- odoo/addons/l10n_it_edi_extension/wizards/compute_fc_view.xml +65 -0
- odoo/addons/l10n_it_edi_extension/wizards/l10n_it_edi_import_file_wizard.py +98 -0
- odoo/addons/l10n_it_edi_extension/wizards/l10n_it_edi_import_file_wizard.xml +46 -0
- odoo_addon_l10n_it_edi_extension-18.0.1.0.0.30.dist-info/METADATA +513 -0
- odoo_addon_l10n_it_edi_extension-18.0.1.0.0.30.dist-info/RECORD +51 -0
- odoo_addon_l10n_it_edi_extension-18.0.1.0.0.30.dist-info/WHEEL +5 -0
- odoo_addon_l10n_it_edi_extension-18.0.1.0.0.30.dist-info/top_level.txt +1 -0
@@ -0,0 +1,951 @@
|
|
1
|
+
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
|
2
|
+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
3
|
+
|
4
|
+
from . import controllers
|
5
|
+
from . import models
|
6
|
+
from . import wizards
|
7
|
+
|
8
|
+
from odoo.tools import config
|
9
|
+
|
10
|
+
from openupgradelib import openupgrade, openupgrade_tools
|
11
|
+
|
12
|
+
from odoo.addons.base.models.ir_qweb_fields import Markup, nl2br, nl2br_enclose
|
13
|
+
|
14
|
+
OLD_MODULES = [
|
15
|
+
"l10n_it_fatturapa",
|
16
|
+
"l10n_it_fatturapa_in",
|
17
|
+
"l10n_it_fatturapa_out",
|
18
|
+
"l10n_it_fiscal_payment_term",
|
19
|
+
"l10n_it_fiscalcode",
|
20
|
+
"l10n_it_ipa",
|
21
|
+
"l10n_it_pec",
|
22
|
+
"l10n_it_rea",
|
23
|
+
"l10n_it_vat_payability",
|
24
|
+
]
|
25
|
+
|
26
|
+
|
27
|
+
def _l10n_it_fatturapa_pre_migration(env):
|
28
|
+
RENAMED_FIELDS = [
|
29
|
+
[
|
30
|
+
(
|
31
|
+
"account.move",
|
32
|
+
"protocol_number",
|
33
|
+
),
|
34
|
+
(
|
35
|
+
"account.move",
|
36
|
+
"l10n_it_edi_protocol_number",
|
37
|
+
),
|
38
|
+
],
|
39
|
+
[
|
40
|
+
(
|
41
|
+
"account.move",
|
42
|
+
"tax_representative_id",
|
43
|
+
),
|
44
|
+
(
|
45
|
+
"account.move",
|
46
|
+
"l10n_it_edi_tax_representative_id",
|
47
|
+
),
|
48
|
+
],
|
49
|
+
[
|
50
|
+
(
|
51
|
+
"account.move",
|
52
|
+
"sender",
|
53
|
+
),
|
54
|
+
(
|
55
|
+
"account.move",
|
56
|
+
"l10n_it_edi_sender",
|
57
|
+
),
|
58
|
+
],
|
59
|
+
[
|
60
|
+
(
|
61
|
+
"account.move",
|
62
|
+
"fatturapa_summary_ids",
|
63
|
+
),
|
64
|
+
(
|
65
|
+
"account.move",
|
66
|
+
"l10n_it_edi_summary_ids",
|
67
|
+
),
|
68
|
+
],
|
69
|
+
[
|
70
|
+
(
|
71
|
+
"account.move",
|
72
|
+
"activity_progress_ids",
|
73
|
+
),
|
74
|
+
(
|
75
|
+
"account.move",
|
76
|
+
"l10n_it_edi_activity_progress_ids",
|
77
|
+
),
|
78
|
+
],
|
79
|
+
[
|
80
|
+
(
|
81
|
+
"account.move",
|
82
|
+
"efatt_rounding",
|
83
|
+
),
|
84
|
+
(
|
85
|
+
"account.move",
|
86
|
+
"l10n_it_edi_rounding",
|
87
|
+
),
|
88
|
+
],
|
89
|
+
[
|
90
|
+
(
|
91
|
+
"account.move",
|
92
|
+
"art73",
|
93
|
+
),
|
94
|
+
(
|
95
|
+
"account.move",
|
96
|
+
"l10n_edi_it_art73",
|
97
|
+
),
|
98
|
+
],
|
99
|
+
[
|
100
|
+
(
|
101
|
+
"account.move",
|
102
|
+
"related_invoice_code",
|
103
|
+
),
|
104
|
+
(
|
105
|
+
"account.move",
|
106
|
+
"l10n_it_edi_related_invoice_code",
|
107
|
+
),
|
108
|
+
],
|
109
|
+
[
|
110
|
+
(
|
111
|
+
"account.move",
|
112
|
+
"related_invoice_code",
|
113
|
+
),
|
114
|
+
(
|
115
|
+
"account.move",
|
116
|
+
"l10n_it_edi_related_invoice_code",
|
117
|
+
),
|
118
|
+
],
|
119
|
+
[
|
120
|
+
(
|
121
|
+
"account.move",
|
122
|
+
"related_invoice_date",
|
123
|
+
),
|
124
|
+
(
|
125
|
+
"account.move",
|
126
|
+
"l10n_it_edi_related_invoice_date",
|
127
|
+
),
|
128
|
+
],
|
129
|
+
[
|
130
|
+
(
|
131
|
+
"account.move",
|
132
|
+
"efatt_stabile_organizzazione_indirizzo",
|
133
|
+
),
|
134
|
+
(
|
135
|
+
"account.move",
|
136
|
+
"l10n_it_edi_stabile_organizzazione_indirizzo",
|
137
|
+
),
|
138
|
+
],
|
139
|
+
[
|
140
|
+
(
|
141
|
+
"account.move",
|
142
|
+
"efatt_stabile_organizzazione_civico",
|
143
|
+
),
|
144
|
+
(
|
145
|
+
"account.move",
|
146
|
+
"l10n_it_edi_stabile_organizzazione_civico",
|
147
|
+
),
|
148
|
+
],
|
149
|
+
[
|
150
|
+
(
|
151
|
+
"account.move",
|
152
|
+
"efatt_stabile_organizzazione_cap",
|
153
|
+
),
|
154
|
+
(
|
155
|
+
"account.move",
|
156
|
+
"l10n_it_edi_stabile_organizzazione_cap",
|
157
|
+
),
|
158
|
+
],
|
159
|
+
[
|
160
|
+
(
|
161
|
+
"account.move",
|
162
|
+
"efatt_stabile_organizzazione_comune",
|
163
|
+
),
|
164
|
+
(
|
165
|
+
"account.move",
|
166
|
+
"l10n_it_edi_stabile_organizzazione_comune",
|
167
|
+
),
|
168
|
+
],
|
169
|
+
[
|
170
|
+
(
|
171
|
+
"account.move",
|
172
|
+
"efatt_stabile_organizzazione_provincia",
|
173
|
+
),
|
174
|
+
(
|
175
|
+
"account.move",
|
176
|
+
"l10n_it_edi_stabile_organizzazione_provincia",
|
177
|
+
),
|
178
|
+
],
|
179
|
+
[
|
180
|
+
(
|
181
|
+
"account.move",
|
182
|
+
"efatt_stabile_organizzazione_nazione",
|
183
|
+
),
|
184
|
+
(
|
185
|
+
"account.move",
|
186
|
+
"l10n_it_edi_stabile_organizzazione_nazione",
|
187
|
+
),
|
188
|
+
],
|
189
|
+
[
|
190
|
+
(
|
191
|
+
"account.move",
|
192
|
+
"efatt_stabile_organizzazione_nazione",
|
193
|
+
),
|
194
|
+
(
|
195
|
+
"account.move",
|
196
|
+
"l10n_it_edi_stabile_organizzazione_nazione",
|
197
|
+
),
|
198
|
+
],
|
199
|
+
[
|
200
|
+
(
|
201
|
+
"account.move.line",
|
202
|
+
"admin_ref",
|
203
|
+
),
|
204
|
+
(
|
205
|
+
"account.move.line",
|
206
|
+
"l10n_it_edi_admin_ref",
|
207
|
+
),
|
208
|
+
],
|
209
|
+
[
|
210
|
+
(
|
211
|
+
"res.partner",
|
212
|
+
"eori_code",
|
213
|
+
),
|
214
|
+
(
|
215
|
+
"res.partner",
|
216
|
+
"l10n_edi_it_eori_code",
|
217
|
+
),
|
218
|
+
],
|
219
|
+
[
|
220
|
+
(
|
221
|
+
"res.partner",
|
222
|
+
"electronic_invoice_no_contact_update",
|
223
|
+
),
|
224
|
+
(
|
225
|
+
"res.partner",
|
226
|
+
"l10n_edi_it_electronic_invoice_no_contact_update",
|
227
|
+
),
|
228
|
+
],
|
229
|
+
[
|
230
|
+
(
|
231
|
+
"res.partner",
|
232
|
+
"register",
|
233
|
+
),
|
234
|
+
(
|
235
|
+
"res.partner",
|
236
|
+
"l10n_edi_it_register",
|
237
|
+
),
|
238
|
+
],
|
239
|
+
[
|
240
|
+
(
|
241
|
+
"res.partner",
|
242
|
+
"register_province",
|
243
|
+
),
|
244
|
+
(
|
245
|
+
"res.partner",
|
246
|
+
"l10n_edi_it_register_province_id",
|
247
|
+
),
|
248
|
+
],
|
249
|
+
[
|
250
|
+
(
|
251
|
+
"res.partner",
|
252
|
+
"register_code",
|
253
|
+
),
|
254
|
+
(
|
255
|
+
"res.partner",
|
256
|
+
"l10n_edi_it_register_code",
|
257
|
+
),
|
258
|
+
],
|
259
|
+
[
|
260
|
+
(
|
261
|
+
"res.partner",
|
262
|
+
"register_regdate",
|
263
|
+
),
|
264
|
+
(
|
265
|
+
"res.partner",
|
266
|
+
"l10n_edi_it_register_regdate",
|
267
|
+
),
|
268
|
+
],
|
269
|
+
[
|
270
|
+
(
|
271
|
+
"res.company",
|
272
|
+
"fatturapa_art73",
|
273
|
+
),
|
274
|
+
(
|
275
|
+
"res.company",
|
276
|
+
"l10n_edi_it_art73",
|
277
|
+
),
|
278
|
+
],
|
279
|
+
[
|
280
|
+
(
|
281
|
+
"res.company",
|
282
|
+
"fatturapa_pub_administration_ref",
|
283
|
+
),
|
284
|
+
(
|
285
|
+
"res.company",
|
286
|
+
"l10n_edi_it_admin_ref",
|
287
|
+
),
|
288
|
+
],
|
289
|
+
[
|
290
|
+
(
|
291
|
+
"res.company",
|
292
|
+
"fatturapa_stabile_organizzazione",
|
293
|
+
),
|
294
|
+
(
|
295
|
+
"res.company",
|
296
|
+
"l10n_edi_it_stable_organization",
|
297
|
+
),
|
298
|
+
],
|
299
|
+
]
|
300
|
+
field_spec = []
|
301
|
+
for renamed_field in RENAMED_FIELDS:
|
302
|
+
(old_model, old_field), (new_model, new_field) = renamed_field
|
303
|
+
field_spec.append(
|
304
|
+
(
|
305
|
+
old_model,
|
306
|
+
new_model.replace(".", "_"),
|
307
|
+
old_field,
|
308
|
+
new_field,
|
309
|
+
)
|
310
|
+
)
|
311
|
+
openupgrade.rename_fields(
|
312
|
+
env,
|
313
|
+
field_spec,
|
314
|
+
)
|
315
|
+
|
316
|
+
|
317
|
+
def _l10n_it_fatturapa_post_migration_related_ddt(env):
|
318
|
+
env.cr.execute("""
|
319
|
+
SELECT invoice_id, invoice_line_id, name, date
|
320
|
+
FROM fatturapa_related_ddt
|
321
|
+
WHERE invoice_id IS NOT NULL OR invoice_line_id IS NOT NULL
|
322
|
+
""")
|
323
|
+
rows = env.cr.fetchall()
|
324
|
+
invoice_map = {}
|
325
|
+
for row in rows:
|
326
|
+
invoice_id, invoice_line_id, name, date = row
|
327
|
+
move_id = (
|
328
|
+
invoice_id or env["account.move.line"].browse(invoice_line_id).move_id.id
|
329
|
+
)
|
330
|
+
if move_id:
|
331
|
+
invoice_map.setdefault(move_id, []).append((name, date))
|
332
|
+
|
333
|
+
moves = env["account.move"].browse(invoice_map.keys())
|
334
|
+
for move in moves:
|
335
|
+
for name, date in invoice_map[move.id]:
|
336
|
+
ddt_tags = Markup('<ul class="mb-0">{}</ul>').format(
|
337
|
+
Markup().join(
|
338
|
+
nl2br_enclose(" ".join(tag.split()), "li")
|
339
|
+
for tag in [
|
340
|
+
f"NumeroDDT: {name}",
|
341
|
+
f'DataDDT: {date or "N/A"}',
|
342
|
+
]
|
343
|
+
)
|
344
|
+
)
|
345
|
+
message = Markup("{} {}<br/>{}").format(
|
346
|
+
"DatiDDT", env._("from XML file:"), ddt_tags
|
347
|
+
)
|
348
|
+
move.sudo().message_post(body=message)
|
349
|
+
|
350
|
+
|
351
|
+
def _l10n_it_fatturapa_post_migration_delivery_data(env):
|
352
|
+
env.cr.execute("""
|
353
|
+
SELECT
|
354
|
+
am.id AS move_id,
|
355
|
+
rp.name AS carrier_name,
|
356
|
+
rp.license_number AS license_number,
|
357
|
+
am.transport_vehicle,
|
358
|
+
am.transport_reason,
|
359
|
+
am.number_items,
|
360
|
+
am.description,
|
361
|
+
am.unit_weight,
|
362
|
+
am.gross_weight,
|
363
|
+
am.net_weight,
|
364
|
+
am.pickup_datetime,
|
365
|
+
am.transport_date,
|
366
|
+
am.delivery_address,
|
367
|
+
am.delivery_datetime,
|
368
|
+
am.ftpa_incoterms
|
369
|
+
FROM account_move am
|
370
|
+
LEFT JOIN res_partner rp ON am.carrier_id = rp.id
|
371
|
+
""")
|
372
|
+
rows = env.cr.fetchall()
|
373
|
+
invoice_map = {}
|
374
|
+
for row in rows:
|
375
|
+
move_id, *delivery_data = row
|
376
|
+
invoice_map.setdefault(move_id, []).append(tuple(delivery_data))
|
377
|
+
|
378
|
+
moves = env["account.move"].browse(invoice_map.keys())
|
379
|
+
for move in moves:
|
380
|
+
for delivery_data in invoice_map[move.id]:
|
381
|
+
(
|
382
|
+
carrier_name,
|
383
|
+
license_number,
|
384
|
+
transport_vehicle,
|
385
|
+
transport_reason,
|
386
|
+
number_items,
|
387
|
+
description,
|
388
|
+
unit_weight,
|
389
|
+
gross_weight,
|
390
|
+
net_weight,
|
391
|
+
pickup_datetime,
|
392
|
+
transport_date,
|
393
|
+
delivery_address,
|
394
|
+
delivery_datetime,
|
395
|
+
ftpa_incoterms,
|
396
|
+
) = delivery_data
|
397
|
+
delivery_tags = Markup('<ul class="mb-0">{}</ul>').format(
|
398
|
+
Markup().join(
|
399
|
+
nl2br_enclose(" ".join(tag.split()), "li")
|
400
|
+
for tag in [
|
401
|
+
f'Carrier: {carrier_name or "N/A"}',
|
402
|
+
f'NumeroLicenzaGuida: {license_number or "N/A"}',
|
403
|
+
f'MezzoTrasporto: {transport_vehicle or "N/A"}',
|
404
|
+
f'CausaleTrasporto: {transport_reason or "N/A"}',
|
405
|
+
f'NumeroColli: {number_items or "N/A"}',
|
406
|
+
f'Descrizione: {description or "N/A"}',
|
407
|
+
f'UnitaMisuraPeso: {unit_weight or "N/A"}',
|
408
|
+
f'PesoLordo: {gross_weight or "N/A"}',
|
409
|
+
f'PesoNetto: {net_weight or "N/A"}',
|
410
|
+
f'DataOraRitiro: {pickup_datetime or "N/A"}',
|
411
|
+
f'DataInizioTrasporto: {transport_date or "N/A"}',
|
412
|
+
f'IndirizzoResa: {delivery_address or "N/A"}',
|
413
|
+
f'DataOraConsegna: {delivery_datetime or "N/A"}',
|
414
|
+
f'TipoResa: {ftpa_incoterms or "N/A"}',
|
415
|
+
]
|
416
|
+
)
|
417
|
+
)
|
418
|
+
message = Markup("{} {}<br/>{}").format(
|
419
|
+
"DatiTrasporto", env._("from XML file:"), delivery_tags
|
420
|
+
)
|
421
|
+
move.sudo().message_post(body=message)
|
422
|
+
|
423
|
+
|
424
|
+
def _l10n_it_fatturapa_post_migration_vehicle_data(env):
|
425
|
+
env.cr.execute("""
|
426
|
+
SELECT
|
427
|
+
id AS move_id,
|
428
|
+
vehicle_registration,
|
429
|
+
total_travel
|
430
|
+
FROM account_move
|
431
|
+
WHERE
|
432
|
+
vehicle_registration IS NOT NULL
|
433
|
+
OR total_travel IS NOT NULL
|
434
|
+
""")
|
435
|
+
rows = env.cr.fetchall()
|
436
|
+
invoice_map = {}
|
437
|
+
for row in rows:
|
438
|
+
move_id, *vehicle_data = row
|
439
|
+
invoice_map.setdefault(move_id, []).append(tuple(vehicle_data))
|
440
|
+
|
441
|
+
moves = env["account.move"].browse(invoice_map.keys())
|
442
|
+
for move in moves:
|
443
|
+
for vehicle_data in invoice_map[move.id]:
|
444
|
+
vehicle_registration, total_travel = vehicle_data
|
445
|
+
vehicle_tags = Markup('<ul class="mb-0">{}</ul>').format(
|
446
|
+
Markup().join(
|
447
|
+
nl2br_enclose(" ".join(tag.split()), "li")
|
448
|
+
for tag in [
|
449
|
+
f'Data: {vehicle_registration or "N/A"}',
|
450
|
+
f'TotalePercorso: {total_travel or "N/A"}',
|
451
|
+
]
|
452
|
+
)
|
453
|
+
)
|
454
|
+
message = Markup("{} {}<br/>{}").format(
|
455
|
+
"DatiVeicoli", env._("from XML file:"), vehicle_tags
|
456
|
+
)
|
457
|
+
move.sudo().message_post(body=message)
|
458
|
+
|
459
|
+
|
460
|
+
def _l10n_it_fatturapa_post_migration_payment_data(env):
|
461
|
+
env.cr.execute("""
|
462
|
+
SELECT
|
463
|
+
fpd.invoice_id,
|
464
|
+
fpt.code AS term_code,
|
465
|
+
fpdl.recipient,
|
466
|
+
fpm.code AS method_code,
|
467
|
+
fpdl.payment_term_start,
|
468
|
+
fpdl.payment_days,
|
469
|
+
fpdl.payment_due_date,
|
470
|
+
fpdl.payment_amount,
|
471
|
+
fpdl.post_office_code,
|
472
|
+
fpdl.recepit_surname,
|
473
|
+
fpdl.recepit_name,
|
474
|
+
fpdl.recepit_cf,
|
475
|
+
fpdl.recepit_title,
|
476
|
+
fpdl.payment_bank_name,
|
477
|
+
fpdl.payment_bank_iban,
|
478
|
+
fpdl.payment_bank_abi,
|
479
|
+
fpdl.payment_bank_cab,
|
480
|
+
fpdl.payment_bank_bic,
|
481
|
+
fpdl.prepayment_discount,
|
482
|
+
fpdl.max_payment_date,
|
483
|
+
fpdl.penalty_amount,
|
484
|
+
fpdl.penalty_date,
|
485
|
+
fpdl.payment_code
|
486
|
+
FROM fatturapa_payment_data fpd
|
487
|
+
LEFT JOIN fatturapa_payment_term fpt ON fpd.payment_terms = fpt.id
|
488
|
+
LEFT JOIN fatturapa_payment_detail fpdl ON fpd.id = fpdl.payment_data_id
|
489
|
+
LEFT JOIN fatturapa_payment_method fpm ON fpdl.fatturapa_pm_id = fpm.id
|
490
|
+
""")
|
491
|
+
rows = env.cr.fetchall()
|
492
|
+
invoice_map = {}
|
493
|
+
for row in rows:
|
494
|
+
invoice_id, *payment_data = row
|
495
|
+
invoice_map.setdefault(invoice_id, []).append(tuple(payment_data))
|
496
|
+
|
497
|
+
moves = env["account.move"].browse(invoice_map.keys())
|
498
|
+
for move in moves:
|
499
|
+
for payment_data in invoice_map[move.id]:
|
500
|
+
(
|
501
|
+
term_code,
|
502
|
+
recipient,
|
503
|
+
method_code,
|
504
|
+
payment_term_start,
|
505
|
+
payment_days,
|
506
|
+
payment_due_date,
|
507
|
+
payment_amount,
|
508
|
+
post_office_code,
|
509
|
+
recepit_surname,
|
510
|
+
recepit_name,
|
511
|
+
recepit_cf,
|
512
|
+
recepit_title,
|
513
|
+
payment_bank_name,
|
514
|
+
payment_bank_iban,
|
515
|
+
payment_bank_abi,
|
516
|
+
payment_bank_cab,
|
517
|
+
payment_bank_bic,
|
518
|
+
prepayment_discount,
|
519
|
+
max_payment_date,
|
520
|
+
penalty_amount,
|
521
|
+
penalty_date,
|
522
|
+
payment_code,
|
523
|
+
) = payment_data
|
524
|
+
payment_tags = Markup('<ul class="mb-0">{}</ul>').format(
|
525
|
+
Markup().join(
|
526
|
+
nl2br_enclose(" ".join(tag.split()), "li")
|
527
|
+
for tag in [
|
528
|
+
f'CondizioniPagamento: {term_code or "N/A"}',
|
529
|
+
f'Beneficiario: {recipient or "N/A"}',
|
530
|
+
f'ModalitaPagamento: {method_code or "N/A"}',
|
531
|
+
f'DataRiferimentoTerminiPagamento: {payment_term_start or "N/A"}', # noqa: E501
|
532
|
+
f'GiorniTerminiPagamento: {payment_days or "N/A"}',
|
533
|
+
f'DataScadenzaPagamento: {payment_due_date or "N/A"}',
|
534
|
+
f'ImportoPagamento: {payment_amount or "N/A"}',
|
535
|
+
f'CodUfficioPostale: {post_office_code or "N/A"}',
|
536
|
+
f'CognomeQuietanzante: {recepit_surname or "N/A"}',
|
537
|
+
f'NomeQuietanzante: {recepit_name or "N/A"}',
|
538
|
+
f'CFQuietanzante: {recepit_cf or "N/A"}',
|
539
|
+
f'TitoloQuietanzante: {recepit_title or "N/A"}',
|
540
|
+
f'IstitutoFinanziario: {payment_bank_name or "N/A"}',
|
541
|
+
f'IBAN: {payment_bank_iban or "N/A"}',
|
542
|
+
f'ABI: {payment_bank_abi or "N/A"}',
|
543
|
+
f'CAB: {payment_bank_cab or "N/A"}',
|
544
|
+
f'BIC: {payment_bank_bic or "N/A"}',
|
545
|
+
f'ScontoPagamentoAnticipato: {prepayment_discount or "N/A"}',
|
546
|
+
f'DataLimitePagamentoAnticipato: {max_payment_date or "N/A"}',
|
547
|
+
f'PenalitaPagamentiRitardati: {penalty_amount or "N/A"}',
|
548
|
+
f'DataDecorrenzaPenale: {penalty_date or "N/A"}',
|
549
|
+
f'CodicePagamento: {payment_code or "N/A"}',
|
550
|
+
]
|
551
|
+
)
|
552
|
+
)
|
553
|
+
message = Markup("{} {}<br/>{}").format(
|
554
|
+
"DatiPagamento", env._("from XML file:"), payment_tags
|
555
|
+
)
|
556
|
+
move.sudo().message_post(body=message)
|
557
|
+
|
558
|
+
|
559
|
+
def _l10n_it_fatturapa_post_migration(env):
|
560
|
+
query = """
|
561
|
+
UPDATE res_partner
|
562
|
+
SET
|
563
|
+
l10n_it_pa_index = codice_destinatario,
|
564
|
+
l10n_it_pec_email = pec_destinatario
|
565
|
+
"""
|
566
|
+
openupgrade.logged_query(env.cr, query)
|
567
|
+
|
568
|
+
query = """
|
569
|
+
UPDATE res_company
|
570
|
+
SET l10n_it_tax_system = fp.code
|
571
|
+
FROM res_partner rp
|
572
|
+
LEFT JOIN fatturapa_fiscal_position fp ON rp.register_fiscalpos = fp.id
|
573
|
+
WHERE res_company.partner_id = rp.id AND rp.register_fiscalpos IS NOT NULL
|
574
|
+
"""
|
575
|
+
openupgrade.logged_query(env.cr, query)
|
576
|
+
|
577
|
+
query = """
|
578
|
+
UPDATE ir_attachment
|
579
|
+
SET res_model = 'account.move', res_id = fa.invoice_id
|
580
|
+
FROM fatturapa_attachments fa
|
581
|
+
WHERE ir_attachment.id = fa.ir_attachment_id
|
582
|
+
"""
|
583
|
+
openupgrade.logged_query(env.cr, query)
|
584
|
+
|
585
|
+
query = """
|
586
|
+
UPDATE account_move_line
|
587
|
+
SET sequence = ftpa_line_number
|
588
|
+
"""
|
589
|
+
openupgrade.logged_query(env.cr, query)
|
590
|
+
|
591
|
+
query = """
|
592
|
+
UPDATE res_company
|
593
|
+
SET l10n_it_tax_representative_partner_id = fatturapa_tax_representative
|
594
|
+
"""
|
595
|
+
openupgrade.logged_query(env.cr, query)
|
596
|
+
|
597
|
+
if openupgrade_tools.table_exists(env.cr, "fatturapa_activity_progress"):
|
598
|
+
env.cr.execute("SELECT * FROM fatturapa_activity_progress LIMIT 1")
|
599
|
+
if env.cr.fetchone():
|
600
|
+
openupgrade.logged_query(
|
601
|
+
env.cr,
|
602
|
+
"""
|
603
|
+
INSERT INTO
|
604
|
+
l10n_it_edi_activity_progress (activity_progress, invoice_id)
|
605
|
+
SELECT
|
606
|
+
fatturapa_activity_progress, invoice_id
|
607
|
+
FROM
|
608
|
+
fatturapa_activity_progress
|
609
|
+
""",
|
610
|
+
)
|
611
|
+
|
612
|
+
if openupgrade_tools.table_exists(env.cr, "fatturapa_summary_data"):
|
613
|
+
env.cr.execute("SELECT * FROM fatturapa_summary_data LIMIT 1")
|
614
|
+
if env.cr.fetchone():
|
615
|
+
openupgrade.logged_query(
|
616
|
+
env.cr,
|
617
|
+
"""
|
618
|
+
INSERT INTO
|
619
|
+
l10n_it_edi_summary_data (
|
620
|
+
tax_rate, non_taxable_nature, incidental_charges, rounding,
|
621
|
+
amount_untaxed, amount_tax, payability, law_reference,
|
622
|
+
invoice_id
|
623
|
+
)
|
624
|
+
SELECT
|
625
|
+
tax_rate, non_taxable_nature, incidental_charges, rounding,
|
626
|
+
amount_untaxed, amount_tax, payability, law_reference,
|
627
|
+
invoice_id
|
628
|
+
FROM
|
629
|
+
fatturapa_summary_data
|
630
|
+
""",
|
631
|
+
)
|
632
|
+
|
633
|
+
_l10n_it_fatturapa_post_migration_related_ddt(env)
|
634
|
+
_l10n_it_fatturapa_post_migration_delivery_data(env)
|
635
|
+
_l10n_it_fatturapa_post_migration_vehicle_data(env)
|
636
|
+
_l10n_it_fatturapa_post_migration_payment_data(env)
|
637
|
+
|
638
|
+
|
639
|
+
def _l10n_it_fatturapa_in_pre_migration(env):
|
640
|
+
RENAMED_FIELDS = [
|
641
|
+
[
|
642
|
+
(
|
643
|
+
"account.move",
|
644
|
+
"e_invoice_line_ids",
|
645
|
+
),
|
646
|
+
(
|
647
|
+
"account.move",
|
648
|
+
"l10n_it_edi_line_ids",
|
649
|
+
),
|
650
|
+
],
|
651
|
+
[
|
652
|
+
(
|
653
|
+
"account.move",
|
654
|
+
"e_invoice_amount_untaxed",
|
655
|
+
),
|
656
|
+
(
|
657
|
+
"account.move",
|
658
|
+
"l10n_it_edi_amount_untaxed",
|
659
|
+
),
|
660
|
+
],
|
661
|
+
[
|
662
|
+
(
|
663
|
+
"account.move",
|
664
|
+
"e_invoice_amount_tax",
|
665
|
+
),
|
666
|
+
(
|
667
|
+
"account.move",
|
668
|
+
"l10n_it_edi_amount_tax",
|
669
|
+
),
|
670
|
+
],
|
671
|
+
[
|
672
|
+
(
|
673
|
+
"account.move",
|
674
|
+
"e_invoice_amount_total",
|
675
|
+
),
|
676
|
+
(
|
677
|
+
"account.move",
|
678
|
+
"l10n_it_edi_amount_total",
|
679
|
+
),
|
680
|
+
],
|
681
|
+
]
|
682
|
+
|
683
|
+
field_spec = []
|
684
|
+
for renamed_field in RENAMED_FIELDS:
|
685
|
+
(old_model, old_field), (new_model, new_field) = renamed_field
|
686
|
+
field_spec.append(
|
687
|
+
(
|
688
|
+
old_model,
|
689
|
+
new_model.replace(".", "_"),
|
690
|
+
old_field,
|
691
|
+
new_field,
|
692
|
+
)
|
693
|
+
)
|
694
|
+
openupgrade.rename_fields(
|
695
|
+
env,
|
696
|
+
field_spec,
|
697
|
+
)
|
698
|
+
|
699
|
+
|
700
|
+
def _l10n_it_fatturapa_in_post_migration(env):
|
701
|
+
query = """
|
702
|
+
UPDATE account_move
|
703
|
+
SET ref = e_invoice_reference
|
704
|
+
WHERE e_invoice_reference IS NOT NULL
|
705
|
+
"""
|
706
|
+
openupgrade.logged_query(env.cr, query)
|
707
|
+
|
708
|
+
if openupgrade_tools.table_exists(env.cr, "einvoice_line"):
|
709
|
+
env.cr.execute("SELECT * FROM einvoice_line LIMIT 1")
|
710
|
+
if env.cr.fetchone():
|
711
|
+
openupgrade.logged_query(
|
712
|
+
env.cr,
|
713
|
+
"""
|
714
|
+
INSERT INTO
|
715
|
+
l10n_it_edi_line (
|
716
|
+
id, invoice_id, line_number, service_type, name, qty, uom,
|
717
|
+
period_start_date, period_end_date, unit_price,
|
718
|
+
total_price, tax_amount, wt_amount, tax_kind
|
719
|
+
)
|
720
|
+
SELECT
|
721
|
+
id, invoice_id, line_number, service_type, name, qty, uom,
|
722
|
+
period_start_date, period_end_date, unit_price,
|
723
|
+
total_price, tax_amount, wt_amount, tax_kind
|
724
|
+
FROM
|
725
|
+
einvoice_line
|
726
|
+
""",
|
727
|
+
)
|
728
|
+
|
729
|
+
if openupgrade_tools.table_exists(env.cr, "fatturapa_article_code"):
|
730
|
+
env.cr.execute("SELECT * FROM fatturapa_article_code LIMIT 1")
|
731
|
+
if env.cr.fetchone():
|
732
|
+
openupgrade.logged_query(
|
733
|
+
env.cr,
|
734
|
+
"""
|
735
|
+
INSERT INTO
|
736
|
+
l10n_it_edi_article_code (name, code_val, l10n_it_edi_line_id)
|
737
|
+
SELECT
|
738
|
+
name, code_val, e_invoice_line_id
|
739
|
+
FROM
|
740
|
+
fatturapa_article_code
|
741
|
+
""",
|
742
|
+
)
|
743
|
+
|
744
|
+
if openupgrade_tools.table_exists(env.cr, "discount_rise_price"):
|
745
|
+
env.cr.execute("SELECT * FROM discount_rise_price LIMIT 1")
|
746
|
+
if env.cr.fetchone():
|
747
|
+
openupgrade.logged_query(
|
748
|
+
env.cr,
|
749
|
+
"""
|
750
|
+
INSERT INTO
|
751
|
+
l10n_it_edi_discount_rise_price (
|
752
|
+
name, percentage, amount, invoice_line_id, invoice_id,
|
753
|
+
l10n_it_edi_line_id
|
754
|
+
)
|
755
|
+
SELECT
|
756
|
+
name, percentage, amount, invoice_line_id, invoice_id,
|
757
|
+
e_invoice_line_id
|
758
|
+
FROM
|
759
|
+
discount_rise_price
|
760
|
+
""",
|
761
|
+
)
|
762
|
+
|
763
|
+
if openupgrade_tools.table_exists(env.cr, "einvoice_line_other_data"):
|
764
|
+
env.cr.execute("SELECT * FROM einvoice_line_other_data LIMIT 1")
|
765
|
+
if env.cr.fetchone():
|
766
|
+
openupgrade.logged_query(
|
767
|
+
env.cr,
|
768
|
+
"""
|
769
|
+
INSERT INTO
|
770
|
+
l10n_it_edi_line_other_data (
|
771
|
+
l10n_it_edi_line_id, name, text_ref, num_ref, date_ref
|
772
|
+
)
|
773
|
+
SELECT
|
774
|
+
e_invoice_line_id, name, text_ref, num_ref, date_ref
|
775
|
+
FROM
|
776
|
+
einvoice_line_other_data
|
777
|
+
""",
|
778
|
+
)
|
779
|
+
|
780
|
+
env.cr.execute("""
|
781
|
+
SELECT
|
782
|
+
am.id,
|
783
|
+
fai.ir_attachment_id AS attachment_id
|
784
|
+
FROM account_move am
|
785
|
+
JOIN fatturapa_attachment_in fai ON fai.id = am.fatturapa_attachment_in_id
|
786
|
+
WHERE am.fatturapa_attachment_in_id IS NOT NULL
|
787
|
+
""")
|
788
|
+
rows = env.cr.fetchall()
|
789
|
+
for row in rows:
|
790
|
+
invoice_id, attachment_id = row
|
791
|
+
move = env["account.move"].browse(invoice_id)
|
792
|
+
attachment = env["ir.attachment"].browse(attachment_id)
|
793
|
+
attachment.res_model = "account.move"
|
794
|
+
attachment.res_id = move.id
|
795
|
+
attachment.res_field = "l10n_it_edi_attachment_file"
|
796
|
+
|
797
|
+
|
798
|
+
def _l10n_it_fatturapa_out_post_migration(env):
|
799
|
+
updates = {
|
800
|
+
"ready": "being_sent",
|
801
|
+
"sent": "processing",
|
802
|
+
"delivered": "forwarded",
|
803
|
+
"accepted": "accepted_by_pa_partner",
|
804
|
+
"error": "forward_failed",
|
805
|
+
}
|
806
|
+
|
807
|
+
for fatturapa_state, l10n_it_edi_state in updates.items():
|
808
|
+
query = f"""
|
809
|
+
UPDATE account_move
|
810
|
+
SET l10n_it_edi_state = '{l10n_it_edi_state}'
|
811
|
+
WHERE fatturapa_state = '{fatturapa_state}'
|
812
|
+
"""
|
813
|
+
openupgrade.logged_query(env.cr, query)
|
814
|
+
|
815
|
+
env.cr.execute("""
|
816
|
+
SELECT
|
817
|
+
am.id,
|
818
|
+
fao.ir_attachment_id AS attachment_id
|
819
|
+
FROM account_move am
|
820
|
+
JOIN fatturapa_attachment_out fao ON fao.id = am.fatturapa_attachment_out_id
|
821
|
+
WHERE am.fatturapa_attachment_out_id IS NOT NULL
|
822
|
+
""")
|
823
|
+
rows = env.cr.fetchall()
|
824
|
+
for row in rows:
|
825
|
+
invoice_id, attachment_id = row
|
826
|
+
move = env["account.move"].browse(invoice_id)
|
827
|
+
attachment = env["ir.attachment"].browse(attachment_id)
|
828
|
+
attachment.res_model = "account.move"
|
829
|
+
attachment.res_id = move.id
|
830
|
+
attachment.res_field = "l10n_it_edi_attachment_file"
|
831
|
+
|
832
|
+
|
833
|
+
def _l10n_it_fiscal_payment_term_post_migration(env):
|
834
|
+
if not openupgrade.column_exists(env.cr, "account_move", "l10n_it_payment_method"):
|
835
|
+
field_spec = [
|
836
|
+
(
|
837
|
+
"l10n_it_payment_method",
|
838
|
+
"account.move",
|
839
|
+
"account_move",
|
840
|
+
"selection",
|
841
|
+
"selection",
|
842
|
+
"l10n_it_edi_ndd",
|
843
|
+
False,
|
844
|
+
)
|
845
|
+
]
|
846
|
+
openupgrade.add_fields(env, field_spec)
|
847
|
+
|
848
|
+
query = """
|
849
|
+
UPDATE account_move
|
850
|
+
SET l10n_it_payment_method = fpm.code
|
851
|
+
FROM account_payment_term apt
|
852
|
+
LEFT JOIN fatturapa_payment_method fpm ON apt.fatturapa_pm_id = fpm.id
|
853
|
+
WHERE account_move.invoice_payment_term_id = apt.id
|
854
|
+
"""
|
855
|
+
openupgrade.logged_query(env.cr, query)
|
856
|
+
|
857
|
+
|
858
|
+
def _l10n_it_fiscalcode_post_migration(env):
|
859
|
+
query = """
|
860
|
+
UPDATE res_partner
|
861
|
+
SET l10n_it_codice_fiscale = fiscalcode
|
862
|
+
WHERE
|
863
|
+
fiscalcode IS NOT NULL
|
864
|
+
AND LENGTH(TRIM(fiscalcode)) >= 11
|
865
|
+
"""
|
866
|
+
openupgrade.logged_query(env.cr, query)
|
867
|
+
|
868
|
+
query = """
|
869
|
+
UPDATE res_company
|
870
|
+
SET l10n_it_codice_fiscale = fiscalcode
|
871
|
+
WHERE
|
872
|
+
fiscalcode IS NOT NULL
|
873
|
+
AND LENGTH(TRIM(fiscalcode)) >= 11
|
874
|
+
"""
|
875
|
+
openupgrade.logged_query(env.cr, query)
|
876
|
+
|
877
|
+
|
878
|
+
def _l10n_it_ipa_post_migration(env):
|
879
|
+
query = """
|
880
|
+
UPDATE res_partner
|
881
|
+
SET l10n_it_pa_index = ipa_code
|
882
|
+
WHERE ipa_code IS NOT NULL
|
883
|
+
"""
|
884
|
+
openupgrade.logged_query(env.cr, query)
|
885
|
+
|
886
|
+
|
887
|
+
def _l10n_it_pec_post_migration(env):
|
888
|
+
query = """
|
889
|
+
UPDATE res_partner
|
890
|
+
SET l10n_it_pec_email = pec_mail
|
891
|
+
WHERE pec_mail IS NOT NULL
|
892
|
+
"""
|
893
|
+
openupgrade.logged_query(env.cr, query)
|
894
|
+
|
895
|
+
|
896
|
+
def _l10n_it_rea_post_migration(env):
|
897
|
+
query = """
|
898
|
+
UPDATE
|
899
|
+
res_company
|
900
|
+
SET
|
901
|
+
l10n_it_eco_index_office = res_partner.rea_office,
|
902
|
+
l10n_it_eco_index_number = res_partner.rea_code,
|
903
|
+
l10n_it_eco_index_share_capital = res_partner.rea_capital,
|
904
|
+
l10n_it_eco_index_sole_shareholder = res_partner.rea_member_type,
|
905
|
+
l10n_it_eco_index_liquidation_state = res_partner.rea_liquidation_state
|
906
|
+
FROM
|
907
|
+
res_partner
|
908
|
+
WHERE
|
909
|
+
res_company.partner_id = res_partner.id
|
910
|
+
AND res_partner.rea_office IS NOT NULL
|
911
|
+
"""
|
912
|
+
openupgrade.logged_query(env.cr, query)
|
913
|
+
|
914
|
+
openupgrade.logged_query(
|
915
|
+
env.cr,
|
916
|
+
"""
|
917
|
+
UPDATE res_company
|
918
|
+
SET l10n_it_has_eco_index = 't'
|
919
|
+
WHERE l10n_it_eco_index_number IS NOT NULL
|
920
|
+
""",
|
921
|
+
)
|
922
|
+
|
923
|
+
|
924
|
+
def _l10n_it_vat_payability_pre_migration(env):
|
925
|
+
updates = {
|
926
|
+
"D": "on_payment",
|
927
|
+
"I": "on_invoice",
|
928
|
+
"S": "on_invoice",
|
929
|
+
}
|
930
|
+
|
931
|
+
for payability, tax_exigibility in updates.items():
|
932
|
+
query = f"""
|
933
|
+
UPDATE account_tax
|
934
|
+
SET tax_exigibility = '{tax_exigibility}'
|
935
|
+
WHERE payability = '{payability}'
|
936
|
+
"""
|
937
|
+
openupgrade.logged_query(env.cr, query)
|
938
|
+
|
939
|
+
|
940
|
+
def _l10n_it_edi_extension_pre_init_hook(env):
|
941
|
+
for module in OLD_MODULES:
|
942
|
+
migration_function = globals().get(f"_{module}_pre_migration")
|
943
|
+
if openupgrade.is_module_installed(env.cr, module) and migration_function:
|
944
|
+
migration_function(env)
|
945
|
+
|
946
|
+
|
947
|
+
def _l10n_it_edi_extension_post_init_hook(env):
|
948
|
+
for module in OLD_MODULES:
|
949
|
+
migration_function = globals().get(f"_{module}_post_migration")
|
950
|
+
if openupgrade.is_module_installed(env.cr, module) and migration_function:
|
951
|
+
migration_function(env)
|