Skip to content

Commit f03e5f6

Browse files
committed
Merge PR #4749 into 18.0
Signed-off-by tafaRU
2 parents 11197dc + 58529a4 commit f03e5f6

18 files changed

+1096
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
=========================
2+
Related Documents for EDI
3+
=========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:03af5c30726a2eeb63eafaf004b914ef4148d1bb103b8b7d5a32bfb7fe8e186f
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
20+
:target: https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_edi_related_document
21+
:alt: OCA/l10n-italy
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/l10n-italy-18-0/l10n-italy-18-0-l10n_it_edi_related_document
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
**English**
32+
33+
Module for managing the types of documents linked to invoices. The data
34+
related to the linked documents is then exported in the electronic
35+
invoice XML or imported during the creation of an invoice from an XML
36+
file. If a related document has 0 as the line reference, it means that
37+
it refers to the entire document and not to a specific invoice line.
38+
39+
**Italiano**
40+
41+
Modulo per la gestione dei tipi di documenti collegati alle fatture. I
42+
dati relativi ai documenti collegati vengono poi esportati nell'XML
43+
della fattura elettronica oppure importati durante la creazione di una
44+
fattura da XML. Nel caso in cui un documento collegato abbia 0 come
45+
riferimento linea, significa che è riferito all’intero documento e non
46+
ad una specifica linea della fattura.
47+
48+
**Table of contents**
49+
50+
.. contents::
51+
:local:
52+
53+
Bug Tracker
54+
===========
55+
56+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
57+
In case of trouble, please check there if your issue has already been reported.
58+
If you spotted it first, help us to smash it by providing a detailed and welcomed
59+
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_edi_related_document%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
60+
61+
Do not contact contributors directly about support or help with technical issues.
62+
63+
Credits
64+
=======
65+
66+
Authors
67+
-------
68+
69+
* Nextev Srl
70+
71+
Contributors
72+
------------
73+
74+
- Nextev Srl <odoo@nextev.it>
75+
76+
Maintainers
77+
-----------
78+
79+
This module is maintained by the OCA.
80+
81+
.. image:: https://odoo-community.org/logo.png
82+
:alt: Odoo Community Association
83+
:target: https://odoo-community.org
84+
85+
OCA, or the Odoo Community Association, is a nonprofit organization whose
86+
mission is to support the collaborative development of Odoo features and
87+
promote its widespread use.
88+
89+
This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_edi_related_document>`_ project on GitHub.
90+
91+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import models
4+
from openupgradelib import openupgrade
5+
6+
7+
def _insert_account_move_related_document(env):
8+
cr = env.cr
9+
cr.execute("SELECT * FROM fatturapa_related_document_type LIMIT 1")
10+
if cr.fetchone():
11+
cr.execute("""
12+
INSERT INTO account_move_related_document (
13+
type, name, "lineRef", invoice_id, invoice_line_id, date,
14+
numitem, code, cig, cup
15+
)
16+
SELECT
17+
type, name, "lineRef", invoice_id, invoice_line_id, date,
18+
numitem, code, cig, cup
19+
FROM fatturapa_related_document_type
20+
""")
21+
22+
23+
def _l10n_it_edi_related_document_post_init_hook(env):
24+
module = "l10n_it_fatturapa"
25+
if openupgrade.is_module_installed(env.cr, module):
26+
_insert_account_move_related_document(env)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2025 Nextev Srl
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Related Documents for EDI",
6+
"version": "18.0.1.0.0",
7+
"category": "Localization/Italy",
8+
"author": "Nextev Srl, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/l10n-italy",
10+
"license": "AGPL-3",
11+
"depends": ["l10n_it_edi"],
12+
"data": [
13+
"views/related_document_views.xml",
14+
"views/l10n_it_views.xml",
15+
"views/account_move_related_documents.xml",
16+
"data/invoice_it_template.xml",
17+
"security/ir.model.access.csv",
18+
],
19+
"installable": True,
20+
"post_init_hook": "_l10n_it_edi_related_document_post_init_hook",
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<template
4+
id="account_invoice_it_FatturaPA_export_inherit"
5+
inherit_id="l10n_it_edi.account_invoice_it_FatturaPA_export"
6+
>
7+
<xpath expr="//DatiGeneraliDocumento" position="after">
8+
<t
9+
t-call="l10n_it_edi_related_document.account_invoice_it_dati_documenti_correlati"
10+
/>
11+
</xpath>
12+
</template>
13+
</odoo>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import account_move
4+
from . import account_move_line
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from odoo import api, fields, models
2+
3+
from odoo.addons.l10n_it_edi.models.account_move import get_text
4+
5+
6+
class AccountMoveRelatedDocumentType(models.Model):
7+
_name = "account.move.related_document"
8+
_description = "E-invoice Related Documents"
9+
10+
type = fields.Selection(
11+
[
12+
("order", "Order"),
13+
("contract", "Contract"),
14+
("agreement", "Agreement"),
15+
("reception", "Reception"),
16+
("invoice", "Related Invoice"),
17+
],
18+
"Document",
19+
required=True,
20+
)
21+
name = fields.Char("Document ID", size=20, required=True)
22+
lineRef = fields.Integer("Line Ref.")
23+
invoice_id = fields.Many2one(
24+
"account.move",
25+
"Related Invoice",
26+
ondelete="cascade",
27+
index=True,
28+
readonly=True,
29+
)
30+
date = fields.Date()
31+
numitem = fields.Char("Item Num.", size=20)
32+
code = fields.Char("Order Agreement Code", size=100)
33+
cig = fields.Char("CIG Code", size=15)
34+
cup = fields.Char("CUP Code", size=15)
35+
invoice_line_id = fields.Many2one(
36+
"account.move.line",
37+
"Related Invoice Line",
38+
ondelete="cascade",
39+
index=True,
40+
readonly=True,
41+
)
42+
43+
@api.model_create_multi
44+
def create(self, vals_list):
45+
line_obj = self.env["account.move.line"]
46+
for vals in vals_list:
47+
if (
48+
vals.get("lineRef")
49+
and not vals.get("invoice_line_id")
50+
and vals.get("invoice_id")
51+
):
52+
line = line_obj.search(
53+
[
54+
("move_id", "=", vals["invoice_id"]),
55+
("sequence", "=", vals["lineRef"]),
56+
],
57+
limit=1,
58+
)
59+
if line:
60+
vals["invoice_line_id"] = line.id
61+
return super().create(vals_list)
62+
63+
64+
class AccountMove(models.Model):
65+
_inherit = "account.move"
66+
67+
related_document_ids = fields.One2many(
68+
"account.move.related_document", "invoice_id", copy=False
69+
)
70+
71+
def _l10n_it_edi_get_values(self, pdf_values=None):
72+
res = super()._l10n_it_edi_get_values(pdf_values=pdf_values)
73+
updated_values = self.remove_redundant_values(res)
74+
return updated_values
75+
76+
def remove_redundant_values(self, values):
77+
redundant_list = [
78+
"cig",
79+
"cup",
80+
"origin_document_type",
81+
"origin_document_name",
82+
"origin_document_date",
83+
]
84+
for key in redundant_list:
85+
values.pop(key, None)
86+
return values
87+
88+
def _l10n_it_edi_import_invoice(self, invoice, data, is_new):
89+
res = super()._l10n_it_edi_import_invoice(invoice, data, is_new)
90+
tree = data["xml_tree"]
91+
rel_docs_dict = {
92+
"order": tree.xpath(".//DatiOrdineAcquisto"),
93+
"contract": tree.xpath(".//DatiContratto"),
94+
"agreement": tree.xpath(".//DatiConvenzione"),
95+
"reception": tree.xpath(".//DatiRicezione"),
96+
"invoice": tree.xpath(".//DatiFattureCollegate"),
97+
}
98+
self.create_related_document(invoice, rel_docs_dict)
99+
return res
100+
101+
def create_related_document(self, invoice, rel_docs_dict):
102+
result = []
103+
invoice_line_model = self.env["account.move.line"]
104+
for key, rel_doc in rel_docs_dict.items():
105+
for element in rel_doc:
106+
invoice_lineid = False
107+
lineRef = get_text(element, "./RiferimentoNumeroLinea")
108+
if lineRef:
109+
invoice_line = invoice_line_model.search(
110+
[
111+
("move_id", "=", invoice.id),
112+
("sequence", "=", int(lineRef)),
113+
],
114+
limit=1,
115+
)
116+
if invoice_line:
117+
invoice_lineid = invoice_line.id
118+
entry = {
119+
"type": key,
120+
"lineRef": lineRef,
121+
"name": get_text(element, "./IdDocumento"),
122+
"date": get_text(element, "./Data"),
123+
"numitem": get_text(element, "./NumItem"),
124+
"code": get_text(element, "./CodiceCommessaConvenzione"),
125+
"cup": get_text(element, "./CodiceCUP"),
126+
"cig": get_text(element, "./CodiceCIG"),
127+
"invoice_id": invoice.id,
128+
"invoice_line_id": invoice_lineid,
129+
}
130+
entry = {k: v for k, v in entry.items() if v}
131+
result.append(entry)
132+
model = self.env["account.move.related_document"]
133+
model.create(result)
134+
return result
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from odoo import fields, models
2+
3+
4+
class AccountMoveLine(models.Model):
5+
_inherit = "account.move.line"
6+
7+
related_document_ids = fields.One2many(
8+
"account.move.related_document",
9+
"invoice_line_id",
10+
"Related Documents",
11+
copy=False,
12+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Nextev Srl \<<odoo@nextev.it>\>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
**English**
2+
3+
Module for managing the types of documents linked to invoices.
4+
The data related to the linked documents is then exported in
5+
the electronic invoice XML or imported during the creation of
6+
an invoice from an XML file.
7+
If a related document has 0 as the line reference, it means that
8+
it refers to the entire document and not to a specific
9+
invoice line.
10+
11+
**Italiano**
12+
13+
Modulo per la gestione dei tipi di documenti collegati alle fatture.
14+
I dati relativi ai documenti collegati vengono poi esportati nell'XML
15+
della fattura elettronica oppure importati durante la creazione di una
16+
fattura da XML.
17+
Nel caso in cui un documento collegato abbia 0 come riferimento linea,
18+
significa che è riferito all’intero documento e non ad una specifica
19+
linea della fattura.

0 commit comments

Comments
 (0)