Skip to content

Commit 96e6c4e

Browse files
committed
[IMP] Improvement to the web_widget_remaining_days_exact_date module
1 parent b28acbd commit 96e6c4e

25 files changed

+662
-94
lines changed

web_widget_remaining_days_exact_date/README.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
====================================
26
Web Widget Remaining Days Exact Date
37
====================================
@@ -7,29 +11,29 @@ Web Widget Remaining Days Exact Date
711
!! This file is generated by oca-gen-addon-readme !!
812
!! changes will be overwritten. !!
913
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:a84ad30ebfaa64e7c8874579509890ef6e9fecfeac8202b233ddfc57b2dde5ca
14+
!! source digest: sha256:04e1fccbb2fb34f3070c1a479bc49f65e0887e6e898f9b7da33911a3e1c85669
1115
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1216
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Alpha
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
20-
:target: https://github.com/OCA/web/tree/18.0/web_widget_remaining_days_exact_date
24+
:target: https://github.com/OCA/web/tree/TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date/web_widget_remaining_days_exact_date
2125
:alt: OCA/web
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_remaining_days_exact_date
27+
: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
2428
:alt: Translate me on Weblate
2529
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=TRESCLOUD:18.0-mig-web_widget_remaining_days_exact_date
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
3034

3135
This module allows displaying the exact date alongside the remaining
32-
days.
36+
days. You can also control it by model, view, or specific field.
3337

3438
.. IMPORTANT::
3539
This is an alpha version, the data model and design can change at any time without warning.
@@ -60,7 +64,7 @@ Bug Tracker
6064
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
6165
In case of trouble, please check there if your issue has already been reported.
6266
If you spotted it first, help us to smash it by providing a detailed and welcomed
63-
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_remaining_days_exact_date%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
67+
`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**>`_.
6468

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

@@ -71,6 +75,7 @@ Authors
7175
-------
7276

7377
* Tecnativa
78+
* Trescloud
7479

7580
Contributors
7681
------------
@@ -80,6 +85,10 @@ Contributors
8085
- Pedro M. Baeza
8186
- Carlos Roca
8287

88+
- `Trescloud <https://www.trescloud.com>`__
89+
90+
- César León
91+
8392
Maintainers
8493
-----------
8594

@@ -96,11 +105,14 @@ promote its widespread use.
96105
.. |maintainer-CarlosRoca13| image:: https://github.com/CarlosRoca13.png?size=40px
97106
:target: https://github.com/CarlosRoca13
98107
:alt: CarlosRoca13
108+
.. |maintainer-CILC98| image:: https://github.com/CILC98.png?size=40px
109+
:target: https://github.com/CILC98
110+
:alt: CILC98
99111

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

102-
|maintainer-CarlosRoca13|
114+
|maintainer-CarlosRoca13| |maintainer-CILC98|
103115

