Skip to content

Commit 2dcd83b

Browse files
committed
Merge PR #3118 into 14.0
Signed-off-by eLBati
2 parents d8bdd7e + 504e1a2 commit 2dcd83b

37 files changed

Lines changed: 889 additions & 486 deletions

l10n_it_fatturapa/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"views/account_view.xml",
3333
"views/company_view.xml",
3434
"views/partner_view.xml",
35+
"views/fatturapa_attachment_views.xml",
3536
"views/related_document_type_views.xml",
3637
"security/ir.model.access.csv",
3738
],

l10n_it_fatturapa/controllers/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class FatturaElettronicaController(Controller):
1212
)
1313
def pdf_preview(self, attachment_id, **data):
1414
attach = request.env["ir.attachment"].browse(int(attachment_id))
15-
html = attach.get_fattura_elettronica_preview()
15+
fatturapa_attachment_model = request.env["fatturapa.attachment"]
16+
html = fatturapa_attachment_model.get_fattura_elettronica_preview(attach)
1617
pdf = request.env["ir.actions.report"]._run_wkhtmltopdf([html])
1718

1819
pdfhttpheaders = [

l10n_it_fatturapa/models/ir_attachment.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright 2022 Simone Rubino - TAKOBI
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
14
import base64
25
import binascii
36
import logging
@@ -6,9 +9,9 @@
69

710
import lxml.etree as ET
811

9-
from odoo import fields, models
12+
from odoo import api, fields, models
1013
from odoo.exceptions import UserError
11-
from odoo.modules import get_resource_path
14+
from odoo.modules import get_module_resource
1215
from odoo.tools.translate import _
1316

1417
_logger = logging.getLogger(__name__)
@@ -28,17 +31,36 @@ def is_base64(s):
2831
return re_base64.match(s)
2932

3033

31-
class Attachment(models.Model):
32-
_inherit = "ir.attachment"
33-
34+
class FatturaPAAttachment(models.AbstractModel):
35+
_name = "fatturapa.attachment"
36+
_description = "SdI file"
37+
_inherits = {
38+
"ir.attachment": "ir_attachment_id",
39+
}
40+
_inherit = [
41+
"mail.thread",
42+
]
43+
_order = "id desc"
44+
45+
ir_attachment_id = fields.Many2one(
46+
comodel_name="ir.attachment",
47+
string="Attachment",
48+
required=True,
49+
ondelete="cascade",
50+
)
51+
att_name = fields.Char(
52+
string="SdI file name",
53+
related="ir_attachment_id.name",
54+
store=True,
55+
)
3456
ftpa_preview_link = fields.Char(
3557
"Preview link", readonly=True, compute="_compute_ftpa_preview_link"
3658
)
3759

3860
def _compute_ftpa_preview_link(self):
3961
for att in self:
4062
att.ftpa_preview_link = (
41-
att.get_base_url() + "/fatturapa/preview/%s" % att.id
63+
att.get_base_url() + "/fatturapa/preview/%s" % att.ir_attachment_id.id
4264
)
4365

4466
@staticmethod
@@ -50,6 +72,7 @@ def ftpa_preview(self):
5072
"target": "new",
5173
}
5274

75+
@api.model
5376
def remove_xades_sign(self, xml):
5477
# Recovering parser is needed for files where strings like
5578
# xmlns:ds="http://www.w3.org/2000/09/xmldsig#""
@@ -65,6 +88,7 @@ def remove_xades_sign(self, xml):
6588
break
6689
return ET.tostring(root)
6790

91+
@api.model
6892
def strip_xml_content(self, xml):
6993
recovering_parser = ET.XMLParser(recover=True)
7094
root = ET.XML(xml, parser=recovering_parser)
@@ -75,14 +99,18 @@ def extract_cades(data):
7599
info = cms.ContentInfo.load(data)
76100
return info["content"]["encap_content_info"]["content"].native
77101

102+
@api.model
78103
def cleanup_xml(self, xml_string):
79104
xml_string = self.remove_xades_sign(xml_string)
80105
xml_string = self.strip_xml_content(xml_string)
81106
return xml_string
82107

83-
def get_xml_string(self):
108+
def get_xml_string(self, attachment=None):
109+
if not attachment:
110+
self.ensure_one()
111+
attachment = self.ir_attachment_id
84112
try:
85-
data = base64.b64decode(self.datas)
113+
data = base64.b64decode(attachment.datas)
86114
except binascii.Error as e:
87115
raise UserError(_("Corrupted attachment %s.") % e.args)
88116

@@ -112,14 +140,14 @@ def get_xml_string(self):
112140
except AttributeError as e:
113141
raise UserError(_("Invalid xml %s.") % e.args)
114142

