diff --git a/trytond/trytond/ir/cron.py b/trytond/trytond/ir/cron.py index 5e0693fbc2..7d170b9698 100644 --- a/trytond/trytond/ir/cron.py +++ b/trytond/trytond/ir/cron.py @@ -3,6 +3,7 @@ import datetime import hashlib import logging +import random import time from collections import defaultdict @@ -181,15 +182,18 @@ class Cron(DeactivableMixin, ModelSQL, ModelView): microsecond=0, second=0, minute=( - self.minute + (self.minute if self.minute is not None + else random.randint(0, 59)) if self.interval_type != 'minutes' else None), hour=( - self.hour + (self.hour if self.hour is not None + else random.randint(0, 23)) if self.interval_type not in {'minutes', 'hours'} else None), day=( - self.day + (self.day if self.day is not None + else random.randint(0, 31)) if self.interval_type not in { 'minutes', 'hours', 'days', 'weeks'} else None), diff --git a/trytond/trytond/tests/test_ir.py b/trytond/trytond/tests/test_ir.py index b303229ba2..b7fb6ac011 100644 --- a/trytond/trytond/tests/test_ir.py +++ b/trytond/trytond/tests/test_ir.py @@ -515,6 +515,7 @@ class IrCronTestCase(TestCase): cron.interval_number = 1 cron.interval_type = 'days' cron.hour = 1 + cron.minute = 0 # Quebec is UTC-5 self.assertEqual( @@ -529,6 +530,7 @@ class IrCronTestCase(TestCase): cron.interval_number = 1 cron.interval_type = 'days' cron.hour = 2 + cron.minute = 30 # 2022-03-13 is the day of DST switch # Quebec is UTC-4 @@ -542,6 +544,7 @@ class IrCronTestCase(TestCase): cron = self._get_cron() cron.interval_number = 1 cron.interval_type = 'hours' + cron.minute = 30 # 2022-11-06 is the day of DST switch # Quebec is UTC-5