Skip to content

Commit

Permalink
[MIG] edi_storage_oca: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
duongtq committed Nov 20, 2023
1 parent 9d52254 commit d2168b0
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 235 deletions.
24 changes: 15 additions & 9 deletions edi_storage_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EDI Storage backend support
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f2718fe12ff53362a2da3e253d22e0641ebcd6a01195db14f8d9c8c71878080d
!! source digest: sha256:318f3c9a59e743846c522a71e16271af79789793456af1694eb8c2c58b0d949a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -16,14 +16,14 @@ EDI Storage backend support
.. |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-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/15.0/edi_storage_oca
:alt: OCA/edi
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framwork-lightgray.png?logo=github
:target: https://github.com/OCA/edi-framwork/tree/16.0/edi_storage_oca
:alt: OCA/edi-framwork
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-15-0/edi-15-0-edi_storage_oca
:target: https://translation.odoo-community.org/projects/edi-framwork-16-0/edi-framwork-16-0-edi_storage_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi-framwork&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -65,10 +65,10 @@ Go to "EDI -> EDI backend" then configure your backend to use a storage backend.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi-framwork/issues>`_.
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
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20edi_storage_oca%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/edi-framwork/issues/new?body=module:%20edi_storage_oca%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -86,6 +86,12 @@ Contributors
* Simone Orsi <simahawk@gmail.com>
* Foram Shah <foram.shah@initos.com>
* Lois Rilo <lois.rilo@forgeflow.com>
* Duong (Tran Quoc) <duongtq@trobz.com>

Other credits
~~~~~~~~~~~~~

The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp.

