Use decorator before ModelView.button to set default records for cron task

Closes #15076
(grafted from e92eb501cc50ea906fa839596f2c533b787126d6)

--HG--
branch : 8.0
This commit is contained in:
Cédric Krier
2026-09-09 12:22:52 +02:00
parent 7733443332
commit 78ffbdd65f
2 changed files with 37 additions and 35 deletions
+16 -10
View File
@@ -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 functools import wraps
from sql.conditionals import NullIf
from sql.operators import Equal
@@ -22,6 +24,18 @@ else:
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'
@@ -239,17 +253,9 @@ class Peppol(Workflow, ModelSQL, ModelView):
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)