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

====================================
Web Widget Remaining Days Exact Date
====================================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date/web_widget_remaining_days_exact_date
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-TRESCLOUD:18-0-mig-web_widget_remaining_days_exact_date/web-TRESCLOUD:18-0-mig-web_widget_remaining_days_exact_date-web_widget_remaining_days_exact_date
: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=TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date
:alt: Try me on Runboat

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

This module allows displaying the exact date alongside the remaining
days. You can also control it by model, view, or specific field.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

If in any case the exact date doesn't need to be displayed, we can
disable the functionality by adding options="{'exact_date': False}" to
the field that has the widget.

**Example**

.. code:: xml

<field name="date_deadline" widget="remaining_days" options="{'exact_date': False}"/>

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/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/web/issues/new?body=module:%20web_widget_remaining_days_exact_date%0Aversion:%20TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date%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
-------

* Tecnativa
* Trescloud

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

- `Tecnativa <https://www.tecnativa.com>`__

- Pedro M. Baeza
- Carlos Roca

- `Trescloud <https://www.trescloud.com>`__

- César León

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

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

|maintainer-CarlosRoca13| |maintainer-CILC98|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date/web_widget_remaining_days_exact_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions web_widget_remaining_days_exact_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import wizards
from . import models
27 changes: 27 additions & 0 deletions web_widget_remaining_days_exact_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2025 Tecnativa - Carlos Roca
# Copyright 2025 Trescloud - César León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Web Widget Remaining Days Exact Date",
"summary": "Allows displaying the exact date alongside the remaining days",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"website": "https://github.com/OCA/web",
"author": "Tecnativa, Trescloud, Odoo Community Association (OCA)",
"maintainers": ["CarlosRoca13", "CILC98"],
"license": "AGPL-3",
"depends": ["web"],
"data": [
"security/disable_remaining_days_security.xml",
"security/ir.model.access.csv",
"views/disable_remaining_days_rule_views.xml",
"views/res_config_settings_views.xml",
"wizards/disable_remaining_days_rule_wizard_views.xml",
],
"assets": {
"web.assets_backend": [
"web_widget_remaining_days_exact_date/static/src/**/*",
]
},
}
4 changes: 4 additions & 0 deletions web_widget_remaining_days_exact_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import disable_remaining_days_rule
from . import res_company
from . import res_config_settings
from . import ir_http
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import ast

from odoo import Command, _, api, fields, models


class DisableRemainingDaysRule(models.Model):
_name = "disable.remaining.days.rule"
_description = "Disable Remaining Days Rule"

res_model_id = fields.Many2one(
"ir.model",
string="Model",
required=True,
ondelete="cascade",
copy=False,
help="Select the model where you want to disable the remaining days widget.",
)
res_model_name = fields.Char(
related="res_model_id.model",
string="Technical model name",
store=True,
)
active = fields.Boolean(string="Active record", default=True)
company_id = fields.Many2one(
"res.company",
required=True,
default=lambda self: self.env.company,
string="Company",
)
diseable_view_types = fields.Char(
string="Disable View Types",
compute="_compute_diseable_view_types",
store=True,
help="Name of the view types where the remaining days widget will be disabled.",
)
diseable_view_types_json = fields.Char(
string="Disable View Types JSON",
readonly=True,
help="JSON representation of the view types where the remaining days"
" widget will be disabled. {'list': List, 'form': Form}",
)
date_type_fields_ids = fields.Many2many(
"ir.model.fields",
string="Date/Datetime Fields",
help="Select the date/datetime fields of the model where you want to disable"
" the remaining days widget.",
domain="[('model_id', '=', res_model_id),"
" ('ttype', 'in', ['date', 'datetime'])]",
copy=False,
)

@api.depends("diseable_view_types_json")
def _compute_diseable_view_types(self):
"""
Get Values of diseable_view_types_json
"""
for record in self:
# Convert chart to json array
diseable_view_types_json = ast.literal_eval(
record.diseable_view_types_json or "{}"
)
# Get values of dict
view_types = []
for value in diseable_view_types_json.values():
if value:
view_types.append(value)
record.diseable_view_types = ", ".join(view_types)

