details: https://code.tryton.org/tryton/commit/e92eb501cc50
branch: default
user: Cédric Krier <[email protected]>
date: Wed Sep 09 12:22:52 2026 +0200
description:
Use decorator before ModelView.button to set default records for cron
task
Closes #15076
diffstat:
modules/account_fr_chorus/account.py | 46 +++++++++++++++-------------------
modules/edocument_peppol/edocument.py | 25 +++++++++++-------
2 files changed, 36 insertions(+), 35 deletions(-)
diffs (130 lines):
diff -r 02567102eb63 -r e92eb501cc50 modules/account_fr_chorus/account.py
--- a/modules/account_fr_chorus/account.py Wed Sep 16 14:35:33 2026 +0200
+++ b/modules/account_fr_chorus/account.py Wed Sep 09 12:22:52 2026 +0200
@@ -5,6 +5,7 @@
import logging
import posixpath
from collections import defaultdict
+from functools import wraps
from oauthlib.oauth2 import BackendApplicationClient, TokenExpiredError
from requests_oauthlib import OAuth2Session
@@ -204,6 +205,22 @@
InvoiceChorus.save(invoices_chorus)
+def default_records(state):
+ def decorator(func):
+ @wraps(func)
+ def wrapper(cls, records=None):
+ transaction = Transaction()
+ if records is None:
+ records = cls.search([
+ ('invoice.company', '=',
+ transaction.context.get('company')),
+ ('state', '=', state),
+ ])
+ return func(cls, records)
+ return wrapper
+ return decorator
+
+
class InvoiceChorus(
Workflow, ModelSQL, ModelView, _SyntaxMixin, metaclass=PoolMeta):
__name__ = 'account.invoice.chorus'
@@ -337,20 +354,10 @@
}
@classmethod
- def send(cls, records=None):
- transaction = Transaction()
- if not records:
- records = cls.search([
- ('invoice.company', '=',
- transaction.context.get('company')),
- ('state', '=', 'draft'),
- ])
- cls.send_button(records)
-
- @classmethod
+ @default_records('draft')
@ModelView.button
@Workflow.transition('sent')
- def send_button(cls, records=None):
+ def send(cls, records=None):
"""Send invoice to Chorus
The transaction is committed after each invoice.
@@ -396,20 +403,9 @@
}
@classmethod
+ @default_records('sent')
+ @ModelView.button
def update(cls, records=None):
- transaction = Transaction()
-
- if not records:
- records = cls.search([
- ('invoice.company', '=',
- transaction.context.get('company')),
- ('state', '=', 'sent'),
- ])
- cls.update_button(records)
-
- @classmethod
- @ModelView.button
- def update_button(cls, records=None):
"Update state from Chorus"
pool = Pool()
Credential = pool.get('account.credential.chorus')
diff -r 02567102eb63 -r e92eb501cc50 modules/edocument_peppol/edocument.py
--- a/modules/edocument_peppol/edocument.py Wed Sep 16 14:35:33 2026 +0200
+++ b/modules/edocument_peppol/edocument.py Wed Sep 09 12:22:52 2026 +0200
@@ -1,6 +1,7 @@
# 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 functools import wraps
from itertools import groupby
from sql.conditionals import NullIf
@@ -24,6 +25,18 @@
file_id = store_prefix = None
+def default_records(func):
+ @wraps(func)
+ def wrapper(cls, documents=None):
+ if documents is None:
+ documents = cls.search([
+ ('direction', '=', 'out'),
+ ('state', '=', 'processing'),
+ ])
+ return func(cls, documents)
+ return wrapper
+
+
class Peppol(Workflow, ModelSQL, ModelView):
__name__ = 'edocument.peppol'
@@ -246,17 +259,9 @@
self.succeed()
@classmethod
- def update_status(cls, documents=None):
- if documents is None:
- documents = cls.search([
- ('direction', '=', 'out'),
- ('state', '=', 'processing'),
- ])
- cls.update_status_button(documents)
-
- @classmethod
+ @default_records
@ModelView.button
- def update_status_button(cls, documents):
+ def update_status(cls, documents):
for document in documents:
document._update_status()
cls.save(documents)