From 776cadec0668904cb9b149efd8ca24adeaeed49f Mon Sep 17 00:00:00 2001 From: Andreu Orensanz Date: Tue, 12 May 2026 12:13:52 +0200 Subject: [PATCH] [ADD] web_calendar_workdays --- .../odoo/addons/web_calendar_workdays | 1 + setup/web_calendar_workdays/setup.py | 6 + web_calendar_workdays/README.rst | 138 +++++ web_calendar_workdays/__init__.py | 0 web_calendar_workdays/__manifest__.py | 26 + web_calendar_workdays/i18n/ca_ES.po | 30 ++ web_calendar_workdays/i18n/es.po | 30 ++ web_calendar_workdays/readme/CONTRIBUTORS.md | 2 + web_calendar_workdays/readme/DESCRIPTION.md | 4 + web_calendar_workdays/readme/ROADMAP.md | 1 + web_calendar_workdays/readme/USAGE.md | 40 ++ .../static/description/index.html | 485 ++++++++++++++++++ .../static/src/js/calendar_arch_parser.esm.js | 54 ++ .../src/js/calendar_common_renderer.esm.js | 68 +++ .../static/src/js/calendar_controller.esm.js | 42 ++ .../static/src/js/calendar_date_picker.esm.js | 28 + .../static/src/js/calendar_model.esm.js | 37 ++ .../static/src/js/calendar_renderer.esm.js | 11 + 18 files changed, 1003 insertions(+) create mode 120000 setup/web_calendar_workdays/odoo/addons/web_calendar_workdays create mode 100644 setup/web_calendar_workdays/setup.py create mode 100644 web_calendar_workdays/README.rst create mode 100644 web_calendar_workdays/__init__.py create mode 100644 web_calendar_workdays/__manifest__.py create mode 100644 web_calendar_workdays/i18n/ca_ES.po create mode 100644 web_calendar_workdays/i18n/es.po create mode 100644 web_calendar_workdays/readme/CONTRIBUTORS.md create mode 100644 web_calendar_workdays/readme/DESCRIPTION.md create mode 100644 web_calendar_workdays/readme/ROADMAP.md create mode 100644 web_calendar_workdays/readme/USAGE.md create mode 100644 web_calendar_workdays/static/description/index.html create mode 100644 web_calendar_workdays/static/src/js/calendar_arch_parser.esm.js create mode 100644 web_calendar_workdays/static/src/js/calendar_common_renderer.esm.js create mode 100644 web_calendar_workdays/static/src/js/calendar_controller.esm.js create mode 100644 web_calendar_workdays/static/src/js/calendar_date_picker.esm.js create mode 100644 web_calendar_workdays/static/src/js/calendar_model.esm.js create mode 100644 web_calendar_workdays/static/src/js/calendar_renderer.esm.js diff --git a/setup/web_calendar_workdays/odoo/addons/web_calendar_workdays b/setup/web_calendar_workdays/odoo/addons/web_calendar_workdays new file mode 120000 index 000000000000..f6eec062322c --- /dev/null +++ b/setup/web_calendar_workdays/odoo/addons/web_calendar_workdays @@ -0,0 +1 @@ +../../../../web_calendar_workdays \ No newline at end of file diff --git a/setup/web_calendar_workdays/setup.py b/setup/web_calendar_workdays/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_calendar_workdays/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_calendar_workdays/README.rst b/web_calendar_workdays/README.rst new file mode 100644 index 000000000000..e4775f885170 --- /dev/null +++ b/web_calendar_workdays/README.rst @@ -0,0 +1,138 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +Calendar workdays views +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:218877aea2b13eca6b073a3d8c53cfc6ab953946cb2e8eed0fa9afc5ea7044aa + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/16.0/web_calendar_workdays + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_calendar_workdays + :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/web&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds two opt-in calendar scales to the Odoo backend calendar +view: + +- **Work Week**: same as the standard week view, but hides weekend. +- **Work Month**: same as the standard month view, but hides weekends. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The new ``work_week`` and ``work_month`` scales are **opt-in** per +calendar view. To enable them, list them explicitly in the ``scales`` +attribute of the ```` element: + +.. code:: xml + + + ... + + +Notes: + +- The standard scales (``day``, ``week``, ``month``, ``year``) are + still controlled the same way. List only the ones you want to expose + in the scale selector. +- You can use ``work_week`` or ``work_month`` as the default ``mode``. +- If the ``scales`` attribute is omitted, only the four standard scales + are available, preserving backward compatibility. + +To inherit an existing calendar view and add the new scales: + +.. code:: xml + + + my.model.calendar.workdays + my.model + + + + day,week,work_week,month,work_month,year + + + + +The view will then show two additional entries (``Work Week`` and +``Work Month``) in the scale dropdown next to ``Day`` / ``Week`` / +``Month`` / ``Year``. + +Known issues / Roadmap +====================== + +Use employee working hours to determine weekends and not use Saturday +and Sunday as default weekend days. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__: + + - Andreu Orensanz + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_calendar_workdays/__init__.py b/web_calendar_workdays/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_calendar_workdays/__manifest__.py b/web_calendar_workdays/__manifest__.py new file mode 100644 index 000000000000..7ebe1242f58a --- /dev/null +++ b/web_calendar_workdays/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Calendar workdays views", + "summary": "Adds opt-in Work Week and Work Month calendar scales that hide " + "weekend days (Saturday and Sunday)", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Extra Tools", + "website": "https://github.com/OCA/web", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": ["web"], + "assets": { + "web.assets_backend": [ + "web_calendar_workdays/static/src/js/calendar_arch_parser.esm.js", + "web_calendar_workdays/static/src/js/calendar_renderer.esm.js", + "web_calendar_workdays/static/src/js/calendar_common_renderer.esm.js", + "web_calendar_workdays/static/src/js/calendar_controller.esm.js", + "web_calendar_workdays/static/src/js/calendar_model.esm.js", + "web_calendar_workdays/static/src/js/calendar_date_picker.esm.js", + ], + }, +} diff --git a/web_calendar_workdays/i18n/ca_ES.po b/web_calendar_workdays/i18n/ca_ES.po new file mode 100644 index 000000000000..1ca95d9fbdad --- /dev/null +++ b/web_calendar_workdays/i18n/ca_ES.po @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_calendar_workdays +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-05-12 10:04+0000\n" +"PO-Revision-Date: 2026-05-12 10:04+0000\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: web_calendar_workdays +#. odoo-javascript +#: code:addons/web_calendar_workdays/static/src/js/calendar_controller.esm.js:0 +#, python-format +msgid "Work Month" +msgstr "Mes laboral" + +#. module: web_calendar_workdays +#. odoo-javascript +#: code:addons/web_calendar_workdays/static/src/js/calendar_controller.esm.js:0 +#, python-format +msgid "Work Week" +msgstr "Setmana laboral" diff --git a/web_calendar_workdays/i18n/es.po b/web_calendar_workdays/i18n/es.po new file mode 100644 index 000000000000..9b9b676c696e --- /dev/null +++ b/web_calendar_workdays/i18n/es.po @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_calendar_workdays +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-05-12 10:04+0000\n" +"PO-Revision-Date: 2026-05-12 10:04+0000\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: web_calendar_workdays +#. odoo-javascript +#: code:addons/web_calendar_workdays/static/src/js/calendar_controller.esm.js:0 +#, python-format +msgid "Work Month" +msgstr "Mes laboral" + +#. module: web_calendar_workdays +#. odoo-javascript +#: code:addons/web_calendar_workdays/static/src/js/calendar_controller.esm.js:0 +#, python-format +msgid "Work Week" +msgstr "Semana laboral" diff --git a/web_calendar_workdays/readme/CONTRIBUTORS.md b/web_calendar_workdays/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..8143e28ebfc9 --- /dev/null +++ b/web_calendar_workdays/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com): + - Andreu Orensanz diff --git a/web_calendar_workdays/readme/DESCRIPTION.md b/web_calendar_workdays/readme/DESCRIPTION.md new file mode 100644 index 000000000000..8d82df6d8720 --- /dev/null +++ b/web_calendar_workdays/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module adds two opt-in calendar scales to the Odoo backend calendar view: + +- **Work Week**: same as the standard week view, but hides weekend. +- **Work Month**: same as the standard month view, but hides weekends. diff --git a/web_calendar_workdays/readme/ROADMAP.md b/web_calendar_workdays/readme/ROADMAP.md new file mode 100644 index 000000000000..560a985e8e8a --- /dev/null +++ b/web_calendar_workdays/readme/ROADMAP.md @@ -0,0 +1 @@ +Use employee working hours to determine weekends and not use Saturday and Sunday as default weekend days. diff --git a/web_calendar_workdays/readme/USAGE.md b/web_calendar_workdays/readme/USAGE.md new file mode 100644 index 000000000000..1ebc6be1a319 --- /dev/null +++ b/web_calendar_workdays/readme/USAGE.md @@ -0,0 +1,40 @@ +The new `work_week` and `work_month` scales are **opt-in** per calendar view. +To enable them, list them explicitly in the `scales` attribute of the +`` element: + +```xml + + ... + +``` + +Notes: + +- The standard scales (`day`, `week`, `month`, `year`) are still controlled the + same way. List only the ones you want to expose in the scale selector. +- You can use `work_week` or `work_month` as the default `mode`. +- If the `scales` attribute is omitted, only the four standard scales are + available, preserving backward compatibility. + +To inherit an existing calendar view and add the new scales: + +```xml + + my.model.calendar.workdays + my.model + + + + day,week,work_week,month,work_month,year + + + +``` + +The view will then show two additional entries (`Work Week` and `Work Month`) +in the scale dropdown next to `Day` / `Week` / `Month` / `Year`. diff --git a/web_calendar_workdays/static/description/index.html b/web_calendar_workdays/static/description/index.html new file mode 100644 index 000000000000..a13d85ade862 --- /dev/null +++ b/web_calendar_workdays/static/description/index.html @@ -0,0 +1,485 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Calendar workdays views

