Skip to content

Commit 8c2fda2

Browse files
[ADD] edi_storage_component_oca
1 parent 26aeaf0 commit 8c2fda2

File tree

11 files changed

+694
-0
lines changed

11 files changed

+694
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=========================
2+
EDI Storage Component OCA
3+
=========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:929f63d432944d358bc315e8419381157ce9ed930aa5c68995ae6f66c85feea6
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github
20+
:target: https://github.com/OCA/edi-framework/tree/18.0/edi_storage_component_oca
21+
:alt: OCA/edi-framework
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/edi-framework-18-0/edi-framework-18-0-edi_storage_component_oca
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Glue module between edi_storage_oca and edi_component_oca.
32+
33+
It implements the EDI processing listener using the OCA component
34+
framework, allowing custom behaviors to be executed when EDI records are
35+
processed.
36+
37+
**Table of contents**
38+
39+
.. contents::
40+
:local:
41+
42+
Bug Tracker
43+
===========
44+
45+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi-framework/issues>`_.
46+
In case of trouble, please check there if your issue has already been reported.
47+
If you spotted it first, help us to smash it by providing a detailed and welcomed
48+
`feedback <https://github.com/OCA/edi-framework/issues/new?body=module:%20edi_storage_component_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
49+
50+
Do not contact contributors directly about support or help with technical issues.
51+
52+
Credits
53+
=======
54+
55+
Authors
56+
-------
57+
58+
* ForgeFlow
59+
60+
Contributors
61+
------------
62+
63+
- Arnau Cruz <arnau.cruz@forgeflow.com>
64+
65+
Maintainers
66+
-----------
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
This module is part of the `OCA/edi-framework <https://github.com/OCA/edi-framework/tree/18.0/edi_storage_component_oca>`_ project on GitHub.
79+
80+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
{
5+
"name": "EDI Storage Component OCA",
6+
"summary": """
7+
Glue module between edi_storage_oca and edi_component_oca.
8+
""",
9+
"version": "18.0.1.0.0",
10+
"development_status": "Beta",
11+
"license": "LGPL-3",
12+
"website": "https://github.com/OCA/edi-framework",
13+
"author": "ForgeFlow, Odoo Community Association (OCA)",
14+
"depends": ["edi_storage_oca", "edi_component_oca"],
15+
"data": [],
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import edi_event_listener
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
import functools
5+
import os
6+
from pathlib import PurePath
7+
8+
from odoo.addons.component.core import Component
9+
from odoo.addons.edi_storage_oca import utils
10+
11+
12+
class EdiStorageListener(Component):
13+
_name = "edi.storage.component.listener"
14+
_inherit = "base.event.listener"
15+
16+
def _move_file(self, storage, from_dir_str, to_dir_str, filename):
17+
from_dir = PurePath(from_dir_str)
18+
to_dir = PurePath(to_dir_str)
19+
# - storage.list_files now includes path in fs_storage, breaking change
20+
# - we remove path
21+
files = utils.list_files(storage, from_dir.as_posix())
22+
files = [os.path.basename(f) for f in files]
23+
if filename not in files:
24+
return False
25+
self._add_post_commit_hook(
26+
utils.move_files,
27+
storage,
28+
[(from_dir / filename).as_posix()],
29+
to_dir.as_posix(),
30+
)
31+
return True
32+
33+
def _add_post_commit_hook(
34+
self, move_func, storage, sftp_filepath, sftp_destination_path
35+
):
36+
"""Add hook after commit to move the file when transaction is over."""
37+
self.env.cr.postcommit.add(
38+
functools.partial(move_func, storage, sftp_filepath, sftp_destination_path)
39+
)
40+
41+
def on_edi_exchange_done(self, record):
42+
storage = record.storage_id
43+
res = False
44+
if record.direction == "input" and storage:
45+
file = record.exchange_filename
46+
pending_dir = record.type_id._storage_fullpath(
47+
record.backend_id.input_dir_pending
48+
).as_posix()
49+
done_dir = record.type_id._storage_fullpath(
50+
record.backend_id.input_dir_done
51+
).as_posix()
52+
error_dir = record.type_id._storage_fullpath(
53+
record.backend_id.input_dir_error
54+
).as_posix()
55+
if not done_dir:
56+
return res
57+
res = self._move_file(storage, pending_dir, done_dir, file)
58+
if not res:
59+
# If a file previously failed it should have been previously
60+
# moved to the error dir, therefore it is not present in the
61+
# pending dir and we need to retry from error dir.
62+
res = self._move_file(storage, error_dir, done_dir, file)
63+
return res
64+
65+
def on_edi_exchange_error(self, record):
66+
storage = record.storage_id
67+
res = False
68+
if record.direction == "input" and storage:
69+
file = record.exchange_filename
70+
pending_dir = record.type_id._storage_fullpath(
71+
record.backend_id.input_dir_pending
72+
).as_posix()
73+
error_dir = record.type_id._storage_fullpath(
74+
record.backend_id.input_dir_error
75+
).as_posix()
76+
if error_dir:
77+
res = self._move_file(storage, pending_dir, error_dir, file)
78+
return res
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Arnau Cruz \<arnau.cruz@forgeflow.com\>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Glue module between edi_storage_oca and edi_component_oca.
2+
3+
- It implements the EDI processing listener using the OCA component framework,
4+
allowing custom behaviors to be executed when EDI records are processed.

0 commit comments

Comments
 (0)