115-
def get_fattura_elettronica_preview(self):
116-
xsl_path = get_resource_path(
117-
"l10n_it_fatturapa",
118-
"data",
119-
self.env.company.fatturapa_preview_style,
143+
@api.model
144+
def get_fattura_elettronica_preview(self, attachment):
145+
company = self.env.user.company_id
146+
xsl_path = get_module_resource(
147+
"l10n_it_fatturapa", "data", company.fatturapa_preview_style
120148
)
121149
xslt = ET.parse(xsl_path)
122-
xml_string = self.get_xml_string()
150+
xml_string = self.get_xml_string(attachment)
123151
xml_file = BytesIO(xml_string)
124152
recovering_parser = ET.XMLParser(recover=True)
125153
dom = ET.parse(xml_file, parser=recovering_parser)

l10n_it_fatturapa/security/ir.model.access.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ access_fatturapa_summary_data_manager,access_fatturapa_summary_data_manager,mode
2222
access_fatturapa_summary_data,access_fatturapa_summary_data,model_fatturapa_summary_data,account.group_account_invoice,1,0,0,0
2323
access_withholding_data_line_manager,access_withholding_data_line_manager,model_withholding_data_line,account.group_account_manager,1,1,1,1
2424
access_withholding_data_line,access_withholding_data_line,model_withholding_data_line,account.group_account_invoice,1,0,0,0
25+
access_fatturapa_attachment,access_fatturapa_attachment,model_fatturapa_attachment,account.group_account_invoice,1,1,1,1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
~ Copyright 2022 Simone Rubino - TAKOBI
4+
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
-->
6+
<odoo>
7+
<record id="fatturapa_attachment_view_form" model="ir.ui.view">
8+
<field name="name">Form view for SdI file</field>
9+
<field name="model">fatturapa.attachment</field>
10+
<field name="arch" type="xml">
11+
<form string="SdI file">
12+
<sheet>
13+
<group>
14+
<group name="preview">
15+
<field name='id' invisible="1" />
16+
<label for="datas" />
17+
<div>
18+
<div>
19+
<field name="datas" filename="name" />
20+
</div>
21+
<div>
22+
<button
23+
type="object"
24+
name="ftpa_preview"
25+
string="Show preview"
26+
style="margin-bottom:10px;"
27+
attrs="{'invisible': [('id', '=', False)]}"
28+
/>
29+
</div>
30+
</div>
31+
<field name="name" invisible="True" />
32+
</group>
33+
</group>
34+
<notebook>
35+
<page name="history" string="History">
36+
<label for="create_uid" string="Created by" />
37+
<div name="creation_div">
38+
<field
39+
name="create_uid"
40+
readonly="1"
41+
class="oe_inline"
42+
/> on
43+
<field
44+
name="create_date"
45+
readonly="1"
46+
class="oe_inline"
47+
/>
48+
</div>
49+
</page>
50+
</notebook>
51+
</sheet>
52+
<div class="oe_chatter">
53+
<field name="message_follower_ids" widget="mail_followers" />
54+
<field name="message_ids" widget="mail_thread" />
55+
</div>
56+
</form>
57+
</field>
58+
</record>
59+
</odoo>

l10n_it_fatturapa_in/models/attachment.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@
55

66

77
class FatturaPAAttachmentIn(models.Model):
8+
_inherit = "fatturapa.attachment"
89
_name = "fatturapa.attachment.in"
9-
_description = "E-bill import file"
10-
_inherits = {"ir.attachment": "ir_attachment_id"}
11-
_inherit = ["mail.thread"]
12-
_order = "id desc"
10+
_description = "Electronic Invoice"
1311

14-
ir_attachment_id = fields.Many2one(
15-
"ir.attachment", "Attachment", required=True, ondelete="cascade"
16-
)
17-
att_name = fields.Char(
18-
string="E-bill file name", related="ir_attachment_id.name", store=True
19-
)
2012
in_invoice_ids = fields.One2many(
2113
"account.move",
2214
"fatturapa_attachment_in_id",
@@ -91,9 +83,6 @@ def _compute_e_invoice_validation_error(self):
9183
)
9284
att.e_invoice_validation_message = "\n\n".join(error_messages)
9385

94-
def get_xml_string(self):
95-
return self.ir_attachment_id.get_xml_string()
96-
9786
def recompute_xml_fields(self):
9887
self._compute_xml_data()
9988
self._compute_registered()
@@ -179,6 +168,3 @@ def _compute_linked_invoice_id_xml(self):
179168
0
180169
].IdDocumento
181170
)
182-
183-
def ftpa_preview(self):
184-
return self.env["ir.attachment"].ftpa_preview(self)

0 commit comments

Comments
 (0)