Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,44 @@
# Multi-week calendars
Odoo addon: resource_multi_week_calendar
## Installation
```bash
pip install odoo-bringout-oca-hr-resource_multi_week_calendar
```
## Dependencies
This addon depends on:
- resource
## Manifest Information
- **Name**: Multi-week calendars
- **Version**: 16.0.1.0.0
- **Category**: Hidden
- **License**: AGPL-3
- **Installable**: False
## Source
Based on [OCA/hr](https://github.com/OCA/hr) branch 16.0, addon `resource_multi_week_calendar`.
## License
This package maintains the original AGPL-3 license from the upstream Odoo project.
## Documentation
- Overview: doc/OVERVIEW.md
- Architecture: doc/ARCHITECTURE.md
- Models: doc/MODELS.md
- Controllers: doc/CONTROLLERS.md
- Wizards: doc/WIZARDS.md
- Install: doc/INSTALL.md
- Usage: doc/USAGE.md
- Configuration: doc/CONFIGURATION.md
- Dependencies: doc/DEPENDENCIES.md
- Troubleshooting: doc/TROUBLESHOOTING.md
- FAQ: doc/FAQ.md

View file

@ -0,0 +1,32 @@
# Architecture
```mermaid
flowchart TD
U[Users] -->|HTTP| V[Views and QWeb Templates]
V --> C[Controllers]
V --> W[Wizards Transient Models]
C --> M[Models and ORM]
W --> M
M --> R[Reports]
DX[Data XML] --> M
S[Security ACLs and Groups] -. enforces .-> M
subgraph Resource_multi_week_calendar Module - resource_multi_week_calendar
direction LR
M:::layer
W:::layer
C:::layer
V:::layer
R:::layer
S:::layer
DX:::layer
end
classDef layer fill:#eef8ff,stroke:#6ea8fe,stroke-width:1px
```
Notes
- Views include tree/form/kanban templates and report templates.
- Controllers provide website/portal routes when present.
- Wizards are UI flows implemented with `models.TransientModel`.
- Data XML loads data/demo records; Security defines groups and access.

View file

@ -0,0 +1,3 @@
# Configuration
Refer to Odoo settings for resource_multi_week_calendar. Configure related models, access rights, and options as needed.

View file

@ -0,0 +1,3 @@
# Controllers
This module does not define custom HTTP controllers.

View file

@ -0,0 +1,5 @@
# Dependencies
This addon depends on:
- [resource](../../odoo-bringout-oca-ocb-resource)

View file

@ -0,0 +1,4 @@
# FAQ
- Q: Which Odoo version? A: 16.0 (OCA/OCB packaged).
- Q: How to enable? A: Start server with --addon resource_multi_week_calendar or install in UI.

View file

@ -0,0 +1,7 @@
# Install
```bash
pip install odoo-bringout-oca-hr-resource_multi_week_calendar"
# or
uv pip install odoo-bringout-oca-hr-resource_multi_week_calendar"
```

View file

@ -0,0 +1,12 @@
# Models
Detected core models and extensions in resource_multi_week_calendar.
```mermaid
classDiagram
class resource_calendar
```
Notes
- Classes show model technical names; fields omitted for brevity.
- Items listed under _inherit are extensions of existing models.

View file

@ -0,0 +1,6 @@
# Overview
Packaged Odoo addon: resource_multi_week_calendar. Provides features documented in upstream Odoo 16 under this addon.
- Source: OCA/OCB 16.0, addon resource_multi_week_calendar
- License: LGPL-3

View file

@ -0,0 +1,3 @@
# Reports
This module does not define custom reports.

View file

@ -0,0 +1,8 @@
# Security
This module does not define custom security rules or access controls beyond Odoo defaults.
Default Odoo security applies:
- Base user access through standard groups
- Model access inherited from dependencies
- No custom row-level security rules

View file

@ -0,0 +1,5 @@
# Troubleshooting
- Ensure Python and Odoo environment matches repo guidance.
- Check database connectivity and logs if startup fails.
- Validate that dependent addons listed in DEPENDENCIES.md are installed.

View file

@ -0,0 +1,7 @@
# Usage
Start Odoo including this addon (from repo root):
```bash
python3 scripts/nix_odoo_web_server.py --db-name mydb --addon resource_multi_week_calendar
```

View file

@ -0,0 +1,3 @@
# Wizards
This module does not include UI wizards.

View file

@ -0,0 +1,43 @@
[project]
name = "odoo-bringout-oca-hr-resource_multi_week_calendar"
version = "16.0.0"
description = "Multi-week calendars -
Allow a calendar to alternate between multiple weeks."
authors = [
{ name = "Ernad Husremovic", email = "hernad@bring.out.ba" }
]
dependencies = [
"odoo-bringout-oca-ocb-resource>=16.0.0",
"requests>=2.25.1"
]
readme = "README.md"
requires-python = ">= 3.11"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Office/Business",
]
[project.urls]
homepage = "https://github.com/bringout/0"
repository = "https://github.com/bringout/0"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.metadata]
allow-direct-references = true
[tool.hatch.build.targets.wheel]
packages = ["resource_multi_week_calendar"]
[tool.rye]
managed = true
dev-dependencies = [
"pytest>=8.4.1",
]

