-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathscript_file_import.py
43 lines (32 loc) · 1.19 KB
/
script_file_import.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
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ScriptFileImport(models.Model):
_name = "script.file.import"
_description = "Script File Import"
in_filename = fields.Char()
out_filename = fields.Char(compute="_compute_out_filename")
in_data = fields.Binary(string="Input CSV file", required=True)
out_data = fields.Binary(string="Output CSV file", readonly=True)
processor = fields.Selection(
string="Processor", selection="_get_processor", required=True
)
state = fields.Selection(
[
("draft", "Draft"),
("processing", "Processing"),
("done", "Done"),
],
)
def _get_processor(self):
return []
def run_in_background(self):
self.state = "processing"
self.with_delay().run()
def run(self):
self.out_data = self.env[self.processor].run(self.in_data)
self.state = "done"
def _compute_out_filename(self):
for record in self:
record.out_filename = "Result-" + record.in_filename