Skip to content

Commit 791bfcb

Browse files
committed
[WIP] start adding xml support
1 parent f35935c commit 791bfcb

File tree

10 files changed

+131
-6
lines changed

10 files changed

+131
-6
lines changed

chunk_processing/__manifest__.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"data": [
2525
"views/chunk_item_view.xml",
26+
"views/chunk_group_view.xml",
2627
],
2728
"demo": [],
2829
}
+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from . import processor
2+
from . import processor_xml
23
from . import splitter
34
from . import splitter_json
5+
from . import splitter_xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
import base64
6+
7+
from lxml import objectify
8+
9+
from odoo.addons.component.core import AbstractComponent
10+
11+
12+
class ChunkProcessorXml(AbstractComponent):
13+
_name = "chunk.importer.xml"
14+
_collection = "chunk.item"
15+
16+
def _parse_data(self):
17+
return objectify.fromstring(
18+
base64.b64decode(self.collection.data)
19+
).iterchildren()
20+
21+
def _import_item(self):
22+
raise NotImplementedError
23+
24+
def run(self):
25+
for item in self._parse_data():
26+
self._import_item(item)

chunk_processing/components/splitter.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# @author Sébastien BEAU <[email protected]>
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

5+
import base64
6+
57
from odoo.addons.component.core import AbstractComponent
68

79

@@ -12,12 +14,15 @@ class ChunkSplitter(AbstractComponent):
1214
def _parse_data(self, data):
1315
raise NotImplementedError
1416

15-
def _prepare_chunk(self, start_idx, stop_idx, data):
17+
def _convert_items_to_data(self, items):
18+
raise NotImplementedError
19+
20+
def _prepare_chunk(self, start_idx, stop_idx, items):
1621
return {
1722
"start_idx": start_idx,
1823
"stop_idx": stop_idx,
19-
"data": data,
20-
"nbr_item": len(data),
24+
"data": base64.b64encode(self._convert_items_to_data(items)),
25+
"nbr_item": len(items),
2126
"state": "pending",
2227
"group_id": self.collection.id,
2328
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from lxml import etree
6+
7+
from odoo.addons.component.core import Component
8+
9+
10+
class ChunkSplitterXml(Component):
11+
_inherit = "chunk.splitter"
12+
_name = "chunk.splitter.xml"
13+
_usage = "xml"
14+
15+
def _parse_data(self, data):
16+
tree = etree.fromstring(data)
17+
items = tree.xpath(self.collection.xml_split_xpath)
18+
for idx, item in enumerate(items):
19+
yield idx + 1, item
20+
21+
def _convert_items_to_data(self, items):
22+
data = etree.Element("data")
23+
for item in items:
24+
data.append(item[1])
25+
return etree.tostring(data)

chunk_processing/models/chunk_group.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ChunkGroup(models.Model):
2222
("xml", "XML"),
2323
]
2424
)
25+
xml_split_xpath = fields.Char()
2526
state = fields.Selection(
2627
[("pending", "Pending"), ("failed", "Failed"), ("done", "Done")],
2728
default="pending",

chunk_processing/models/chunk_item.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ChunkItem(models.Model):
1717
)
1818
start_idx = fields.Integer()
1919
stop_idx = fields.Integer()
20-
data = fields.Serialized()
20+
data = fields.Binary()
2121
record_ids = fields.Serialized()
2222
messages = fields.Serialized()
2323
result_info = fields.Html()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="chunk_group_view_tree" model="ir.ui.view">
5+
<field name="model">chunk.group</field>
6+
<field name="arch" type="xml">
7+
<tree string="Chunk Group">
8+
<field name="data_format" />
9+
<field name="date_done" />
10+
</tree>
11+
</field>
12+
</record>
13+
14+
<record id="chunk_group_view_form" model="ir.ui.view">
15+
<field name="model">chunk.group</field>
16+
<field name="arch" type="xml">
17+
<form string="Chunk Group" create="false">
18+
<header>
19+
<button
20+
name="split_in_chunk"
21+
string="Re-launch Import"
22+
type="object"
23+
confirm="Are you sure to re-split the current file?"
24+
/>
25+
<field name="state" widget="statusbar" />
26+
</header>
27+
<sheet>
28+
<group>
29+
<group name="config" string="Config">
30+
<field name="process_multi" readonly="1" />
31+
<field name="chunk_size" readonly="1" />
32+
<field name="job_priority" readonly="1" />
33+
<field name="data_format" readonly="1" />
34+
<field name="apply_on_model" readonly="1" />
35+
<field name="usage" readonly="1" />
36+
</group>
37+
<group>
38+
<field name="create_date" readonly="1" />
39+
<field name="date_done" readonly="1" />
40+
</group>
41+
</group>
42+
<notebook>
43+
<page name="chunk" string="Chunk">
44+
<div>
45+
<label for="progress" />
46+
<field name="progress" readonly="1" widget="progressbar" />
47+
</div>
48+
<group>
49+
<field name="nbr_error" />
50+
<field name="nbr_success" />
51+
</group>
52+
<field
53+
name="info"
54+
readonly="1"
55+
attrs="{'invisible': [('info', '=', False)]}"
56+
/>
57+
<field name="item_ids" nolabel="1" />
58+
</page>
59+
</notebook>
60+
</sheet>
61+
</form>
62+
</field>
63+
</record>
64+
</odoo>

chunk_processing/views/chunk_item_view.xml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</header>
2424
<sheet>
2525
<group>
26+
<field name="data" />
2627
<field name="start_idx" />
2728
<field name="stop_idx" />
2829
<field name="nbr_error" />

pattern_import_export/models/pattern_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PatternFile(models.Model):
1616
pattern_config_id = fields.Many2one(
1717
"pattern.config", required=True, string="Export pattern"
1818
)
19-
chunk_group_id = fields.Many2one("chunk.group")
19+
chunk_group_id = fields.Many2one("chunk.group", string="Chunk Group")
2020
chunk_item_ids = fields.One2many("chunk.item", related="chunk_group_id.item_ids")
2121
state = fields.Selection(
2222
[("pending", "Pending"), ("failed", "Failed"), ("done", "Done")],
@@ -29,7 +29,7 @@ class PatternFile(models.Model):
2929
info = fields.Char(related="chunk_group_id.info")
3030

3131
_sql_constraints = [
32-
("uniq_group_id", "unique(group_id)", "The Group must be unique!")
32+
("uniq_chunk_group_id", "unique(chunk_group_id)", "The Group must be unique!")
3333
]
3434

3535
def _add_chunk_group(self):

0 commit comments

Comments
 (0)