View file

@ -0,0 +1,120 @@
====================
Multi-week calendars
====================
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4348386169e012a60689410f75f79832320917b387e3a14fe186f1a7f1bd3ace
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/16.0/resource_multi_week_calendar
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-16-0/hr-16-0-resource_multi_week_calendar
: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/hr&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
Allow a calendar to alternate between multiple weeks.
An implementation of this functionality exists in Odoo's ``resource`` module
since version 13. In Odoo's implementation, you can only alternate between two
weeks. Furthermore, the implementation is more than a little wonky.
The advantage of this module over the implementation in ``resource`` is that you
can alternate between more than two weeks. The implementation is (hopefully)
better.
The downside of adopting this module is that all modules which interact with the
week-alternating functionality of ``resource`` must be adapted to be compatible
with this module. At the time of writing (2024-07-29), the only Odoo module
which does this is ``hr_holidays``.
**Table of contents**
.. contents::
:local:
Known issues / Roadmap
======================
This module is a template for building on top of. It _will_ need glue modules to
work with various other modules. Most notably, ``hr_holidays`` will not work
without modification.
The existing base Odoo two-week calendar functionality is hidden rather than
disabled. This may or may not be desirable.
The module may need improvements for timezone handling; this is currently
untested. ``_split_into_weeks`` splits weeks on the timezone of the datetime
objects passed to it instead of on the timezone of the calendar. The calculation
of the current week number uses ``fields.Date.today()`` instead of the
environment's or calendar's timezone. Finally, child calendars may have a
different timezone compared to their parent, which is probably not a desired
feature.
This module assumes that a week always starts on a Monday. Upstream Odoo appears
to do the same, but this may not be desired by certain audiences.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/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/hr/issues/new?body=module:%20resource_multi_week_calendar%0Aversion:%2016.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
~~~~~~~
* Coop IT Easy SC
Contributors
~~~~~~~~~~~~
* `Coop IT Easy SC <https://coopiteasy.be>`_:
* Carmen Bianca BAKKER
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.
.. |maintainer-carmenbianca| image:: https://github.com/carmenbianca.png?size=40px
:target: https://github.com/carmenbianca
:alt: carmenbianca
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-carmenbianca|
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/16.0/resource_multi_week_calendar>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import models

View file

@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{
"name": "Multi-week calendars",
"summary": """
Allow a calendar to alternate between multiple weeks.""",
"version": "16.0.1.0.0",
"category": "Hidden",
"website": "https://github.com/OCA/hr",
"author": "Coop IT Easy SC, Odoo Community Association (OCA)",
"maintainers": ["carmenbianca"],
"license": "AGPL-3",
"application": False,
"depends": [
"resource",
],
"data": [
"views/resource_calendar_views.xml",
],
}

View file

@ -0,0 +1,86 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * resource_multi_week_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__child_calendar_ids
msgid "Alternating Working Times"
msgstr "Alternativna radna vremena"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_multi_week_calendar_id
msgid "Current Multi Week Calendar"
msgstr "Trenutni višetjedni kalendar"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_week_number
msgid "Current Week Number"
msgstr "Trenutni broj tjedna"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid "Date of First Week"
msgstr "Datum prvog tjedna"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__is_multi_week
msgid "Is Multi Week"
msgstr "Je višetjedni"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__parent_calendar_id
msgid "Main Working Time"
msgstr "Glavno radno vrijeme"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_calendar_ids
msgid "Multi Week Calendar"
msgstr "Višetjedni kalendar"
#. module: resource_multi_week_calendar
#: model_terms:ir.ui.view,arch_db:resource_multi_week_calendar.view_resource_calendar_search
msgid "Only Main Working Times"
msgstr "Samo glavna radna vremena"
#. module: resource_multi_week_calendar
#: model:ir.model,name:resource_multi_week_calendar.model_resource_calendar
msgid "Resource Working Time"
msgstr "Radno vrijeme resursa"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_number
msgid "Week Number"
msgstr "Sedmica broj"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_sequence
msgid "Week Sequence"
msgstr "Sekvenca tjedana"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,help:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid ""
"When using alternating weeks, the week which contains the\n"
" specified date becomes the first week, and all subsequent weeks\n"
" alternate in order."
msgstr ""
#. module: resource_multi_week_calendar
#. odoo-python
#: code:addons/resource_multi_week_calendar/models/resource_calendar.py:0
#, python-format
msgid ""
"Working Time '%(name)s' may not be the Main Working Time of another Working "
"Time ('%(child)s') while it has a Main Working Time itself ('%(parent)s')"
msgstr ""

