Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions base_cron_weekday/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=================
Base Cron Weekday
=================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:453890bf64f5ace83285eb727f27275145d393858cf5a9c1a08c2fb24c388865
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/19.0/base_cron_weekday
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_cron_weekday
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module lets you restrict a scheduled action (cron) from running on
specific weekdays.

Every scheduled action gains a set of per-weekday checkboxes (all
enabled by default, so behaviour is unchanged until you deselect a day).
When a run would fall on a deselected weekday, it is deferred to the
next allowed day at the same time of day instead of executing.

A common use case is skipping heavy or external-integration jobs on
weekends, when the remote service publishes nothing and the run has
nothing to do.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Go to *Settings > Technical > Automation > Scheduled Actions*
(developer mode).
2. Open a scheduled action.
3. Under *Run on Weekdays*, deselect the days on which the action must
not run.
4. Save. At least one weekday must stay selected.

Notes:

- The weekday is evaluated in the timezone of the action's *Scheduler
User*.
- Only the scheduled cadence is affected. Running an action manually or
through a code trigger still executes it regardless of the selected
weekdays.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_cron_weekday%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ForgeFlow

Contributors
------------

- ForgeFlow <https://www.forgeflow.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/base_cron_weekday>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions base_cron_weekday/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions base_cron_weekday/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2026 ForgeFlow
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

{
"name": "Base Cron Weekday",
"version": "19.0.1.0.0",
"category": "Technical Settings",
"summary": "Restrict scheduled actions from running on selected weekdays",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"license": "LGPL-3",
"depends": ["base"],
"data": ["views/ir_cron_views.xml"],
"installable": True,
}
1 change: 1 addition & 0 deletions base_cron_weekday/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_cron
75 changes: 75 additions & 0 deletions base_cron_weekday/models/ir_cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2026 ForgeFlow
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

from datetime import timedelta, timezone

from odoo import api, fields, models
from odoo.exceptions import ValidationError

WEEKDAY_FIELDS = [
("run_monday", 0),
("run_tuesday", 1),
("run_wednesday", 2),
("run_thursday", 3),
("run_friday", 4),
("run_saturday", 5),
("run_sunday", 6),
]


class IrCron(models.Model):
_inherit = "ir.cron"

run_monday = fields.Boolean(default=True)
run_tuesday = fields.Boolean(default=True)
run_wednesday = fields.Boolean(default=True)
run_thursday = fields.Boolean(default=True)
run_friday = fields.Boolean(default=True)
run_saturday = fields.Boolean(default=True)
run_sunday = fields.Boolean(default=True)

@api.constrains(*[name for name, _weekday in WEEKDAY_FIELDS])
def _check_run_weekdays(self):
for cron in self:
if not any(cron[name] for name, _weekday in WEEKDAY_FIELDS):
raise ValidationError(
self.env._(
"A scheduled action must be allowed to run on at least "
"one weekday."
)
)

def _disallowed_weekdays(self):
"""Return the set of Python weekday numbers (Mon=0..Sun=6) the cron
must not run on."""
self.ensure_one()
return {weekday for name, weekday in WEEKDAY_FIELDS if not self[name]}

def _weekday_in_tz(self, nextcall):
"""Weekday of a naive-UTC ``nextcall`` evaluated in the cron's timezone."""
return fields.Datetime.context_timestamp(self, nextcall).weekday()

@api.model
def _reschedule_later(self, job):
super()._reschedule_later(job)
cron = self.browse(job["id"])
disallowed = cron._disallowed_weekdays()
if not disallowed:
return
# core wrote nextcall via raw SQL, so drop the stale ORM value first.
cron.invalidate_recordset(["nextcall"])
nextcall = cron.nextcall
# Defer one day at a time to the next allowed weekday, at the same time
# of day. Bounded to at most 6 steps since at least one weekday is
# always allowed.
guard = 0
while cron._weekday_in_tz(nextcall) in disallowed and guard < 7:
nextcall = fields.Datetime.context_timestamp(cron, nextcall)
nextcall += timedelta(days=1)
nextcall = nextcall.astimezone(timezone.utc).replace(tzinfo=None)
guard += 1
if nextcall != cron.nextcall:
self.env.cr.execute(
"UPDATE ir_cron SET nextcall = %s WHERE id = %s",
[nextcall, job["id"]],
)
3 changes: 3 additions & 0 deletions base_cron_weekday/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions base_cron_weekday/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- ForgeFlow \<<https://www.forgeflow.com>\>
11 changes: 11 additions & 0 deletions base_cron_weekday/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module lets you restrict a scheduled action (cron) from running on
specific weekdays.

Every scheduled action gains a set of per-weekday checkboxes (all
enabled by default, so behaviour is unchanged until you deselect a day).
When a run would fall on a deselected weekday, it is deferred to the
next allowed day at the same time of day instead of executing.

A common use case is skipping heavy or external-integration jobs on
weekends, when the remote service publishes nothing and the run has
nothing to do.
14 changes: 14 additions & 0 deletions base_cron_weekday/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
1. Go to *Settings \> Technical \> Automation \> Scheduled Actions*
(developer mode).
2. Open a scheduled action.
3. Under *Run on Weekdays*, deselect the days on which the action must
not run.
4. Save. At least one weekday must stay selected.

Notes:

- The weekday is evaluated in the timezone of the action's *Scheduler
User*.
- Only the scheduled cadence is affected. Running an action manually or
through a code trigger still executes it regardless of the selected
weekdays.
Loading
Loading