From d2007b3c40fb7b2d80b5d8d91e8c796b02461e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 9 Dec 2021 18:13:37 +0100 Subject: [PATCH 1/4] [ADD] start adding edi_chunk_processing_oca --- edi_chunk_processing_oca/__init__.py | 2 ++ edi_chunk_processing_oca/__manifest__.py | 27 +++++++++++++++++ .../components/__init__.py | 1 + .../components/input_process_with_chunk.py | 29 +++++++++++++++++++ edi_chunk_processing_oca/models/__init__.py | 2 ++ .../models/chunk_group.py | 26 +++++++++++++++++ .../models/edi_exchange_record.py | 15 ++++++++++ .../views/edi_exchange_record_views.xml | 12 ++++++++ 8 files changed, 114 insertions(+) create mode 100644 edi_chunk_processing_oca/__init__.py create mode 100644 edi_chunk_processing_oca/__manifest__.py create mode 100644 edi_chunk_processing_oca/components/__init__.py create mode 100644 edi_chunk_processing_oca/components/input_process_with_chunk.py create mode 100644 edi_chunk_processing_oca/models/__init__.py create mode 100644 edi_chunk_processing_oca/models/chunk_group.py create mode 100644 edi_chunk_processing_oca/models/edi_exchange_record.py create mode 100644 edi_chunk_processing_oca/views/edi_exchange_record_views.xml diff --git a/edi_chunk_processing_oca/__init__.py b/edi_chunk_processing_oca/__init__.py new file mode 100644 index 0000000000..f24d3e2426 --- /dev/null +++ b/edi_chunk_processing_oca/__init__.py @@ -0,0 +1,2 @@ +from . import components +from . import models diff --git a/edi_chunk_processing_oca/__manifest__.py b/edi_chunk_processing_oca/__manifest__.py new file mode 100644 index 0000000000..cac693cca1 --- /dev/null +++ b/edi_chunk_processing_oca/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "EDI Chunk Processing OCA", + "summary": "Add a new component for spliting and processing file using chunk", + "version": "14.0.1.0.0", + "category": "Uncategorized", + "website": "https://github.com/OCA/edi", + "author": " Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "chunk_processing", + "edi_oca", + ], + "data": [ + "views/edi_exchange_record_views.xml", + ], + "demo": [], +} diff --git a/edi_chunk_processing_oca/components/__init__.py b/edi_chunk_processing_oca/components/__init__.py new file mode 100644 index 0000000000..d782f55222 --- /dev/null +++ b/edi_chunk_processing_oca/components/__init__.py @@ -0,0 +1 @@ +from . import input_process_with_chunk diff --git a/edi_chunk_processing_oca/components/input_process_with_chunk.py b/edi_chunk_processing_oca/components/input_process_with_chunk.py new file mode 100644 index 0000000000..221b38b36a --- /dev/null +++ b/edi_chunk_processing_oca/components/input_process_with_chunk.py @@ -0,0 +1,29 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.component.core import Component + +CHUNK_GROUP_FIELDS = [ + "job_priority", + "chunk_size", + "process_multi", + "data_format", + "apply_on_model", + "usage", + "xml_split_xpath", +] + + +class ProcessWithChunk(Component): + _name = "edi.input.process.with.chunk" + _inherit = "edi.component.input.mixin" + _usage = "process.with.chunk" + + def process(self): + vals = {} + for key in CHUNK_GROUP_FIELDS: + if hasattr(self.work, key): + vals[key] = getattr(self.work, key) + + self.exchange_record.chunk_group_id = self.env["chunk.group"].create(vals) diff --git a/edi_chunk_processing_oca/models/__init__.py b/edi_chunk_processing_oca/models/__init__.py new file mode 100644 index 0000000000..966fea5df1 --- /dev/null +++ b/edi_chunk_processing_oca/models/__init__.py @@ -0,0 +1,2 @@ +from . import edi_exchange_record +from . import chunk_group diff --git a/edi_chunk_processing_oca/models/chunk_group.py b/edi_chunk_processing_oca/models/chunk_group.py new file mode 100644 index 0000000000..034b0a732c --- /dev/null +++ b/edi_chunk_processing_oca/models/chunk_group.py @@ -0,0 +1,26 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 + +from odoo import fields, models + + +class ChunkGroup(models.Model): + _inherit = "chunk.group" + + # We use a O2M but as there is a sql constraint we can have only + # one pattern file, this is why the fieldname end with "id" + edi_exchange_record_id = fields.One2many( + "edi.exchange.record", "chunk_group_id", "Exchange Record" + ) + + def _get_data(self): + self.ensure_one() + if self.edi_exchange_record_id: + return base64.b64decode( + self.edi_exchange_record_id.exchange_file.decode("utf-8") + ) + else: + return super()._get_data() diff --git a/edi_chunk_processing_oca/models/edi_exchange_record.py b/edi_chunk_processing_oca/models/edi_exchange_record.py new file mode 100644 index 0000000000..ce6ffb57c1 --- /dev/null +++ b/edi_chunk_processing_oca/models/edi_exchange_record.py @@ -0,0 +1,15 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class EdiExchangeRecord(models.Model): + _inherit = "edi.exchange.record" + + chunk_group_id = fields.Many2one("chunk.group", string="Chunk Group") + + _sql_constraints = [ + ("uniq_chunk_group_id", "unique(chunk_group_id)", "The Group must be unique!") + ] diff --git a/edi_chunk_processing_oca/views/edi_exchange_record_views.xml b/edi_chunk_processing_oca/views/edi_exchange_record_views.xml new file mode 100644 index 0000000000..b959234ee7 --- /dev/null +++ b/edi_chunk_processing_oca/views/edi_exchange_record_views.xml @@ -0,0 +1,12 @@ + + + + edi.exchange.record + + + + + + + + From a89a1a9d0255d0e6d08335b5e9ca7a955d14b3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 23 Dec 2021 01:31:16 +0100 Subject: [PATCH 2/4] [REF] refactor code --- .../components/input_process_with_chunk.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/edi_chunk_processing_oca/components/input_process_with_chunk.py b/edi_chunk_processing_oca/components/input_process_with_chunk.py index 221b38b36a..6da88eb900 100644 --- a/edi_chunk_processing_oca/components/input_process_with_chunk.py +++ b/edi_chunk_processing_oca/components/input_process_with_chunk.py @@ -21,9 +21,8 @@ class ProcessWithChunk(Component): _usage = "process.with.chunk" def process(self): - vals = {} + vals = {"edi_exchange_record_id": [(4, self.exchange_record.id, 0)]} for key in CHUNK_GROUP_FIELDS: if hasattr(self.work, key): vals[key] = getattr(self.work, key) - - self.exchange_record.chunk_group_id = self.env["chunk.group"].create(vals) + self.env["chunk.group"].create(vals) From bfe835b661f09d9f0601e7d0552f6893f30e0c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 27 Jan 2022 10:45:23 +0100 Subject: [PATCH 3/4] [IMP] Add missing access rule --- edi_chunk_processing_oca/__manifest__.py | 1 + edi_chunk_processing_oca/security/ir.model.access.csv | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 edi_chunk_processing_oca/security/ir.model.access.csv diff --git a/edi_chunk_processing_oca/__manifest__.py b/edi_chunk_processing_oca/__manifest__.py index cac693cca1..9ac72f1102 100644 --- a/edi_chunk_processing_oca/__manifest__.py +++ b/edi_chunk_processing_oca/__manifest__.py @@ -22,6 +22,7 @@ ], "data": [ "views/edi_exchange_record_views.xml", + "security/ir.model.access.csv", ], "demo": [], } diff --git a/edi_chunk_processing_oca/security/ir.model.access.csv b/edi_chunk_processing_oca/security/ir.model.access.csv new file mode 100644 index 0000000000..44bfac7ee4 --- /dev/null +++ b/edi_chunk_processing_oca/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_chunk_group,Chunk group,chunk_processing.model_chunk_group,base_edi.group_edi_manager,1,1,1,1 +access_chunk_item,Chunk item,chunk_processing.model_chunk_item,base_edi.group_edi_manager,1,1,1,1 From bbd07d0de5b259f35e26be199ba640c0214892db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Mon, 7 Feb 2022 12:37:33 +0100 Subject: [PATCH 4/4] [IMP] add setup --- .../odoo/addons/edi_chunk_processing_oca | 1 + setup/edi_chunk_processing_oca/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/edi_chunk_processing_oca/odoo/addons/edi_chunk_processing_oca create mode 100644 setup/edi_chunk_processing_oca/setup.py diff --git a/setup/edi_chunk_processing_oca/odoo/addons/edi_chunk_processing_oca b/setup/edi_chunk_processing_oca/odoo/addons/edi_chunk_processing_oca new file mode 120000 index 0000000000..d6cad16b97 --- /dev/null +++ b/setup/edi_chunk_processing_oca/odoo/addons/edi_chunk_processing_oca @@ -0,0 +1 @@ +../../../../edi_chunk_processing_oca \ No newline at end of file diff --git a/setup/edi_chunk_processing_oca/setup.py b/setup/edi_chunk_processing_oca/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/edi_chunk_processing_oca/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)