View file

@ -0,0 +1,96 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * resource_multi_week_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-06-04 10:26+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.4\n"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__child_calendar_ids
msgid "Alternating Working Times"
msgstr "Orari di lavoro alternati"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_multi_week_calendar_id
msgid "Current Multi Week Calendar"
msgstr "Calendario multi settimana attuale"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_week_number
msgid "Current Week Number"
msgstr "Numero settimana attuale"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid "Date of First Week"
msgstr "Data della prima settimana"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__is_multi_week
msgid "Is Multi Week"
msgstr "È multi settimana"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__parent_calendar_id
msgid "Main Working Time"
msgstr "Orario di lavoro principale"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_calendar_ids
msgid "Multi Week Calendar"
msgstr "Calendario multi settimana"
#. module: resource_multi_week_calendar
#: model_terms:ir.ui.view,arch_db:resource_multi_week_calendar.view_resource_calendar_search
msgid "Only Main Working Times"
msgstr "Solo orari di lavoro principali"
#. module: resource_multi_week_calendar
#: model:ir.model,name:resource_multi_week_calendar.model_resource_calendar
msgid "Resource Working Time"
msgstr "Orario lavoro risorsa"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_number
msgid "Week Number"
msgstr "Numero settimana"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_sequence
msgid "Week Sequence"
msgstr "Sequenza settimana"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,help:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid ""
"When using alternating weeks, the week which contains the\n"
" specified date becomes the first week, and all subsequent weeks\n"
" alternate in order."
msgstr ""
"Quando si utilizzano settimane alternate, la settimana che contiene \n"
" la data specificata diventa la prima settimana e tutte le settimane "
"successive \n"
" si alternano in ordine."
#. module: resource_multi_week_calendar
#. odoo-python
#: code:addons/resource_multi_week_calendar/models/resource_calendar.py:0
#, python-format
msgid ""
"Working Time '%(name)s' may not be the Main Working Time of another Working "
"Time ('%(child)s') while it has a Main Working Time itself ('%(parent)s')"
msgstr ""
"L'orario di lavoro '%(name)s' non può essere l'orario di lavoro principale "
"di un altro orario di lavoro ('%(child)s') se ha un orario di lavoro "
"principale ('%(parent)s')"

View file

@ -0,0 +1,86 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * resource_multi_week_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__child_calendar_ids
msgid "Alternating Working Times"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_multi_week_calendar_id
msgid "Current Multi Week Calendar"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__current_week_number
msgid "Current Week Number"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid "Date of First Week"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__is_multi_week
msgid "Is Multi Week"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__parent_calendar_id
msgid "Main Working Time"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__multi_week_calendar_ids
msgid "Multi Week Calendar"
msgstr ""
#. module: resource_multi_week_calendar
#: model_terms:ir.ui.view,arch_db:resource_multi_week_calendar.view_resource_calendar_search
msgid "Only Main Working Times"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model,name:resource_multi_week_calendar.model_resource_calendar
msgid "Resource Working Time"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_number
msgid "Week Number"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,field_description:resource_multi_week_calendar.field_resource_calendar__week_sequence
msgid "Week Sequence"
msgstr ""
#. module: resource_multi_week_calendar
#: model:ir.model.fields,help:resource_multi_week_calendar.field_resource_calendar__multi_week_epoch_date
msgid ""
"When using alternating weeks, the week which contains the\n"
" specified date becomes the first week, and all subsequent weeks\n"
" alternate in order."
msgstr ""
#. module: resource_multi_week_calendar
#. odoo-python
#: code:addons/resource_multi_week_calendar/models/resource_calendar.py:0
#, python-format
msgid ""
"Working Time '%(name)s' may not be the Main Working Time of another Working "
"Time ('%(child)s') while it has a Main Working Time itself ('%(parent)s')"
msgstr ""

View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import resource_calendar

View file

