Skip to content

Commit 4c54e3f

Browse files
committed
[MIG] web_widget_remaining_days_exact_date: Migration to 18.0
1 parent 16ed186 commit 4c54e3f

25 files changed

+673
-102
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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
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 Trescloud - César León
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
{
55
"name": "Web Widget Remaining Days Exact Date",
66
"summary": "Allows displaying the exact date alongside the remaining days",
7-
"version": "16.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"development_status": "Alpha",
99
"website": "https://github.com/OCA/web",
10-
"author": "Tecnativa, Odoo Community Association (OCA)",
11-
"maintainers": ["CarlosRoca13"],
10+
"author": "Tecnativa, Trescloud, Odoo Community Association (OCA)",
11+
"maintainers": ["CarlosRoca13", "CILC98"],
1212
"license": "AGPL-3",
1313
"depends": ["web"],
14+
"data": [
15+
"security/disable_remaining_days_security.xml",
16+
"security/ir.model.access.csv",
17+
"views/disable_remaining_days_rule_views.xml",
18+
"views/res_config_settings_views.xml",
19+
"wizards/disable_remaining_days_rule_wizard_views.xml",
20+
],
1421
"assets": {
1522
"web.assets_backend": [
16-
"web_widget_remaining_days_exact_date/static/src/remaining_days"
17-
"/remaining_days.esm.js",
18-
],
23+
"web_widget_remaining_days_exact_date/static/src/**/*",
24+
]
1925
},
2026
}

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