forked from OCA/l10n-italy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_file.py
46 lines (35 loc) · 1.41 KB
/
export_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2019 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import base64
from odoo import _, fields, models
class AccountIntrastatExportFile(models.TransientModel):
_name = "account.intrastat.export.file"
_description = "Intrastat export file"
name = fields.Char(string="File Name", readonly=True)
data = fields.Binary(string="File", readonly=True)
state = fields.Selection(
selection=[("choose", "Choose"), ("get", "Get")],
default="choose",
)
def act_getfile(self):
self.ensure_one()
statement_id = self.env.context.get("active_id")
statement = self.env["account.intrastat.statement"].browse(statement_id)
file = statement.generate_file_export()
filename = statement._get_file_name()
out = base64.encodebytes(file.encode())
view = self.env.ref(
"l10n_it_intrastat_statement.wizard_account_intrastat_export_file"
)
view_id = view.id
self.write({"state": "get", "data": out, "name": filename})
return {
"type": "ir.actions.act_window",
"res_model": "account.intrastat.export.file",
"view_mode": "form",
"name": _("Export Intrastat File"),
"res_id": self.id,
"nodestroy": True,
"view_id": [view_id],
"target": "new",
}