@ -0,0 +1,264 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import math
from datetime import datetime, timedelta
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ResourceCalendar(models.Model):
_inherit = "resource.calendar"
parent_calendar_id = fields.Many2one(
comodel_name="resource.calendar",
domain=[("parent_calendar_id", "=", False)],
ondelete="cascade",
string="Main Working Time",
)
child_calendar_ids = fields.One2many(
comodel_name="resource.calendar",
inverse_name="parent_calendar_id",
string="Alternating Working Times",
copy=True,
)
# These are all your siblings (including yourself) if you are a child, or
# all your children if you are a parent. This is not a sorted set.
multi_week_calendar_ids = fields.One2many(
comodel_name="resource.calendar",
compute="_compute_multi_week_calendar_ids",
recursive=True,
)
is_multi_week = fields.Boolean(compute="_compute_is_multi_week", store=True)
# Making week_number a computed derivative of week_sequence has the
# advantage of being able to drag calendars around in a table, and not
# having to manually fiddle with every week number (nor make sure that no
# weeks are skipped).
#
# However, week sequences MUST be unique. Unfortunately, creating a
# constraint on (parent_calendar_id, week_sequence) does not work. The
# constraint method is called before all children/siblings are saved,
# meaning that they can conflict with each other in this interim stage.
#
# If this value is not unique, the order is preserved between the identical
# elements. The elements of child_calendar_ids are always sorted by _order,
# which is id by default. The value may not be unique when new calendars are
# added.
week_sequence = fields.Integer(default=0)
week_number = fields.Integer(
compute="_compute_week_number",
store=True,
recursive=True,
)
current_week_number = fields.Integer(
compute="_compute_current_week",
recursive=True,
)
current_multi_week_calendar_id = fields.Many2one(
comodel_name="resource.calendar",
compute="_compute_current_week",
recursive=True,
)
multi_week_epoch_date = fields.Date(
string="Date of First Week",
help="""When using alternating weeks, the week which contains the
specified date becomes the first week, and all subsequent weeks
alternate in order.""",
required=True,
default="1970-01-01",
)
def copy(self, default=None):
self.ensure_one()
if default is None:
default = {}
sequences = sorted(self.multi_week_calendar_ids.mapped("week_sequence"))
if sequences:
# Assign highest value sequence.
default["week_sequence"] = sequences[-1] + 1
return super().copy(default=default)
@api.depends(
"child_calendar_ids",
"parent_calendar_id",
"parent_calendar_id.child_calendar_ids",
)
def _compute_multi_week_calendar_ids(self):
for calendar in self:
parent = calendar.parent_calendar_id or calendar
calendar.multi_week_calendar_ids = parent.child_calendar_ids
@api.depends(
"child_calendar_ids",
"parent_calendar_id",
)
def _compute_is_multi_week(self):
for calendar in self:
calendar.is_multi_week = bool(
calendar.child_calendar_ids or calendar.parent_calendar_id
)
@api.depends(
"week_sequence",
"parent_calendar_id",
"parent_calendar_id.child_calendar_ids",
"parent_calendar_id.child_calendar_ids.week_sequence",
)
def _compute_week_number(self):
for calendar in self:
parent = calendar.parent_calendar_id
if parent:
for week_number, sibling in enumerate(
parent.child_calendar_ids.sorted(lambda item: item.week_sequence),
start=1,
):
if calendar == sibling:
calendar.week_number = week_number
break
else:
# Parent calendars have no week number.
calendar.week_number = 0
def _get_first_day_of_epoch_week(self):
self.ensure_one()
epoch_date = self.get_multi_week_epoch_date()
return epoch_date - timedelta(days=epoch_date.weekday())
def _get_week_number(self, day=None):
self.ensure_one()
if not self.is_multi_week:
return 0
if day is None:
day = fields.Date.today()
if isinstance(day, datetime):
day = day.date()
calendar_count = len(self.multi_week_calendar_ids)
weeks_since_epoch = math.floor(
(day - self._get_first_day_of_epoch_week()).days / 7
)
return (weeks_since_epoch % calendar_count) + 1
def _get_multi_week_calendar(self, day=None):
self.ensure_one()
if not self.is_multi_week:
return self
week_number = self._get_week_number(day=day)
# Should return a 1-item recordset. If it does not, we've hit a bug.
return self.multi_week_calendar_ids.filtered(
lambda item: item.week_number == week_number
)
@api.depends(
"multi_week_epoch_date",
"week_number",
"multi_week_calendar_ids",
)
def _compute_current_week(self):
for calendar in self:
current_calendar = calendar._get_multi_week_calendar()
calendar.current_multi_week_calendar_id = current_calendar
calendar.current_week_number = current_calendar.week_number
@api.constrains("parent_calendar_id", "child_calendar_ids")
def _check_child_is_not_parent(self):
err_str = _(
"Working Time '%(name)s' may not be the Main Working Time of"
" another Working Time ('%(child)s') while it has a Main Working"
" Time itself ('%(parent)s')"
)
for calendar in self:
if calendar.parent_calendar_id and calendar.child_calendar_ids:
raise ValidationError(
err_str
% {
"name": calendar.name,
"child": calendar.child_calendar_ids[0].name,
"parent": calendar.parent_calendar_id.name,
}
)
# This constraint isn't triggered on calendars which have children
# added to them. Therefore, we also check whether our parent already
# has a parent.
if (
calendar.parent_calendar_id
and calendar.parent_calendar_id.parent_calendar_id
):
raise ValidationError(
err_str
% {
"name": calendar.parent_calendar_id.name,
"child": calendar.name,
"parent": calendar.parent_calendar_id.parent_calendar_id.name,
}
)
def get_multi_week_epoch_date(self):
self.ensure_one()
if self.parent_calendar_id:
return self.parent_calendar_id.multi_week_epoch_date
return self.multi_week_epoch_date
@api.model
def _split_into_weeks(self, start_dt, end_dt):
# TODO: This method splits weeks on the timezone of start_dt. Maybe it
# should split weeks on the timezone of the calendar. It is not
# immediately clear to me how to implement that.
current_start = start_dt
while current_start < end_dt:
# Calculate the end of the week (Monday 00:00:00, the threshold
# of Sunday-to-Monday.)
days_until_monday = 7 - current_start.weekday()
week_end = current_start + timedelta(days=days_until_monday)
week_end = week_end.replace(hour=0, minute=0, second=0, microsecond=0)
current_end = min(week_end, end_dt)
yield (current_start, current_end)
# Move to the next week (start of next Monday)
current_start = current_end
def _attendance_intervals_batch(
self, start_dt, end_dt, resources=None, domain=None, tz=None
):
self.ensure_one()
if not self.is_multi_week:
return super()._attendance_intervals_batch(
start_dt, end_dt, resources=resources, domain=domain, tz=tz
)
calendars_by_week = {
calendar.week_number: calendar for calendar in self.multi_week_calendar_ids
}
results = []
# Calculate each week separately, choosing the correct calendar for each
# week.
for week_start, week_end in self._split_into_weeks(start_dt, end_dt):
results.append(
super(
ResourceCalendar,
calendars_by_week[self._get_week_number(week_start)].with_context(
# This context is not used here, but could possibly be
# used by other modules that use this module. I am not
# sure how useful it is.
recursive_multi_week=True
),
)._attendance_intervals_batch(
week_start, week_end, resources=resources, domain=domain, tz=tz
)
)
# Aggregate the results from each week.
result = {}
for item in results:
for resource, intervals in item.items():
if resource not in result:
result[resource] = intervals
else:
result[resource] |= intervals
return result

