Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ addon | version | maintainers | summary
[edi_sale_ubl_output_oca](edi_sale_ubl_output_oca/) | 18.0.1.0.1 | | Configuration and special behaviors for EDI on sales.
[edi_state_oca](edi_state_oca/) | 18.0.1.0.3 | <a href='https://github.com/simahawk'><img src='https://github.com/simahawk.png' width='32' height='32' style='border-radius:50%;' alt='simahawk'/></a> | Allow to assign specific EDI states to related records.
[edi_stock_oca](edi_stock_oca/) | 18.0.1.0.1 | | Define EDI Configuration for Stock
[edi_storage_oca](edi_storage_oca/) | 18.0.1.0.2 | | Base module to allow exchanging files via storage backend (eg: SFTP).
[edi_storage_oca](edi_storage_oca/) | 18.0.1.0.4 | | Base module to allow exchanging files via storage backend (eg: SFTP).
[edi_storage_queue_oca](edi_storage_queue_oca/) | 18.0.1.0.0 | | Integrates EDI Storage with Queue
[edi_ubl_oca](edi_ubl_oca/) | 18.0.1.0.1 | <a href='https://github.com/simahawk'><img src='https://github.com/simahawk.png' width='32' height='32' style='border-radius:50%;' alt='simahawk'/></a> | Define EDI backend type for UBL.
[edi_webservice_oca](edi_webservice_oca/) | 18.0.1.0.2 | <a href='https://github.com/etobella'><img src='https://github.com/etobella.png' width='32' height='32' style='border-radius:50%;' alt='etobella'/></a> <a href='https://github.com/simahawk'><img src='https://github.com/simahawk.png' width='32' height='32' style='border-radius:50%;' alt='simahawk'/></a> | Defines webservice integration from EDI Exchange records
Expand Down
2 changes: 1 addition & 1 deletion edi_storage_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EDI Storage backend support
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae52c0238c8bab278e4e2d6a48d86d4222672b893df1f171be046f3b7a3c58ae
!! source digest: sha256:ca9c4e0d1ecd9744b5cfa517900a5dace2a206007360ce2c1299dc1da5910bfa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
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 @@ -7,7 +7,7 @@
"summary": """
Base module to allow exchanging files via storage backend (eg: SFTP).
""",
"version": "18.0.1.0.2",
"version": "18.0.1.0.4",
"development_status": "Beta",
"license": "LGPL-3",
"website": "https://github.com/OCA/edi-framework",
Expand Down
6 changes: 6 additions & 0 deletions edi_storage_oca/i18n/edi_storage_oca.pot
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ msgstr ""
msgid "Storage Handler for EDI"
msgstr ""

#. module: edi_storage_oca
#. odoo-python
#: code:addons/edi_storage_oca/models/edi_oca_storage_handler.py:0
msgid "Storage error while reading %(path)s: %(error)s"
msgstr ""

#. module: edi_storage_oca
#: model:ir.model.fields,help:edi_storage_oca.field_edi_backend__storage_id
msgid "Storage for in-out files"
Expand Down
21 changes: 18 additions & 3 deletions edi_storage_oca/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ msgstr "Tipo scambio EDI"

#. module: edi_storage_oca
#: model:ir.actions.server,name:edi_storage_oca.cron_check_storage_pending_input_ir_actions_server
#: model:ir.cron,cron_name:edi_storage_oca.cron_check_storage_pending_input
msgid "EDI backend storage check pending input"
msgstr "Controllo ingressi in attesa deposito backend EDI"