@api.constrains("res_model_id")
def _constrains_res_model_id(self):
"""Ensure that there is only one rule per model"""
for record in self:
domain = [
("res_model_id", "=", record.res_model_id.id),
("id", "!=", record.id),
("company_id", "=", record.company_id.id),
]
if self.search_count(domain) > 0:
raise models.ValidationError(
self.env._(
"There is already a rule for the model '%s'."
" You cannot create two rules for the same model.",
record.res_model_id.name,
)
)

@api.onchange("res_model_id")
def _onchange_res_model_id(self):
""" " On change of the model, reset the date field"""
for record in self:
record.date_type_fields_ids = False

def action_open_set_disable_remaining_days_rule_wizard(self):
"""
Open the wizard to set the disable remaining days rule
"""
self.ensure_one()
model_id = self.res_model_id
view_ids = model_id.view_ids
if not view_ids:
raise models.ValidationError(
_(
"The model '%s' does not have any views."
" You cannot set the disable remaining days rule by view type"
" for this model."
)
% model_id.name
)
IrUiView = self.env["ir.ui.view"]
# Get selection from ir.ui.view.
selection = IrUiView._fields["type"].selection
view_types = []
for technical_name, name in selection:
selected = technical_name in ast.literal_eval(
self.diseable_view_types_json or "{}"
)
view_types.append((name, technical_name, selected))
wizard_id = (
self.env["disable.remaining.days.rule.wizard"]
.sudo()
.create(
{
"disable_remaining_days_rule_id": self.id,
"line_ids": [
Command.create(
{
"name": name,
"technical_name": technical_name,
"selected": selected,
},
)
for name, technical_name, selected in view_types
],
}
)
)
# Return wizard created
return {
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "disable.remaining.days.rule.wizard",
"target": "new",
"res_id": wizard_id.id,
}

@api.model
def get_all_rules(self):
"""
Get all rules like {'model_name': active}
"""
# Return one rule per model if some company has it active
rules_ids = self.search([])
if self.get_disable_all_models():
# If all models are disabled, return True for all
return True
rules = {}
for rule in rules_ids:
view_types = rule.get_data_by_view_type()
fields = rule.get_data_by_field()
rules[rule.res_model_id.model] = {
"model": rule.get_data_by_model()
if not view_types and not fields
else False,
"view_types": view_types,
"fields": fields,
}
return rules

def get_data_by_model(self):
"""
Get rule data for a specific model
"""
self.ensure_one()
return self.active

def get_data_by_view_type(self):
"""
Get rule data for a specific model and view type
"""
self.ensure_one()
diseable_view_types_json = ast.literal_eval(
self.diseable_view_types_json or "{}"
)
key_list = list(diseable_view_types_json.keys())
if not key_list:
return []
return key_list

def get_data_by_field(self):
"""
Get rule data for a specific model and field
"""
self.ensure_one()
field_ids = self.date_type_fields_ids
if not field_ids:
return []
return field_ids.mapped("name")

@api.model
def get_disable_all_models(self):
"""
Get all models with the remaining days disabled
:return: list of model names
"""
disable_remaining_days = self.env.company.disable_remaining_days
if disable_remaining_days:
return True
return False
14 changes: 14 additions & 0 deletions web_widget_remaining_days_exact_date/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class IrHttp(models.AbstractModel):
_inherit = "ir.http"

def session_info(self):
res = super().session_info()
res["disable_remaining_days_rule"] = self.env[
"disable.remaining.days.rule"
].get_all_rules()
return res
13 changes: 13 additions & 0 deletions web_widget_remaining_days_exact_date/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

disable_remaining_days = fields.Boolean(
string="Disable Remaining Days Widget",
company_dependent=True,
default=True,
groups="base.group_system",
help="If active, the remaining days widget will be disabled for all models.",
)
Loading