Maintainers
~~~~~~~~~~~
Expand All @@ -100,6 +106,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/15.0/edi_storage_oca>`_ project on GitHub.
This module is part of the `OCA/edi-framwork <https://github.com/OCA/edi-framwork/tree/16.0/edi_storage_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 3 additions & 3 deletions edi_storage_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"summary": """
Base module to allow exchanging files via storage backend (eg: SFTP).
""",
"version": "15.0.1.2.0",
"version": "16.0.1.0.0",
"development_status": "Beta",
"license": "LGPL-3",
"website": "https://github.com/OCA/edi",
"website": "https://github.com/OCA/edi-framework",
"author": "ACSONE,Odoo Community Association (OCA)",
"depends": ["edi_oca", "storage_backend", "component"],
"depends": ["edi_oca", "fs_storage", "component"],
"data": [
"data/cron.xml",
"data/job_channel_data.xml",
Expand Down
24 changes: 5 additions & 19 deletions edi_storage_oca/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class EDIStorageComponentMixin(AbstractComponent):

_name = "edi.storage.component.mixin"
_inherit = "edi.component.mixin"
# Components having `_storage_backend_type` will have precedence.
# Components having `_storage_type` will have precedence.
# If the value is not set, generic components will be used.
_storage_backend_type = None
_storage_type = None

@classmethod
def _component_match(cls, work, usage=None, model_name=None, **kw):
res = super()._component_match(work, usage=usage, model_name=model_name, **kw)
storage_type = kw.get("storage_backend_type")
if storage_type and cls._storage_backend_type:
return cls._storage_backend_type == storage_type
storage_type = kw.get("storage_type")
if storage_type and cls._storage_type:
return cls._storage_type == storage_type
return res

@property
Expand All @@ -43,20 +43,6 @@ def _dir_by_state(self, direction, state):
(self.backend[direction + "_dir_" + state] or "").strip().rstrip("/")
)

def _remote_file_path(self, direction, state, filename):
"""Return remote file path by direction and state for give filename.
:param direction: string stating direction of the exchange
:param state: string stating state of the exchange
:param filename: string for file name
:return: PurePath object
"""
_logger.warning(
"Call of deprecated function `_remote_file_path`. "
"Please use `_get_remote_file_path` instead.",
)
return self._dir_by_state(direction, state) / filename.strip("/ ")

def _get_remote_file_path(self, state, filename=None):
"""Retrieve remote path for current exchange record."""
filename = filename or self.exchange_record.exchange_filename
Expand Down
21 changes: 0 additions & 21 deletions edi_storage_oca/components/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,3 @@ def _exchange_output_check(self):
self.exchange_record._notify_error("process_ko")
return False
return True

# FIXME: this is not used ATM -> should be refactored
# into an incoming exchange.
# The backend will look for records needing an ack
# and generate and ack record.
def _exchange_output_handle_ack(self):
ack_type = self.exchange_record.type_id.ack_type_id
filename = ack_type._make_exchange_filename(self.exchange_record)
ack_file = self._get_remote_file("done", filename=filename)
if ack_file:
self.backend.create_record(
ack_type.code,
{
"parent_id": self.exchange_record.id,
"exchange_file": ack_file,
"edi_exchange_state": "input_received",
},
)
self.exchange_record._notify_ack_received()
else:
self.exchange_record._notify_ack_missing()
10 changes: 8 additions & 2 deletions edi_storage_oca/components/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 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
Expand All @@ -14,12 +15,17 @@ class EdiStorageListener(Component):
def _move_file(self, storage, from_dir_str, to_dir_str, filename):
from_dir = PurePath(from_dir_str)
to_dir = PurePath(to_dir_str)

Check warning on line 17 in edi_storage_oca/components/listener.py

View check run for this annotation

Codecov / codecov/patch

edi_storage_oca/components/listener.py#L16-L17

Added lines #L16 - L17 were not covered by tests
if filename not in storage.list_files(from_dir.as_posix()):
# The file might have been moved after a previous error.
# TODO:
# - storage.list_files now includes path in fs_storage, breaking change
# - we remove path
files = storage.list_files(from_dir.as_posix())

Check warning on line 21 in edi_storage_oca/components/listener.py

View check run for this annotation

Codecov / codecov/patch

edi_storage_oca/components/listener.py#L21

Added line #L21 was not covered by tests
files = [os.path.basename(f) for f in files]
if filename not in files:
return False
self._add_after_commit_hook(

Check warning on line 25 in edi_storage_oca/components/listener.py

View check run for this annotation

Codecov / codecov/patch

edi_storage_oca/components/listener.py#L24-L25

Added lines #L24 - L25 were not covered by tests
storage._move_files, [(from_dir / filename).as_posix()], to_dir.as_posix()
)
storage.move_files([(from_dir / filename).as_posix()], to_dir.as_posix())
return True

Check warning on line 29 in edi_storage_oca/components/listener.py

View check run for this annotation

Codecov / codecov/patch

edi_storage_oca/components/listener.py#L28-L29

Added lines #L28 - L29 were not covered by tests

def _add_after_commit_hook(self, move_func, sftp_filepath, sftp_destination_path):
Expand Down
2 changes: 1 addition & 1 deletion edi_storage_oca/demo/edi_backend_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<record id="demo_edi_backend_storage" model="edi.backend">
<field name="name">Storage Demo EDI backend</field>
<field name="backend_type_id" ref="edi_oca.demo_edi_backend_type" />
<field name="storage_id" ref="storage_backend.default_storage_backend" />
<field name="storage_id" ref="fs_storage.default_fs_storage" />
<field name="input_dir_pending">demo_in/pending</field>
<field name="input_dir_done">demo_in/done</field>
<field name="input_dir_error">demo_in/error</field>
Expand Down
106 changes: 0 additions & 106 deletions edi_storage_oca/i18n/edi_storage_oca.pot

This file was deleted.

14 changes: 6 additions & 8 deletions edi_storage_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class EDIBackend(models.Model):
_inherit = "edi.backend"

storage_id = fields.Many2one(
string="Storage backend",
comodel_name="storage.backend",
string="FS Storage",
comodel_name="fs.storage",
help="Storage for in-out files",
ondelete="restrict",
)
Expand Down Expand Up @@ -67,21 +67,19 @@ def _get_component_usage_candidates(self, exchange_record, key):
return ["storage.{}".format(key)] + candidates

def _component_match_attrs(self, exchange_record, key):
# Override to inject storage_backend_type
# Override to inject storage_type
res = super()._component_match_attrs(exchange_record, key)
if not self.storage_id or key not in self._storage_actions:
return res
res["storage_backend_type"] = self.storage_id.backend_type
res["storage_type"] = self.storage_id.protocol
return res

def _component_sort_key(self, component_class):
res = super()._component_sort_key(component_class)
# Override to give precedence by storage_backend_type when needed.
# Override to give precedence by storage_type when needed.
if not self.storage_id:
return res
return (
1 if getattr(component_class, "_storage_backend_type", False) else 0,
) + res
return (1 if getattr(component_class, "_storage_type", False) else 0,) + res

def _storage_cron_check_pending_input(self, **kw):
for backend in self:
Expand Down
1 change: 1 addition & 0 deletions edi_storage_oca/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Simone Orsi <simahawk@gmail.com>
* Foram Shah <foram.shah@initos.com>
* Lois Rilo <lois.rilo@forgeflow.com>
* Duong (Tran Quoc) <duongtq@trobz.com>
1 change: 1 addition & 0 deletions edi_storage_oca/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp.
6 changes: 3 additions & 3 deletions edi_storage_oca/security/ir_model_access.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="ir.model.access" id="access_storage_backend_edi_manager">
<field name="name">access_storage_backend EDI manager</field>
<field name="model_id" ref="storage_backend.model_storage_backend" />
<record model="ir.model.access" id="access_fs_storage_edi_manager">
<field name="name">access_fs_storage EDI manager</field>
<field name="model_id" ref="fs_storage.model_fs_storage" />
<field name="group_id" ref="base_edi.group_edi_manager" />
<field name="perm_read" eval="1" />
<field name="perm_create" eval="1" />
Expand Down
Loading

0 comments on commit d2168b0

Please sign in to comment.