-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f35935c
commit 791bfcb
Showing
10 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
], | ||
"data": [ | ||
"views/chunk_item_view.xml", | ||
"views/chunk_group_view.xml", | ||
], | ||
"demo": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from . import processor | ||
from . import processor_xml | ||
from . import splitter | ||
from . import splitter_json | ||
from . import splitter_xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2021 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import base64 | ||
|
||
from lxml import objectify | ||
|
||
from odoo.addons.component.core import AbstractComponent | ||
|
||
|
||
class ChunkProcessorXml(AbstractComponent): | ||
_name = "chunk.importer.xml" | ||
_collection = "chunk.item" | ||
|
||
def _parse_data(self): | ||
return objectify.fromstring( | ||
base64.b64decode(self.collection.data) | ||
).iterchildren() | ||
|
||
def _import_item(self): | ||
raise NotImplementedError | ||
|
||
def run(self): | ||
for item in self._parse_data(): | ||
self._import_item(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import base64 | ||
|
||
from odoo.addons.component.core import AbstractComponent | ||
|
||
|
||
|
@@ -12,12 +14,15 @@ class ChunkSplitter(AbstractComponent): | |
def _parse_data(self, data): | ||
raise NotImplementedError | ||
|
||
def _prepare_chunk(self, start_idx, stop_idx, data): | ||
def _convert_items_to_data(self, items): | ||
raise NotImplementedError | ||
|
||
def _prepare_chunk(self, start_idx, stop_idx, items): | ||
return { | ||
"start_idx": start_idx, | ||
"stop_idx": stop_idx, | ||
"data": data, | ||
"nbr_item": len(data), | ||
"data": base64.b64encode(self._convert_items_to_data(items)), | ||
"nbr_item": len(items), | ||
"state": "pending", | ||
"group_id": self.collection.id, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2021 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from lxml import etree | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class ChunkSplitterXml(Component): | ||
_inherit = "chunk.splitter" | ||
_name = "chunk.splitter.xml" | ||
_usage = "xml" | ||
|
||
def _parse_data(self, data): | ||
tree = etree.fromstring(data) | ||
items = tree.xpath(self.collection.xml_split_xpath) | ||
for idx, item in enumerate(items): | ||
yield idx + 1, item | ||
|
||
def _convert_items_to_data(self, items): | ||
data = etree.Element("data") | ||
for item in items: | ||
data.append(item[1]) | ||
return etree.tostring(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="chunk_group_view_tree" model="ir.ui.view"> | ||
<field name="model">chunk.group</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Chunk Group"> | ||
<field name="data_format" /> | ||
<field name="date_done" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="chunk_group_view_form" model="ir.ui.view"> | ||
<field name="model">chunk.group</field> | ||
<field name="arch" type="xml"> | ||
<form string="Chunk Group" create="false"> | ||
<header> | ||
<button | ||
name="split_in_chunk" | ||
string="Re-launch Import" | ||
type="object" | ||
confirm="Are you sure to re-split the current file?" | ||
/> | ||
<field name="state" widget="statusbar" /> | ||
</header> | ||
<sheet> | ||
<group> | ||
<group name="config" string="Config"> | ||
<field name="process_multi" readonly="1" /> | ||
<field name="chunk_size" readonly="1" /> | ||
<field name="job_priority" readonly="1" /> | ||
<field name="data_format" readonly="1" /> | ||
<field name="apply_on_model" readonly="1" /> | ||
<field name="usage" readonly="1" /> | ||
</group> | ||
<group> | ||
<field name="create_date" readonly="1" /> | ||
<field name="date_done" readonly="1" /> | ||
</group> | ||
</group> | ||
<notebook> | ||
<page name="chunk" string="Chunk"> | ||
<div> | ||
<label for="progress" /> | ||
<field name="progress" readonly="1" widget="progressbar" /> | ||
</div> | ||
<group> | ||
<field name="nbr_error" /> | ||
<field name="nbr_success" /> | ||
</group> | ||
<field | ||
name="info" | ||
readonly="1" | ||
attrs="{'invisible': [('info', '=', False)]}" | ||
/> | ||
<field name="item_ids" nolabel="1" /> | ||
</page> | ||
</notebook> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters