details:   https://code.tryton.org/tryton/commit/4e07f2a933a2
branch:    default
user:      Cédric Krier <[email protected]>
date:      Mon Apr 13 18:26:21 2026 +0200
description:
        Add a delay to PEPPOL edocument rendering and processing for each 
service

        Closes #14767
diffstat:

 modules/edocument_peppol/CHANGELOG                              |   1 +
 modules/edocument_peppol/edocument.py                           |  24 ++++++++-
 modules/edocument_peppol/view/edocument_peppol_service_form.xml |   3 +-
 3 files changed, 23 insertions(+), 5 deletions(-)

diffs (90 lines):

diff -r 58a34c698a9b -r 4e07f2a933a2 modules/edocument_peppol/CHANGELOG
--- a/modules/edocument_peppol/CHANGELOG        Thu Apr 02 15:29:10 2026 +0200
+++ b/modules/edocument_peppol/CHANGELOG        Mon Apr 13 18:26:21 2026 +0200
@@ -1,3 +1,4 @@
+* Add a delay to document processing for each service
 
 Version 8.0.0 - 2026-04-20
 --------------------------
diff -r 58a34c698a9b -r 4e07f2a933a2 modules/edocument_peppol/edocument.py
--- a/modules/edocument_peppol/edocument.py     Thu Apr 02 15:29:10 2026 +0200
+++ b/modules/edocument_peppol/edocument.py     Mon Apr 13 18:26:21 2026 +0200
@@ -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 @@
     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 @@
     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 @@
         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 @@
     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 -r 58a34c698a9b -r 4e07f2a933a2 
modules/edocument_peppol/view/edocument_peppol_service_form.xml
--- a/modules/edocument_peppol/view/edocument_peppol_service_form.xml   Thu Apr 
02 15:29:10 2026 +0200
+++ b/modules/edocument_peppol/view/edocument_peppol_service_form.xml   Mon Apr 
13 18:26:21 2026 +0200
@@ -9,7 +9,8 @@
 
     <label name="service"/>
     <field name="service"/>
-    <newline/>
+    <label name="process_after"/>
+    <field name="process_after"/>
 
     <label name="types"/>
     <field name="types" colspan="3" yexpand="0"/>

Reply via email to