View file

@ -0,0 +1,3 @@
* `Coop IT Easy SC <https://coopiteasy.be>`_:
* Carmen Bianca BAKKER

View file

@ -0,0 +1,14 @@
Allow a calendar to alternate between multiple weeks.
An implementation of this functionality exists in Odoo's ``resource`` module
since version 13. In Odoo's implementation, you can only alternate between two
weeks. Furthermore, the implementation is more than a little wonky.
The advantage of this module over the implementation in ``resource`` is that you
can alternate between more than two weeks. The implementation is (hopefully)
better.
The downside of adopting this module is that all modules which interact with the
week-alternating functionality of ``resource`` must be adapted to be compatible
with this module. At the time of writing (2024-07-29), the only Odoo module
which does this is ``hr_holidays``.

View file

@ -0,0 +1,17 @@
This module is a template for building on top of. It _will_ need glue modules to
work with various other modules. Most notably, ``hr_holidays`` will not work
without modification.
The existing base Odoo two-week calendar functionality is hidden rather than
disabled. This may or may not be desirable.
The module may need improvements for timezone handling; this is currently
untested. ``_split_into_weeks`` splits weeks on the timezone of the datetime
objects passed to it instead of on the timezone of the calendar. The calculation
of the current week number uses ``fields.Date.today()`` instead of the
environment's or calendar's timezone. Finally, child calendars may have a
different timezone compared to their parent, which is probably not a desired
feature.
This module assumes that a week always starts on a Monday. Upstream Odoo appears
to do the same, but this may not be desired by certain audiences.

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -0,0 +1,456 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Multi-week calendars</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic, pre.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="multi-week-calendars">
<h1 class="title">Multi-week calendars</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4348386169e012a60689410f75f79832320917b387e3a14fe186f1a7f1bd3ace
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr/tree/16.0/resource_multi_week_calendar"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-16-0/hr-16-0-resource_multi_week_calendar"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Allow a calendar to alternate between multiple weeks.</p>
<p>An implementation of this functionality exists in Odoos <tt class="docutils literal">resource</tt> module
since version 13. In Odoos implementation, you can only alternate between two
weeks. Furthermore, the implementation is more than a little wonky.</p>
<p>The advantage of this module over the implementation in <tt class="docutils literal">resource</tt> is that you
can alternate between more than two weeks. The implementation is (hopefully)
better.</p>
<p>The downside of adopting this module is that all modules which interact with the
week-alternating functionality of <tt class="docutils literal">resource</tt> must be adapted to be compatible
with this module. At the time of writing (2024-07-29), the only Odoo module
which does this is <tt class="docutils literal">hr_holidays</tt>.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-1">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<p>This module is a template for building on top of. It _will_ need glue modules to
work with various other modules. Most notably, <tt class="docutils literal">hr_holidays</tt> will not work
without modification.</p>
<p>The existing base Odoo two-week calendar functionality is hidden rather than
disabled. This may or may not be desirable.</p>
<p>The module may need improvements for timezone handling; this is currently
untested. <tt class="docutils literal">_split_into_weeks</tt> splits weeks on the timezone of the datetime
objects passed to it instead of on the timezone of the calendar. The calculation
of the current week number uses <tt class="docutils literal">fields.Date.today()</tt> instead of the
environments or calendars timezone. Finally, child calendars may have a
different timezone compared to their parent, which is probably not a desired
feature.</p>
<p>This module assumes that a week always starts on a Monday. Upstream Odoo appears
to do the same, but this may not be desired by certain audiences.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20resource_multi_week_calendar%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SC</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://coopiteasy.be">Coop IT Easy SC</a>:<ul>
<li>Carmen Bianca BAKKER</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/carmenbianca"><img alt="carmenbianca" src="https://github.com/carmenbianca.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/16.0/resource_multi_week_calendar">OCA/hr</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import test_calendar

