diff --git a/edi_endpoint_oca/README.rst b/edi_endpoint_oca/README.rst index 9ce8aadc7..d37f6647e 100644 --- a/edi_endpoint_oca/README.rst +++ b/edi_endpoint_oca/README.rst @@ -45,6 +45,21 @@ Configuration Go to "EDI -> Config -> Endpoints". +Exec modes +---------- + +Each endpoint must pick an "Exec mode" that decides how the incoming +request is turned into work for the EDI framework: + +- **Create exchange record** (default): persists the raw HTTP body as a + new exchange record on the configured backend / exchange type and + returns ``{"status": "queued", "id": }`` with HTTP 200. + Use this for "receive and queue" endpoints — no per-endpoint code + snippet is required, and request validation (e.g. JSON Schema) is + handled by the endpoint mixin before the handler runs. +- **Execute code**: runs the user-provided code snippet, giving full + control over how the request is processed and what is returned. + Bug Tracker =========== diff --git a/edi_endpoint_oca/demo/edi_backend_demo.xml b/edi_endpoint_oca/demo/edi_backend_demo.xml index cea2db0e8..e211b69f9 100644 --- a/edi_endpoint_oca/demo/edi_backend_demo.xml +++ b/edi_endpoint_oca/demo/edi_backend_demo.xml @@ -26,4 +26,15 @@ record = endpoint.create_exchange_record() result = {"response": Response("Created record: %s" % record.identifier)} + + + + + + EDI Demo Endpoint 2 + /demo/create + POST + application/json + create_exchange_record + diff --git a/edi_endpoint_oca/models/edi_endpoint.py b/edi_endpoint_oca/models/edi_endpoint.py index cff7b9e46..d949be77b 100644 --- a/edi_endpoint_oca/models/edi_endpoint.py +++ b/edi_endpoint_oca/models/edi_endpoint.py @@ -33,6 +33,26 @@ class EDIEndpoint(models.Model): comodel_name="edi.exchange.type", domain="[('backend_type_id','=', backend_type_id)]", ) + exec_mode = fields.Selection(default="create_exchange_record") + + def _selection_exec_mode(self): + return super()._selection_exec_mode() + [ + ("create_exchange_record", self.env._("Create exchange record")), + ] + + def _handle_exec__create_exchange_record(self, request): + """Persist the raw HTTP body as an exchange record and acknowledge. + + Covers the "receive and queue" case for incoming EDI endpoints, + avoiding the need for a per-endpoint code snippet. + """ + record = self.create_exchange_record( + file_content=request.httprequest.get_data(), + ) + return { + "payload": {"status": "queued", "id": record.identifier}, + "status_code": 200, + } def create_exchange_record(self, file_content=None, encoding="utf-8", **vals): """Create an EDI exchange record from current endpoint. diff --git a/edi_endpoint_oca/readme/CONFIGURE.md b/edi_endpoint_oca/readme/CONFIGURE.md index 040110335..1064882a8 100644 --- a/edi_endpoint_oca/readme/CONFIGURE.md +++ b/edi_endpoint_oca/readme/CONFIGURE.md @@ -1 +1,15 @@ Go to "EDI -\> Config -\> Endpoints". + +## Exec modes + +Each endpoint must pick an "Exec mode" that decides how the incoming +request is turned into work for the EDI framework: + +- **Create exchange record** (default): persists the raw HTTP body as a + new exchange record on the configured backend / exchange type and + returns `{"status": "queued", "id": }` with HTTP 200. Use + this for "receive and queue" endpoints — no per-endpoint code snippet + is required, and request validation (e.g. JSON Schema) is handled by + the endpoint mixin before the handler runs. +- **Execute code**: runs the user-provided code snippet, giving full + control over how the request is processed and what is returned. diff --git a/edi_endpoint_oca/static/description/index.html b/edi_endpoint_oca/static/description/index.html index a5da052ac..e3289d73f 100644 --- a/edi_endpoint_oca/static/description/index.html +++ b/edi_endpoint_oca/static/description/index.html @@ -380,12 +380,15 @@

EDI endpoint

Table of contents