104-
This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_widget_remaining_days_exact_date>`_ project on GitHub.
116+
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.
105117

106118
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import wizards
2+
from . import models
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
# Copyright 2024 Tecnativa - Carlos Roca
2-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
1+
# Copyright 2025 Tecnativa - Carlos Roca
2+
# Copyright 2025 Trescloud - César León
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34

45
{
56
"name": "Web Widget Remaining Days Exact Date",
67
"summary": "Allows displaying the exact date alongside the remaining days",
78
"version": "18.0.1.0.0",
89
"development_status": "Alpha",
910
"website": "https://github.com/OCA/web",
10-
"author": "Tecnativa, Odoo Community Association (OCA)",
11-
"maintainers": ["CarlosRoca13"],
11+
"author": "Tecnativa, Trescloud, Odoo Community Association (OCA)",
12+
"maintainers": ["CarlosRoca13", "CILC98"],
1213
"license": "AGPL-3",
1314
"depends": ["web"],
15+
"data": [
16+
"security/disable_remaining_days_security.xml",
17+
"security/ir.model.access.csv",
18+
"views/disable_remaining_days_rule_views.xml",
19+
"views/res_config_settings_views.xml",
20+
"wizards/disable_remaining_days_rule_wizard_views.xml",
21+
],
1422
"assets": {
1523
"web.assets_backend": [
1624
"web_widget_remaining_days_exact_date/static/src/**/*",
17-
],
25+
]
1826
},
1927
}

web_widget_remaining_days_exact_date/i18n/it.po

Lines changed: 0 additions & 14 deletions
This file was deleted.

web_widget_remaining_days_exact_date/i18n/web_widget_remaining_days_exact_date.pot

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import disable_remaining_days_rule
2+
from . import res_company
3+
from . import res_config_settings
4+
from . import ir_http
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
import ast
2+
3+
from odoo import Command, _, api, fields, models
4+
5+
6+
class DisableRemainingDaysRule(models.Model):
7+
_name = "disable.remaining.days.rule"
8+
_description = "Disable Remaining Days Rule"
9+
10+
res_model_id = fields.Many2one(
11+
"ir.model",
12+
string="Model",
13+
required=True,
14+
ondelete="cascade",
15+
copy=False,
16+
help="Select the model where you want to disable the remaining days widget.",
17+
)
18+
res_model_name = fields.Char(
19+
related="res_model_id.model",
20+
string="Technical model name",
21+
store=True,
22+
)
23+
active = fields.Boolean(
24+
string="Active record",
25+
default=True
26+
)
27+
company_id = fields.Many2one(
28+
"res.company",
29+
required=True,
30+
default=lambda self: self.env.company,
31+
string="Company",
32+
)
33+
diseable_view_types = fields.Char(
34+
string="Disable View Types",
35+
compute="_compute_diseable_view_types",
36+
store=True,
37+
help="Name of the view types where the remaining days widget will be disabled.",
38+
)
39+
diseable_view_types_json = fields.Char(
40+
string="Disable View Types JSON",
41+
readonly=True,
42+
help="JSON representation of the view types where the remaining days"
43+
" widget will be disabled. {'list': List, 'form': Form}",
44+
)
45+
date_type_fields_ids = fields.Many2many(
46+
"ir.model.fields",
47+
string="Date/Datetime Fields",
48+
help="Select the date/datetime fields of the model where you want to disable"
49+
" the remaining days widget.",
50+
domain="[('model_id', '=', res_model_id),"
51+
" ('ttype', 'in', ['date', 'datetime'])]",
52+
copy=False,
53+
)
54+
55+
@api.depends("diseable_view_types_json")
56+
def _compute_diseable_view_types(self):
57+
"""
58+
Get Values of diseable_view_types_json
59+
"""
60+
for record in self:
61+
# Convert chart to json array
62+
diseable_view_types_json = ast.literal_eval(
63+
record.diseable_view_types_json or "{}"
64+
)
65+
# Get values of dict
66+
view_types = []
67+
for value in diseable_view_types_json.values():
68+
if value:
69+
view_types.append(value)
70+
record.diseable_view_types = ", ".join(view_types)
71+
72+
@api.constrains("res_model_id")
73+
def _constrains_res_model_id(self):
74+
"""Ensure that there is only one rule per model"""
75+
for record in self:
76+
domain = [
77+
("res_model_id", "=", record.res_model_id.id),
78+
("id", "!=", record.id),
79+
("company_id", "=", record.company_id.id),
80+
]
81+
if self.search_count(domain) > 0:
82+
raise models.ValidationError(
83+
self.env._(
84+
"There is already a rule for the model '%s'."
85+
" You cannot create two rules for the same model.",
86+
record.res_model_id.name,
87+
)
88+
)
89+
90+
@api.onchange("res_model_id")
91+
def _onchange_res_model_id(self):
92+
""" " On change of the model, reset the date field"""
93+
for record in self:
94+
record.date_type_fields_ids = False
95+
96+
def action_open_set_disable_remaining_days_rule_wizard(self):
97+
"""
98+
Open the wizard to set the disable remaining days rule
99+
"""
100+
self.ensure_one()
101+
model_id = self.res_model_id
102+
view_ids = model_id.view_ids
103+
if not view_ids:
104+
raise models.ValidationError(
105+
_(
106+
"The model '%s' does not have any views."
107+
" You cannot set the disable remaining days rule by view type"
108+
" for this model."
109+
)
110+
% model_id.name
111+
)
112+
IrUiView = self.env["ir.ui.view"]
113+
# Get selection from ir.ui.view.
114+
selection = IrUiView._fields["type"].selection
115+
view_types = []
116+
for technical_name, name in selection:
117+
selected = technical_name in ast.literal_eval(
118+
self.diseable_view_types_json or "{}"
119+
)
120+
view_types.append((name, technical_name, selected))
121+
wizard_id = (
122+
self.env["disable.remaining.days.rule.wizard"]
123+
.sudo()
124+
.create(
125+
{
126+
"disable_remaining_days_rule_id": self.id,
127+
"line_ids": [
128+
Command.create(
129+
{
130+
"name": name,
131+
"technical_name": technical_name,
132+
"selected": selected,
133+
},
134+
)
135+
for name, technical_name, selected in view_types
136+
],
137+
}
138+
)
139+
)
140+
# Return wizard created
141+
return {
142+
"type": "ir.actions.act_window",
143+
"view_mode": "form",
144+
"res_model": "disable.remaining.days.rule.wizard",
145+
"target": "new",
146+
"res_id": wizard_id.id,
147+
}
148+
149+
@api.model
150+
def get_all_rules(self):
151+
"""
152+
Get all rules like {'model_name': active}
153+
"""
154+
# Return one rule per model if some company has it active
155+
rules_ids = self.search([])
156+
if self.get_disable_all_models():
157+
# If all models are disabled, return True for all
158+
return True
159+
rules = {}
160+
for rule in rules_ids:
161+
view_types = rule.get_data_by_view_type()
162+
fields = rule.get_data_by_field()
163+
rules[rule.res_model_id.model] = {
164+
"model": rule.get_data_by_model()
165+
if not view_types and not fields
166+
else False,
167+
"view_types": view_types,
168+
"fields": fields,
169+
}
170+
return rules
171+
172+
def get_data_by_model(self):
173+
"""
174+
Get rule data for a specific model
175+
"""
176+
self.ensure_one()
177+
return self.active
178+
179+
def get_data_by_view_type(self):
180+
"""
181+
Get rule data for a specific model and view type
182+
"""
183+
self.ensure_one()
184+
diseable_view_types_json = ast.literal_eval(
185+
self.diseable_view_types_json or "{}"
186+
)
187+
key_list = list(diseable_view_types_json.keys())
188+
if not key_list:
189+
return []
190+
return key_list
191+
192+
def get_data_by_field(self):
193+
"""
194+
Get rule data for a specific model and field
195+
"""
196+
self.ensure_one()
197+
field_ids = self.date_type_fields_ids
198+
if not field_ids:
199+
return []
200+
return field_ids.mapped("name")
201+
202+
@api.model
203+
def get_disable_all_models(self):
204+
"""
205+
Get all models with the remaining days disabled
206+
:return: list of model names
207+
"""
208+
disable_remaining_days = self.env.company.disable_remaining_days
209+
if disable_remaining_days:
210+
return True
211+
return False
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo import models
4+
5+
6+
class IrHttp(models.AbstractModel):
7+
_inherit = "ir.http"
8+
9+
def session_info(self):
10+
res = super().session_info()
11+
res["disable_remaining_days_rule"] = self.env[
12+
"disable.remaining.days.rule"
13+
].get_all_rules()
14+
return res

0 commit comments

Comments
 (0)