+ +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This module adds two opt-in calendar scales to the Odoo backend calendar +view:

+
    +
  • Work Week: same as the standard week view, but hides weekend.
  • +
  • Work Month: same as the standard month view, but hides weekends.
  • +
+

Table of contents

+ +
+

Usage

+

The new work_week and work_month scales are opt-in per +calendar view. To enable them, list them explicitly in the scales +attribute of the <calendar> element:

+
+<calendar
+    date_start="date_start"
+    date_stop="date_stop"
+    mode="work_week"
+    scales="day,week,work_week,month,work_month,year"
+>
+    ...
+</calendar>
+
+

Notes:

+
    +
  • The standard scales (day, week, month, year) are +still controlled the same way. List only the ones you want to expose +in the scale selector.
  • +
  • You can use work_week or work_month as the default mode.
  • +
  • If the scales attribute is omitted, only the four standard scales +are available, preserving backward compatibility.
  • +
+

To inherit an existing calendar view and add the new scales:

+
+<record id="my_calendar_view_workdays" model="ir.ui.view">
+    <field name="name">my.model.calendar.workdays</field>
+    <field name="model">my.model</field>
+    <field name="inherit_id" ref="other_module.my_calendar_view"/>
+    <field name="arch" type="xml">
+        <xpath expr="//calendar" position="attributes">
+            <attribute name="scales">day,week,work_week,month,work_month,year</attribute>
+        </xpath>
+    </field>
+</record>
+
+

