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
91 changes: 91 additions & 0 deletions base_week_day/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

====================
Base for Day of Week
====================

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

.. |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-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%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/14.0/base_week_day
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-14-0/server-ux-14-0-base_week_day
: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-ux&target_branch=14.0
:alt: Try me on Runboat

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

Simple technical module to get the Day of Week from records.
This module does nothing visible to the user on its own, but is used as base for other modules, like `sale_order_week_day`.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/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-ux/issues/new?body=module:%20base_week_day%0Aversion:%2014.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
~~~~~~~

* PyTech

Contributors
~~~~~~~~~~~~

* `PyTech <https://www.pytech.it>`_:

* Simone Rubino <simone.rubino@pytech.it>

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-SirPyTech| image:: https://github.com/SirPyTech.png?size=40px
:target: https://github.com/SirPyTech
:alt: SirPyTech

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-SirPyTech|

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/14.0/base_week_day>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions base_week_day/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
22 changes: 22 additions & 0 deletions base_week_day/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2026 Simone Rubino - PyTech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Base for Day of Week",
"summary": "Base module for Day of Week computation.",
"version": "14.0.1.0.0",
"author": "PyTech, Odoo Community Association (OCA)",
"maintainers": [
"SirPyTech",
],
"website": "https://github.com/OCA/server-ux",
"license": "AGPL-3",
"depends": [
"base",
],
"external_dependencies": {
"python": [
"openupgradelib",
],
},
}
53 changes: 53 additions & 0 deletions base_week_day/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2026 Simone Rubino - PyTech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade
from psycopg2.extensions import AsIs


def populate_date_order_week_day(
env,
module,
model_name,
dow_field_name,
date_field_name,
):
"""Populate the new field `model_name.dow_field_name`.

The computation is based on the week day of `model_name.date_field_name`.
Use SQL to avoid Memory/Timeout errors when there are a lot of records.

This is not used in this module but can be used in inheriting modules.
"""
model = env[model_name]

if not openupgrade.column_exists(env.cr, model._table, dow_field_name):
openupgrade.add_fields(
env,
[
(
dow_field_name,
model._name,
model._table,
"selection",
None,
module,
)
],
)

openupgrade.logged_query(
env.cr,
"""
UPDATE %(model_table)s so
SET
%(dow_field_name)s = (EXTRACT(ISODOW FROM %(date_field_name)s) - 1)::TEXT
WHERE
%(date_field_name)s IS NOT NULL
""",
{
"model_table": AsIs(model._table),
"dow_field_name": AsIs(dow_field_name),
"date_field_name": AsIs(date_field_name),
},
)
3 changes: 3 additions & 0 deletions base_week_day/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import mixin
23 changes: 23 additions & 0 deletions base_week_day/models/mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2026 Simone Rubino - PyTech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models

WEEKDAYS = [
("0", "Monday"),
("1", "Tuesday"),
("2", "Wednesday"),
("3", "Thursday"),
("4", "Friday"),
("5", "Saturday"),
("6", "Sunday"),
]
# Use for selection fields


class WeekDayMixin(models.AbstractModel):
_name = "base_week_day.mixin"
_description = "Day of Week computation"

def _get_week_day(self, value):
return str(value.weekday()) if value else None
3 changes: 3 additions & 0 deletions base_week_day/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `PyTech <https://www.pytech.it>`_:

* Simone Rubino <simone.rubino@pytech.it>
2 changes: 2 additions & 0 deletions base_week_day/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Simple technical module to get the Day of Week from records.
This module does nothing visible to the user on its own, but is used as base for other modules, like `sale_order_week_day`.
Loading
Loading