Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions edi_storage_oca/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========================
EDI Storage backend support
===========================
Expand All @@ -17,7 +13,7 @@ EDI Storage backend support
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github
Expand Down
2 changes: 1 addition & 1 deletion edi_storage_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "LGPL-3",
"website": "https://github.com/OCA/edi-framework",
"author": "ACSONE,Odoo Community Association (OCA)",
"depends": ["edi_core_oca", "fs_storage"],
"depends": ["edi_core_oca", "fs_storage", "edi_component_oca"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etobella Could we ask for your opinion here? there was a regression, but to revert it we need a new dependency... not sure if you would prefer this in a glue module. Thoughts?

"data": [
"data/cron.xml",
"security/ir_model_access.xml",
Expand Down
1 change: 1 addition & 0 deletions edi_storage_oca/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import edi_exchange_type
from . import edi_exchange_record
from . import edi_oca_storage_handler
from . import edi_event_listener
79 changes: 79 additions & 0 deletions edi_storage_oca/models/edi_event_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import functools
import os
from pathlib import PurePath

from odoo.addons.component.core import Component

from .. import utils


class EdiStorageListener(Component):
_name = "edi.storage.component.listener"
_inherit = "base.event.listener"

def _move_file(self, storage, from_dir_str, to_dir_str, filename):
from_dir = PurePath(from_dir_str)
to_dir = PurePath(to_dir_str)
# - storage.list_files now includes path in fs_storage, breaking change
# - we remove path
files = utils.list_files(storage, from_dir.as_posix())
files = [os.path.basename(f) for f in files]
if filename not in files:
return False
self._add_post_commit_hook(
utils.move_files,
storage,
[(from_dir / filename).as_posix()],
to_dir.as_posix(),
)
return True

def _add_post_commit_hook(
self, move_func, storage, sftp_filepath, sftp_destination_path
):
"""Add hook after commit to move the file when transaction is over."""
self.env.cr.postcommit.add(
functools.partial(move_func, storage, sftp_filepath, sftp_destination_path)
)

def on_edi_exchange_done(self, record):
storage = record.storage_id
res = False
if record.direction == "input" and storage:
file = record.exchange_filename
pending_dir = record.type_id._storage_fullpath(
record.backend_id.input_dir_pending
).as_posix()
done_dir = record.type_id._storage_fullpath(
record.backend_id.input_dir_done
).as_posix()
error_dir = record.type_id._storage_fullpath(
record.backend_id.input_dir_error
).as_posix()
if not done_dir:
return res
res = self._move_file(storage, pending_dir, done_dir, file)
if not res:
# If a file previously failed it should have been previously
# moved to the error dir, therefore it is not present in the
# pending dir and we need to retry from error dir.
res = self._move_file(storage, error_dir, done_dir, file)
return res

def on_edi_exchange_error(self, record):
storage = record.storage_id
res = False
if record.direction == "input" and storage:
file = record.exchange_filename
pending_dir = record.type_id._storage_fullpath(
record.backend_id.input_dir_pending
).as_posix()
error_dir = record.type_id._storage_fullpath(
record.backend_id.input_dir_error
).as_posix()
if error_dir:
res = self._move_file(storage, pending_dir, error_dir, file)
return res
30 changes: 12 additions & 18 deletions edi_storage_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>EDI Storage backend support</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="edi-storage-backend-support">
<h1 class="title">EDI Storage backend support</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="edi-storage-backend-support">
<h1>EDI Storage backend support</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae52c0238c8bab278e4e2d6a48d86d4222672b893df1f171be046f3b7a3c58ae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi-framework/tree/18.0/edi_storage_oca"><img alt="OCA/edi-framework" src="https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-framework-18-0/edi-framework-18-0-edi_storage_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi-framework/tree/18.0/edi_storage_oca"><img alt="OCA/edi-framework" src="https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-framework-18-0/edi-framework-18-0-edi_storage_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Allow exchange files using storage backends from OCA/storage.</p>
<p>This module adds a storage backend relation on the EDI backend. There
you can configure the backend to be used (most often and SFTP) and the
Expand Down Expand Up @@ -411,34 +406,34 @@ <h1>EDI Storage backend support</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>Go to “EDI -&gt; EDI backend” then configure your backend to use a storage
backend.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>clean deprecated methods in the storage</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi-framework/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/edi-framework/issues/new?body=module:%20edi_storage_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>ACSONE</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simahawk&#64;gmail.com">simahawk&#64;gmail.com</a>&gt;</li>
<li>Foram Shah &lt;<a class="reference external" href="mailto:foram.shah&#64;initos.com">foram.shah&#64;initos.com</a>&gt;</li>
Expand All @@ -451,12 +446,12 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</div>
<div class="section" id="other-credits">
<h3><a class="toc-backref" href="#toc-entry-7">Other credits</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<p>The migration of this module from 15.0 to 16.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -469,6 +464,5 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions edi_storage_oca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_edi_backend_storage
from . import test_exchange_type
from . import test_edi_event_listenner
82 changes: 82 additions & 0 deletions edi_storage_oca/tests/test_edi_event_listenner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import base64
from unittest import mock

from odoo.addons.edi_component_oca.tests.common import (
EDIBackendCommonComponentRegistryTestCase,
)
from odoo.addons.edi_component_oca.tests.fake_components import FakeInputProcess

LISTENER_MOCK_PATH = (
"odoo.addons.edi_storage_oca.models.edi_event_listener.EdiStorageListener"
)


class EDIBackendTestCase(EDIBackendCommonComponentRegistryTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._load_module_components(cls, "edi_storage_oca")
cls._build_components(
cls,
FakeInputProcess,
)
vals = {
"model": cls.partner._name,
"res_id": cls.partner.id,
"exchange_file": base64.b64encode(b"1234"),
}
cls.record = cls.backend.create_record("test_csv_input", vals)
cls.fake_move_args = None

@classmethod
def _get_backend(cls):
return cls.env.ref("edi_storage_oca.demo_edi_backend_storage")

def setUp(self):
super().setUp()
FakeInputProcess.reset_faked()

def _move_file_mocked(self, *args):
self.fake_move_args = [*args]
if not all([*args]):
return False
return True

def _mock_listener_move_file(self):
return mock.patch(LISTENER_MOCK_PATH + "._move_file", self._move_file_mocked)

def test_01_process_record_success(self):
with self._mock_listener_move_file():
self.record.write(
{
"edi_exchange_state": "input_received",
"storage_id": self.backend.storage_id.id,
}
)
self.record.action_exchange_process()
storage, from_dir_str, to_dir_str, filename = self.fake_move_args
self.assertEqual(storage, self.backend.storage_id)
self.assertEqual(from_dir_str, self.backend.input_dir_pending)
self.assertEqual(to_dir_str, self.backend.input_dir_done)
self.assertEqual(filename, self.record.exchange_filename)

def test_02_process_record_with_error(self):
with self._mock_listener_move_file():
self.record.write(
{
"edi_exchange_state": "input_received",
"storage_id": self.backend.storage_id.id,
}
)
self.record._set_file_content("TEST %d" % self.record.id)
self.record.with_context(
test_break_process="OOPS! Something went wrong :("
).action_exchange_process()
storage, from_dir_str, to_dir_str, filename = self.fake_move_args
self.assertEqual(storage, self.backend.storage_id)
self.assertEqual(from_dir_str, self.backend.input_dir_pending)
self.assertEqual(to_dir_str, self.backend.input_dir_error)
self.assertEqual(filename, self.record.exchange_filename)