The view will then show two additional entries (Work Week and +Work Month) in the scale dropdown next to Day / Week / +Month / Year.

+
+
+

Known issues / Roadmap

+

Use employee working hours to determine weekends and not use Saturday +and Sunday as default weekend days.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/web_calendar_workdays/static/src/js/calendar_arch_parser.esm.js b/web_calendar_workdays/static/src/js/calendar_arch_parser.esm.js new file mode 100644 index 000000000000..1bf668529c0a --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_arch_parser.esm.js @@ -0,0 +1,54 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarArchParser} from "@web/views/calendar/calendar_arch_parser"; +import {patch} from "@web/core/utils/patch"; + +export const WORKDAYS_SCALES = ["work_week", "work_month"]; +const WORK_SCALE_TO_BASE = { + work_week: "week", + work_month: "month", +}; + +patch(CalendarArchParser.prototype, "web_calendar_workdays.CalendarArchParser", { + parse(arch, models, modelName) { + const doc = new DOMParser().parseFromString(arch, "text/xml"); + const node = doc.querySelector("calendar"); + let archForSuper = arch; + let requestedMode = null; + let requestedScales = null; + if (node) { + if ( + node.hasAttribute("mode") && + WORKDAYS_SCALES.includes(node.getAttribute("mode")) + ) { + requestedMode = node.getAttribute("mode"); + node.setAttribute("mode", WORK_SCALE_TO_BASE[requestedMode]); + } + if (node.hasAttribute("scales")) { + requestedScales = node + .getAttribute("scales") + .split(",") + .map((s) => s.trim()) + .filter(Boolean); + } + if (requestedMode !== null) { + archForSuper = new XMLSerializer().serializeToString(doc); + } + } + const result = this._super(archForSuper, models, modelName); + if (requestedScales) { + const parentScales = new Set(result.scales); + // Preserve the order requested in the arch, keeping only scales + // either accepted by the parent or contributed by this module. + result.scales = requestedScales.filter( + (s) => parentScales.has(s) || WORKDAYS_SCALES.includes(s) + ); + } + if (requestedMode && result.scales.includes(requestedMode)) { + result.scale = requestedMode; + } + return result; + }, +}); diff --git a/web_calendar_workdays/static/src/js/calendar_common_renderer.esm.js b/web_calendar_workdays/static/src/js/calendar_common_renderer.esm.js new file mode 100644 index 000000000000..fa0fdf63d008 --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_common_renderer.esm.js @@ -0,0 +1,68 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarCommonRenderer} from "@web/views/calendar/calendar_common/calendar_common_renderer"; +import {patch} from "@web/core/utils/patch"; + +// FullCalendar weekday numbering: 0 = Sunday, 6 = Saturday. +const WEEKEND_DAYS = [0, 6]; + +const WORK_SCALE_TO_FC_VIEW = { + work_week: "timeGridWeek", + work_month: "dayGridMonth", +}; + +const WORK_SCALE_TO_HEADER_FORMAT = { + work_week: "EEE d", + work_month: "EEEE", +}; + +const SHORT_WORK_SCALE_TO_HEADER_FORMAT = { + work_week: "EEE d", + work_month: "EEE", +}; + +const WORK_SCALE_TO_BASE = { + work_week: "week", + work_month: "month", +}; + +function withBaseScale(model, callback) { + const scale = model.meta.scale; + const baseScale = WORK_SCALE_TO_BASE[scale]; + if (!baseScale) { + return callback(); + } + model.meta.scale = baseScale; + try { + return callback(); + } finally { + model.meta.scale = scale; + } +} + +patch( + CalendarCommonRenderer.prototype, + "web_calendar_workdays.CalendarCommonRenderer", + { + get options() { + const options = this._super(...arguments); + const scale = this.props.model.scale; + if (WORK_SCALE_TO_FC_VIEW[scale]) { + options.defaultView = WORK_SCALE_TO_FC_VIEW[scale]; + options.columnHeaderFormat = this.env.isSmall + ? SHORT_WORK_SCALE_TO_HEADER_FORMAT[scale] + : WORK_SCALE_TO_HEADER_FORMAT[scale]; + options.hiddenDays = WEEKEND_DAYS; + } + return options; + }, + convertRecordToEvent(record) { + return withBaseScale(this.props.model, () => this._super(record)); + }, + fcEventToRecord(event) { + return withBaseScale(this.props.model, () => this._super(event)); + }, + } +); diff --git a/web_calendar_workdays/static/src/js/calendar_controller.esm.js b/web_calendar_workdays/static/src/js/calendar_controller.esm.js new file mode 100644 index 000000000000..a9a37bdbe6e2 --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_controller.esm.js @@ -0,0 +1,42 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarController} from "@web/views/calendar/calendar_controller"; +import {_lt} from "@web/core/l10n/translation"; +import {patch} from "@web/core/utils/patch"; + +const WORK_SCALE_LABELS = { + work_week: _lt("Work Week"), + work_month: _lt("Work Month"), +}; + +const WORK_SCALE_TO_BASE = { + work_week: "week", + work_month: "month", +}; + +patch(CalendarController.prototype, "web_calendar_workdays.CalendarController", { + get scaleLabels() { + return { + ...this._super(...arguments), + ...WORK_SCALE_LABELS, + }; + }, + async setDate(move) { + const scale = this.model.scale; + const baseScale = WORK_SCALE_TO_BASE[scale]; + if (!baseScale || move === "today") { + return this._super(move); + } + let date = null; + if (move === "next") { + date = this.model.date.plus({[`${baseScale}s`]: 1}); + } else if (move === "previous") { + date = this.model.date.minus({[`${baseScale}s`]: 1}); + } + if (date) { + await this.model.load({date}); + } + }, +}); diff --git a/web_calendar_workdays/static/src/js/calendar_date_picker.esm.js b/web_calendar_workdays/static/src/js/calendar_date_picker.esm.js new file mode 100644 index 000000000000..71eea91684b4 --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_date_picker.esm.js @@ -0,0 +1,28 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarDatePicker} from "@web/views/calendar/date_picker/calendar_date_picker"; +import {patch} from "@web/core/utils/patch"; + +const WORK_SCALE_TO_BASE = { + work_week: "week", + work_month: "month", +}; + +patch(CalendarDatePicker.prototype, "web_calendar_workdays.CalendarDatePicker", { + highlight() { + const model = this.props.model; + const scale = model.meta.scale; + const baseScale = WORK_SCALE_TO_BASE[scale]; + if (!baseScale) { + return this._super(...arguments); + } + model.meta.scale = baseScale; + try { + return this._super(...arguments); + } finally { + model.meta.scale = scale; + } + }, +}); diff --git a/web_calendar_workdays/static/src/js/calendar_model.esm.js b/web_calendar_workdays/static/src/js/calendar_model.esm.js new file mode 100644 index 000000000000..6418484d83b2 --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_model.esm.js @@ -0,0 +1,37 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarModel} from "@web/views/calendar/calendar_model"; +import {patch} from "@web/core/utils/patch"; + +const WORK_SCALE_TO_BASE = { + work_week: "week", + work_month: "month", +}; + +function withBaseScale(model, callback) { + const scale = model.meta.scale; + const baseScale = WORK_SCALE_TO_BASE[scale]; + if (!baseScale) { + return callback(); + } + model.meta.scale = baseScale; + try { + return callback(); + } finally { + model.meta.scale = scale; + } +} + +patch(CalendarModel.prototype, "web_calendar_workdays.CalendarModel", { + computeRange() { + return withBaseScale(this, () => this._super(...arguments)); + }, + buildRawRecord(partialRecord, options = {}) { + return withBaseScale(this, () => this._super(partialRecord, options)); + }, + makeContextDefaults(rawRecord) { + return withBaseScale(this, () => this._super(rawRecord)); + }, +}); diff --git a/web_calendar_workdays/static/src/js/calendar_renderer.esm.js b/web_calendar_workdays/static/src/js/calendar_renderer.esm.js new file mode 100644 index 000000000000..0f5a2a9fcedb --- /dev/null +++ b/web_calendar_workdays/static/src/js/calendar_renderer.esm.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ +/* Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +import {CalendarCommonRenderer} from "@web/views/calendar/calendar_common/calendar_common_renderer"; +import {CalendarRenderer} from "@web/views/calendar/calendar_renderer"; + +Object.assign(CalendarRenderer.components, { + work_week: CalendarCommonRenderer, + work_month: CalendarCommonRenderer, +});