-
-
Notifications
You must be signed in to change notification settings - Fork 53
[18.0][IMP] edi_storage_oca: post-process input file via conf #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ArnauCForgeFlow
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
ForgeFlow:18.0-imp-edi_storage_oca-edi_configuration_move
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,29 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <odoo noupdate="1"> | ||
| <!-- | ||
| IMPORTANT: these configurations are *inactive* by default. Before | ||
| activating them, set 'backend_id' to the specific storage backend | ||
| whose directories should be used, otherwise the snippet will not | ||
| know which input_dir_pending / input_dir_done / input_dir_error to | ||
| operate on. | ||
| --> | ||
| <record id="edi_conf_storage_move_on_done" model="edi.configuration"> | ||
| <field name="name">Storage: move input file to done</field> | ||
| <field name="active" eval="False" /> | ||
| <field name="is_global" eval="True" /> | ||
| <field name="trigger_id" ref="edi_core_oca.edi_config_trigger_record_done" /> | ||
| <field | ||
| name="snippet_do" | ||
| >record.backend_id._storage_on_edi_exchange_done(record)</field> | ||
| </record> | ||
|
|
||
| <record id="edi_conf_storage_move_on_error" model="edi.configuration"> | ||
| <field name="name">Storage: move input file to error</field> | ||
| <field name="active" eval="False" /> | ||
| <field name="is_global" eval="True" /> | ||
| <field name="trigger_id" ref="edi_core_oca.edi_config_trigger_record_error" /> | ||
| <field | ||
| name="snippet_do" | ||
| >record.backend_id._storage_on_edi_exchange_error(record)</field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or 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 hidden or 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,10 @@ | ||
| This module has two **inactive** global `edi.configuration` records | ||
| that move the input file across the storage directories on | ||
| `on_edi_exchange_done` / `on_edi_exchange_error`: | ||
|
|
||
| - *Storage: move input file, pending → done (fallback error → done) | ||
| - *Storage: move input file, pending → error | ||
|
|
||
| Before enabling them you **must** set `backend_id` on the record: | ||
| otherwise the global match runs against every backend in the database, | ||
| including non-storage ones. |
This file contains hidden or 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,2 +1,3 @@ | ||
| from . import test_edi_backend_storage | ||
| from . import test_event_listener | ||
| from . import test_exchange_type |
This file contains hidden or 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,88 @@ | ||
| # Copyright 2020 ACSONE | ||
| # @author: Simone Orsi <simahawk@gmail.com> | ||
| # 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_test_helper import FakeModelLoader | ||
|
|
||
| from odoo.addons.edi_core_oca.tests.common import EDIBackendCommonTestCase | ||
| from odoo.addons.edi_core_oca.tests.fake_models import EdiTestExecution | ||
|
|
||
| STORAGE_MOVE_FILE_PATH = "odoo.addons.fs_storage.models.fs_storage.FSStorage._move_file" | ||
|
|
||
|
|
||
| class TestStorageEventListener(EDIBackendCommonTestCase): | ||
| @classmethod | ||
| def _get_backend(cls): | ||
| return cls.env.ref("edi_storage_oca.demo_edi_backend_storage") | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.conf_done = cls.env.ref("edi_storage_oca.edi_conf_storage_move_on_done") | ||
| cls.conf_error = cls.env.ref("edi_storage_oca.edi_conf_storage_move_on_error") | ||
| (cls.conf_done | cls.conf_error).write( | ||
| {"active": True, "backend_id": cls.backend.id} | ||
| ) | ||
|
|
||
| vals = { | ||
| "model": cls.partner._name, | ||
| "res_id": cls.partner.id, | ||
| "exchange_file": base64.b64encode(b"1234"), | ||
| "storage_id": cls.backend.storage_id.id, | ||
| } | ||
| cls.record = cls.backend.create_record("test_csv_input", vals) | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.loader = FakeModelLoader(self.env, self.__module__) | ||
| self.loader.backup_registry() | ||
|
|
||
| self.loader.update_registry((EdiTestExecution,)) | ||
| fake_model = self.env["ir.model"].search( | ||
| [("model", "=", "edi.framework.test.execution")] | ||
| ) | ||
| self.exchange_type_in.process_model_id = fake_model | ||
| self.exchange_type_in.input_validate_model_id = fake_model | ||
|
|
||
| def tearDown(self): | ||
| self.loader.restore_registry() | ||
| super().tearDown() | ||
|
|
||
| def _patch_move_file(self): | ||
| return mock.patch(STORAGE_MOVE_FILE_PATH, autospec=True, return_value=True) | ||
|
|
||
| def _expected_dir(self, raw_dir): | ||
| return self.exchange_type_in._storage_fullpath(raw_dir).as_posix() | ||
|
|
||
| def test_01_process_record_success(self): | ||
| self.record.write({"edi_exchange_state": "input_received"}) | ||
| with self._patch_move_file() as mocked: | ||
| self.record.action_exchange_process() | ||
| mocked.assert_called_once() | ||
| storage, from_dir_str, to_dir_str, filename = mocked.call_args[0] | ||
| self.assertEqual(storage, self.backend.storage_id) | ||
| self.assertEqual( | ||
| from_dir_str, self._expected_dir(self.backend.input_dir_pending) | ||
| ) | ||
| self.assertEqual(to_dir_str, self._expected_dir(self.backend.input_dir_done)) | ||
| self.assertEqual(filename, self.record.exchange_filename) | ||
|
|
||
| def test_02_process_record_with_error(self): | ||
| self.record.write({"edi_exchange_state": "input_received"}) | ||
| self.record._set_file_content("TEST %d" % self.record.id) | ||
| with self._patch_move_file() as mocked: | ||
| self.record.with_context( | ||
| test_break_process="OOPS! Something went wrong :(" | ||
| ).action_exchange_process() | ||
| mocked.assert_called_once() | ||
| storage, from_dir_str, to_dir_str, filename = mocked.call_args[0] | ||
| self.assertEqual(storage, self.backend.storage_id) | ||
| self.assertEqual( | ||
| from_dir_str, self._expected_dir(self.backend.input_dir_pending) | ||
| ) | ||
| self.assertEqual(to_dir_str, self._expected_dir(self.backend.input_dir_error)) | ||
| self.assertEqual(filename, self.record.exchange_filename) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.