From 3691d1e8efd31e8bd2ef752694e8c360d464d86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 13 Apr 2026 18:26:21 +0200 Subject: [PATCH] Add a delay to PEPPOL edocument rendering and processing for each service Closes #14767 --- modules/edocument_peppol/CHANGELOG | 1 + modules/edocument_peppol/edocument.py | 24 +++++++++++++++---- .../view/edocument_peppol_service_form.xml | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/edocument_peppol/CHANGELOG b/modules/edocument_peppol/CHANGELOG index afb36ea033..ec9e33c797 100644 --- a/modules/edocument_peppol/CHANGELOG +++ b/modules/edocument_peppol/CHANGELOG @@ -1,3 +1,4 @@ +* Add a delay to document processing for each service Version 8.0.0 - 2026-04-20 -------------------------- diff --git a/modules/edocument_peppol/edocument.py b/modules/edocument_peppol/edocument.py index e0458985dc..44bfb78c89 100644 --- a/modules/edocument_peppol/edocument.py +++ b/modules/edocument_peppol/edocument.py @@ -1,6 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from itertools import groupby + from sql.conditionals import NullIf from sql.operators import Equal @@ -9,7 +11,7 @@ from trytond.model import ( Exclude, MatchMixin, ModelSQL, ModelView, Workflow, dualmethod, fields, sequence_ordered) from trytond.pool import Pool -from trytond.pyson import Eval, If +from trytond.pyson import Eval, If, TimeDelta from trytond.transaction import Transaction from .exceptions import PeppolServiceError @@ -182,13 +184,16 @@ class Peppol(Workflow, ModelSQL, ModelView): def submit(cls, documents): pool = Pool() Service = pool.get('edocument.peppol.service') + transaction = Transaction() for document in documents: if not document.service: document.service = Service.get_service(document) - if document.direction == 'out': - document.data = document.render() cls.save(documents) - cls.__queue__.process(documents) + for process_after, sub_documents in groupby( + documents, lambda d: d.service.process_after): + with transaction.set_context( + queue_scheduled_at=process_after): + cls.__queue__.process(documents) def get_service_pattern(self): return { @@ -212,9 +217,11 @@ class Peppol(Workflow, ModelSQL, ModelView): cls.write(documents, {'state': 'processing'}) for document in documents: if document.direction == 'out': + document.data = document.render() cls.__queue__._process(document) else: document._process() + cls.save(documents) def _process(self): pool = Pool() @@ -299,6 +306,15 @@ class PeppolService(sequence_ordered(), MatchMixin, ModelSQL, ModelView): types = fields.MultiSelection( 'get_peppol_types', "Types", help="The types of document supported by the service provider.") + process_after = fields.TimeDelta( + "Process Document after", + domain=['OR', + ('process_after', '=', None), + ('process_after', '>=', TimeDelta()), + ], + help="The time taken to process a document " + "after it has been submitted.\n" + "Applied if a worker queue is activated.") @classmethod def default_company(cls): diff --git a/modules/edocument_peppol/view/edocument_peppol_service_form.xml b/modules/edocument_peppol/view/edocument_peppol_service_form.xml index 868640bf8f..2ae4b5fbeb 100644 --- a/modules/edocument_peppol/view/edocument_peppol_service_form.xml +++ b/modules/edocument_peppol/view/edocument_peppol_service_form.xml @@ -9,7 +9,8 @@ this repository contains the full copyright notices and license terms. -->