View file

@ -0,0 +1,298 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import datetime
from freezegun import freeze_time
from odoo.exceptions import ValidationError
from odoo.fields import Command
from odoo.tests.common import TransactionCase
class CalendarCase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.Calendar = cls.env["resource.calendar"]
cls.parent_calendar = cls.Calendar.create({"name": "Parent"})
cls._sequence = 0
def create_simple_child(self):
self._sequence += 1
return self.Calendar.create(
{
"name": "Child {}".format(self._sequence),
"parent_calendar_id": self.parent_calendar.id,
"week_sequence": self._sequence,
}
)
class TestCalendarConstraints(CalendarCase):
def test_cant_add_child_to_child(self):
one = self.Calendar.create(
{
"name": "One",
"parent_calendar_id": self.parent_calendar.id,
"week_sequence": 1,
}
)
with self.assertRaises(ValidationError):
self.Calendar.create(
{
"name": "Two",
"parent_calendar_id": one.id,
"week_sequence": 2,
}
)
def test_cant_add_parent_to_parent(self):
self.Calendar.create(
{
"name": "Child",
"parent_calendar_id": self.parent_calendar.id,
"week_sequence": 1,
}
)
with self.assertRaises(ValidationError):
self.Calendar.create(
{
"name": "Parent of parent",
"child_calendar_ids": self.parent_calendar.ids,
# This value is kind of arbitrary here.
"week_sequence": 2,
}
)
class TestCalendarIsMultiweek(CalendarCase):
def test_solo(self):
self.assertFalse(self.parent_calendar.is_multi_week)
def test_has_child_or_parent(self):
child = self.create_simple_child()
self.assertTrue(self.parent_calendar.is_multi_week)
self.assertTrue(child.is_multi_week)
class TestCalendarWeekNumber(CalendarCase):
def test_solo(self):
# Parents don't have a week number.
self.assertEqual(self.parent_calendar.week_number, 0)
def test_children(self):
# The parent's sequence should not matter.
self.parent_calendar.week_sequence = 100
one = self.Calendar.create(
{
"name": "One",
"parent_calendar_id": self.parent_calendar.id,
"week_sequence": 1,
}
)
two = self.Calendar.create(
{
"name": "Two",
"parent_calendar_id": self.parent_calendar.id,
# Arbitrarily big number.
"week_sequence": 30,
}
)
self.assertEqual(self.parent_calendar.week_number, 0)
self.assertEqual(one.week_number, 1)
self.assertEqual(two.week_number, 2)
# Change the order.
one.week_sequence = 31
self.assertEqual(one.week_number, 2)
self.assertEqual(two.week_number, 1)
class TestCalendarWeekEpoch(CalendarCase):
@freeze_time("1970-01-08")
def test_compute_current_week_no_family(self):
self.assertEqual(self.parent_calendar.current_week_number, 0)
self.assertEqual(
self.parent_calendar.current_multi_week_calendar_id, self.parent_calendar
)
# 1970-01-01 is a Thursday.
@freeze_time("1970-01-01")
def test_compute_current_week_solo(self):
child = self.create_simple_child()
self.assertEqual(child.current_week_number, 1)
self.assertEqual(child.current_multi_week_calendar_id, child)
# 1970-01-01 is a Thursday.
@freeze_time("1970-01-01")
def test_compute_current_week_same_day(self):
child_1 = self.create_simple_child()
child_2 = self.create_simple_child()
self.assertEqual(child_1.current_week_number, 1)
self.assertEqual(child_1.current_multi_week_calendar_id, child_1)
# Test against the others, too, which should have the same result.
self.assertEqual(self.parent_calendar.current_week_number, 1)
self.assertEqual(self.parent_calendar.current_multi_week_calendar_id, child_1)
self.assertEqual(child_2.current_week_number, 1)
self.assertEqual(child_2.current_multi_week_calendar_id, child_1)
# 1969-12-29 is a Monday.
@freeze_time("1969-12-29")
def test_compute_current_week_first_day_of_week(self):
child_1 = self.create_simple_child()
self.create_simple_child()
self.assertEqual(child_1.current_week_number, 1)
self.assertEqual(child_1.current_multi_week_calendar_id, child_1)
# 1969-12-28 is a Sunday.
@freeze_time("1969-12-28")
def test_compute_current_week_one_week_ago(self):
child_1 = self.create_simple_child()
child_2 = self.create_simple_child()
self.assertEqual(child_1.current_week_number, 2)
self.assertEqual(child_1.current_multi_week_calendar_id, child_2)
# 1970-01-04 is a Sunday.
@freeze_time("1970-01-04")
def test_compute_current_week_last_day_of_week(self):
child_1 = self.create_simple_child()
self.create_simple_child()
self.assertEqual(child_1.current_week_number, 1)
self.assertEqual(child_1.current_multi_week_calendar_id, child_1)
# 1970-01-05 is a Monday.
@freeze_time("1970-01-05")
def test_compute_current_week_next_week(self):
child_1 = self.create_simple_child()
child_2 = self.create_simple_child()
self.assertEqual(child_1.current_week_number, 2)
self.assertEqual(child_1.current_multi_week_calendar_id, child_2)
# 1970-01-12 is a Monday.
@freeze_time("1970-01-12")
def test_compute_current_week_in_two_weeks(self):
child_1 = self.create_simple_child()
self.create_simple_child()
self.assertEqual(child_1.current_week_number, 1)
self.assertEqual(child_1.current_multi_week_calendar_id, child_1)
# 1970-01-12 is a Monday.
@freeze_time("1970-01-12")
def test_compute_current_week_in_two_weeks_three_calendars(self):
self.create_simple_child()
self.create_simple_child()
child_3 = self.create_simple_child()
self.assertEqual(child_3.current_week_number, 3)
self.assertEqual(child_3.current_multi_week_calendar_id, child_3)
# 1970-01-04 is a Sunday.
@freeze_time("1970-01-04")
def test_compute_current_week_when_day_changes(self):
child_1 = self.create_simple_child()
child_2 = self.create_simple_child()
self.assertEqual(child_1.current_week_number, 1)
self.assertEqual(child_1.current_multi_week_calendar_id, child_1)
with freeze_time("1970-01-05"):
# This re-compute shouldn't technically be needed... Maybe there's a
# cache?
child_1._compute_current_week()
self.assertEqual(child_1.current_week_number, 2)
self.assertEqual(child_1.current_multi_week_calendar_id, child_2)
# 2024-07-01 is a Monday.
@freeze_time("2024-07-01")
def test_compute_current_week_non_unix(self):
child_1 = self.create_simple_child()
self.create_simple_child()
self.parent_calendar.multi_week_epoch_date = "2024-07-08"
self.assertEqual(child_1.current_week_number, 2)
class TestMultiCalendar(CalendarCase):
def setUp(self):
super().setUpClass()
# The child_1 calendar has attendances by default: Every weekday from 8
# to 12, and 13 to 17.
self.child_1 = self.create_simple_child()
self.child_2 = self.create_simple_child()
# In the child calendar, only work the mornings.
self.child_2.attendance_ids = False
self.child_2.attendance_ids = [
Command.create(
{
"name": "Monday Morning",
"dayofweek": "0",
"hour_from": 8,
"hour_to": 12,
"day_period": "morning",
}
),
Command.create(
{
"name": "Tuesday Morning",
"dayofweek": "1",
"hour_from": 8,
"hour_to": 12,
"day_period": "morning",
}
),
Command.create(
{
"name": "Wednesday Morning",
"dayofweek": "2",
"hour_from": 8,
"hour_to": 12,
"day_period": "morning",
}
),
Command.create(
{
"name": "Thursday Morning",
"dayofweek": "3",
"hour_from": 8,
"hour_to": 12,
"day_period": "morning",
}
),
Command.create(
{
"name": "Friday Morning",
"dayofweek": "4",
"hour_from": 8,
"hour_to": 12,
"day_period": "morning",
}
),
]
def test_count_work_hours_two_weeks(self):
hours = self.parent_calendar.get_work_hours_count(
# 1st of July is a Monday.
datetime.datetime.fromisoformat("2024-07-01T00:00:00+00:00"),
datetime.datetime.fromisoformat("2024-07-14T23:59:59+00:00"),
)
# 40 from the parent, 20 from the child
self.assertEqual(hours, 60)
def test_count_work_hours_from_child(self):
# It doesn't matter whether you call the method from the child.
hours = self.child_2.get_work_hours_count(
datetime.datetime.fromisoformat("2024-07-01T00:00:00+00:00"),
datetime.datetime.fromisoformat("2024-07-14T23:59:59+00:00"),
)
self.assertEqual(hours, 60)
def test_count_work_hours_weeks_separately(self):
self.parent_calendar.multi_week_epoch_date = "2024-07-01"
hours = self.parent_calendar.get_work_hours_count(
datetime.datetime.fromisoformat("2024-07-01T00:00:00+00:00"),
datetime.datetime.fromisoformat("2024-07-07T23:59:59+00:00"),
)
self.assertEqual(hours, 40)
hours = self.parent_calendar.get_work_hours_count(
datetime.datetime.fromisoformat("2024-07-08T00:00:00+00:00"),
datetime.datetime.fromisoformat("2024-07-14T23:59:59+00:00"),
)
self.assertEqual(hours, 20)