Expand All @@ -51,8 +50,13 @@ msgstr "Deposito FS"
#. module: edi_storage_oca
#: model:ir.model.fields,help:edi_storage_oca.field_edi_exchange_type__exchange_filename_pattern
msgid ""
"For output exchange types this should be a formatting string with the following variables available (to be used between brackets, `{}`): `exchange_record`, `record_name`, `type` and `dt`. For instance, a valid string would be {record_name}-{type.code}-{dt}\n"
"For input exchange types related to storage backends it should be a regex expression to filter the files to be fetched from the pending directory in the related storage. E.g: `.*my-type-[0-9]*.\\.csv`"
"For output exchange types this should be a formatting string with the "
"following variables available (to be used between brackets, `{}`): "
"`exchange_record`, `record_name`, `type` and `dt`. For instance, a valid "
"string would be {record_name}-{type.code}-{dt}\n"
"For input exchange types related to storage backends it should be a regex "
"expression to filter the files to be fetched from the pending directory in "
"the related storage. E.g: `.*my-type-[0-9]*.\\.csv`"
msgstr ""
"Per i tipi di scambio in uscita questo dovrebbe essere una stringa di "
"formattazione con le seguenti variabili disponibili (da utilizzare tra "
Expand Down Expand Up @@ -120,6 +124,17 @@ msgstr "Record creato da un file trovato nel deposito FS"
msgid "Storage"
msgstr "Deposito"

#. module: edi_storage_oca
#: model:ir.model,name:edi_storage_oca.model_edi_oca_storage_handler
msgid "Storage Handler for EDI"
msgstr ""

#. module: edi_storage_oca
#. odoo-python
#: code:addons/edi_storage_oca/models/edi_oca_storage_handler.py:0
msgid "Storage error while reading %(path)s: %(error)s"
msgstr ""

#. module: edi_storage_oca
#: model:ir.model.fields,help:edi_storage_oca.field_edi_backend__storage_id
msgid "Storage for in-out files"
Expand Down
34 changes: 29 additions & 5 deletions edi_storage_oca/models/edi_oca_storage_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import PurePath

from odoo import models
from odoo.exceptions import UserError

from .. import utils

Expand All @@ -34,7 +35,9 @@ def send(self, exchange_record):
utils.add_file(exchange_record.backend_id.storage_id, path.as_posix(), filedata)

def receive(self, exchange_record):
return self._get_remote_file(exchange_record, "pending", binary=True)
return self._get_remote_file(
exchange_record, "pending", binary=True, raise_if_missing=True
)

def _dir_by_state(self, backend, direction, state):
"""Return remote directory path by direction and state.
Expand All @@ -61,11 +64,21 @@ def _get_remote_file_path(self, exchange_record, state, filename=None):
)
return path

def _get_remote_file(self, exchange_record, state, filename=None, binary=False):
def _get_remote_file(
self,
exchange_record,
state,
filename=None,
binary=False,
raise_if_missing=False,
):
"""Get file for current exchange_record in the given destination state.

:param state: string ("pending", "done", "error")
:param filename: custom file name, exchange_record filename used by default
:param raise_if_missing: when True, storage errors are re-raised as
swallable exceptions so the caller transitions the record to an
error state instead of treating "no content" as a successful read.
:return: remote file content as string
"""
path = self._get_remote_file_path(exchange_record, state, filename=filename)
Expand All @@ -84,14 +97,25 @@ def _get_remote_file(self, exchange_record, state, filename=None, binary=False):
path,
state,
)
if raise_if_missing:
raise
return None
except OSError:
_logger.info(
"Ignored OSError when trying to get file %s into path %s for state %s",
except OSError as err:
_logger.warning(
"OSError when trying to get file %s into path %s for state %s: %s",
filename,
path,
state,
err,
)
if raise_if_missing:
raise UserError(
self.env._(
"Storage error while reading %(path)s: %(error)s",
path=path.as_posix(),
error=str(err),
)
) from err
return None

def check(self, exchange_record):
Expand Down
2 changes: 1 addition & 1 deletion edi_storage_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>EDI Storage backend support</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae52c0238c8bab278e4e2d6a48d86d4222672b893df1f171be046f3b7a3c58ae
!! source digest: sha256:ca9c4e0d1ecd9744b5cfa517900a5dace2a206007360ce2c1299dc1da5910bfa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>Allow exchange files using storage backends from OCA/storage.</p>
Expand Down
2 changes: 2 additions & 0 deletions edi_storage_oca/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def list_files(storage, relative_path="", pattern=False):
if pattern:
relative_path = fs.sep.join([relative_path, pattern])
return fs.glob(relative_path)
if fs.protocol == "ftp" and fs.ftp:
return fs.ftp.nlst(relative_path)
return fs.ls(relative_path, detail=False)


Expand Down
Loading