-
-
Notifications
You must be signed in to change notification settings - Fork 480
/
Copy pathmodels.py
44 lines (32 loc) · 1.34 KB
/
models.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
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
# Exemple of pure python processor (inherit is not possible)
class TestPythonPartnerProcessor:
def __init__(self, chunk):
super().__init__()
self.env = chunk.env
self.chunk = chunk
def run(self):
return self.env["res.partner"].create(self.chunk._get_data())
# Exemple of odoo processor (inherit is possible)
class TestOdooStateProcessor(models.TransientModel):
_name = "test.odoo.state.processor"
_description = "Chunk Processor State Create"
chunk_id = fields.Many2one("queue.job.chunk", "Chunk")
def run(self):
return self.env["res.country.state"].create(self.chunk_id._get_data())
class QueueJobChunk(models.Model):
_inherit = "queue.job.chunk"
processor = fields.Selection(
selection_add=[
("test_partner", "Test create Partner"),
("test_state", "Test create Country State"),
],
)
def _get_processor(self):
if self.processor == "test_partner":
return TestPythonPartnerProcessor(self)
elif self.processor == "test_state":
return self.env["test.odoo.state.processor"].new({"chunk_id": self.id})