View file

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="resource_calendar_form" model="ir.ui.view">
<field name="name">resource.calendar.form</field>
<field name="model">resource.calendar</field>
<field name="inherit_id" ref="resource.resource_calendar_form" />
<field name="arch" type="xml">
<button name="switch_calendar_type" position="attributes">
<attribute name="attrs" />
<attribute name="invisible">1</attribute>
</button>
<field name="hours_per_day" position="attributes">
<attribute
name="attrs"
>{'invisible': [('child_calendar_ids', '!=', [])]}</attribute>
</field>
<group name="resource_details" position="inside">
<group name="multi_week">
<!-- TODO: Should this be readonly? If it is, you cannot add
duplicated records to an existing relation. -->
<field
name="parent_calendar_id"
attrs="{'invisible': [('parent_calendar_id', '=', False)]}"
readonly="1"
/>
<field
name="child_calendar_ids"
attrs="{'invisible': [('parent_calendar_id', '!=', False)]}"
>
<tree>
<field name="week_sequence" widget="handle" />
<field name="name" />
</tree>
</field>
</group>
<field name="is_multi_week" invisible="1" />
<group
name="multi_week_current"
attrs="{'invisible': [('is_multi_week', '=', False)]}"
>
<field
name="multi_week_epoch_date"
attrs="{'invisible': [('parent_calendar_id', '!=', False)]}"
/>
<field
name="week_number"
attrs="{'invisible': [('parent_calendar_id', '=', False)]}"
/>
<field name="current_week_number" />
<field name="current_multi_week_calendar_id" />
</group>
</group>
<xpath expr="//page[@name='working_hours']" position="attributes">
<attribute name="attrs">
{'invisible': [('child_calendar_ids', '!=', [])]}
</attribute>
</xpath>
</field>
</record>
<record id="view_resource_calendar_search" model="ir.ui.view">
<field name="name">resource.calendar.search</field>
<field name="model">resource.calendar</field>
<field name="inherit_id" ref="resource.view_resource_calendar_search" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='inactive']" position="before">
<filter
string="Only Main Working Times"
name="only_parent_calendars"
domain="[('parent_calendar_id', '=', False)]"
/>
</xpath>
</field>
</record>
<record id="resource.action_resource_calendar_form" model="ir.actions.act_window">
<field name="context">{'search_default_only_parent_calendars': 1}</field>
</record>
</odoo>