diff --git a/web_widget_remaining_days_exact_date/README.rst b/web_widget_remaining_days_exact_date/README.rst new file mode 100644 index 000000000000..c50f4e0853c4 --- /dev/null +++ b/web_widget_remaining_days_exact_date/README.rst @@ -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 `_ + +**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 + + + +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 +------- + +* Tecnativa +* Trescloud + +Contributors +------------ + +- `Tecnativa `__ + + - Pedro M. Baeza + - Carlos Roca + +- `Trescloud `__ + + - 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 `__: + +|maintainer-CarlosRoca13| |maintainer-CILC98| + +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_widget_remaining_days_exact_date/__init__.py b/web_widget_remaining_days_exact_date/__init__.py new file mode 100644 index 000000000000..976591c996e1 --- /dev/null +++ b/web_widget_remaining_days_exact_date/__init__.py @@ -0,0 +1,2 @@ +from . import wizards +from . import models diff --git a/web_widget_remaining_days_exact_date/__manifest__.py b/web_widget_remaining_days_exact_date/__manifest__.py new file mode 100644 index 000000000000..1eb11d8f6518 --- /dev/null +++ b/web_widget_remaining_days_exact_date/__manifest__.py @@ -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/**/*", + ] + }, +} diff --git a/web_widget_remaining_days_exact_date/models/__init__.py b/web_widget_remaining_days_exact_date/models/__init__.py new file mode 100644 index 000000000000..012bd1ed454b --- /dev/null +++ b/web_widget_remaining_days_exact_date/models/__init__.py @@ -0,0 +1,4 @@ +from . import disable_remaining_days_rule +from . import res_company +from . import res_config_settings +from . import ir_http diff --git a/web_widget_remaining_days_exact_date/models/disable_remaining_days_rule.py b/web_widget_remaining_days_exact_date/models/disable_remaining_days_rule.py new file mode 100644 index 000000000000..281802e0486a --- /dev/null +++ b/web_widget_remaining_days_exact_date/models/disable_remaining_days_rule.py @@ -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 diff --git a/web_widget_remaining_days_exact_date/models/ir_http.py b/web_widget_remaining_days_exact_date/models/ir_http.py new file mode 100644 index 000000000000..7aba4d7c9690 --- /dev/null +++ b/web_widget_remaining_days_exact_date/models/ir_http.py @@ -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 diff --git a/web_widget_remaining_days_exact_date/models/res_company.py b/web_widget_remaining_days_exact_date/models/res_company.py new file mode 100644 index 000000000000..7c329a74e7ee --- /dev/null +++ b/web_widget_remaining_days_exact_date/models/res_company.py @@ -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.", + ) diff --git a/web_widget_remaining_days_exact_date/models/res_config_settings.py b/web_widget_remaining_days_exact_date/models/res_config_settings.py new file mode 100644 index 000000000000..6c75b774db71 --- /dev/null +++ b/web_widget_remaining_days_exact_date/models/res_config_settings.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + disable_remaining_days = fields.Boolean( + related="company_id.disable_remaining_days", + string="Disable Remaining Days", + help="If active, the remaining days widget will be disabled for all models.", + readonly=False, + groups="base.group_system", + ) diff --git a/web_widget_remaining_days_exact_date/pyproject.toml b/web_widget_remaining_days_exact_date/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_widget_remaining_days_exact_date/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_widget_remaining_days_exact_date/readme/CONTRIBUTORS.md b/web_widget_remaining_days_exact_date/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..cff22a7dd902 --- /dev/null +++ b/web_widget_remaining_days_exact_date/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://www.tecnativa.com) + - Pedro M. Baeza + - Carlos Roca +- [Trescloud](https://www.trescloud.com) + - César León \ No newline at end of file diff --git a/web_widget_remaining_days_exact_date/readme/DESCRIPTION.md b/web_widget_remaining_days_exact_date/readme/DESCRIPTION.md new file mode 100644 index 000000000000..836f7c1fccba --- /dev/null +++ b/web_widget_remaining_days_exact_date/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows displaying the exact date alongside the remaining +days. +You can also control it by model, view, or specific field. \ No newline at end of file diff --git a/web_widget_remaining_days_exact_date/readme/USAGE.md b/web_widget_remaining_days_exact_date/readme/USAGE.md new file mode 100644 index 000000000000..41eeb01c5853 --- /dev/null +++ b/web_widget_remaining_days_exact_date/readme/USAGE.md @@ -0,0 +1,9 @@ +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** + +``` xml + +``` diff --git a/web_widget_remaining_days_exact_date/security/disable_remaining_days_security.xml b/web_widget_remaining_days_exact_date/security/disable_remaining_days_security.xml new file mode 100644 index 000000000000..ebd36c2e0471 --- /dev/null +++ b/web_widget_remaining_days_exact_date/security/disable_remaining_days_security.xml @@ -0,0 +1,8 @@ + + + + Disable Remaining Days Rule + + [('company_id', 'in', company_ids)] + + diff --git a/web_widget_remaining_days_exact_date/security/ir.model.access.csv b/web_widget_remaining_days_exact_date/security/ir.model.access.csv new file mode 100644 index 000000000000..5da86ca53abb --- /dev/null +++ b/web_widget_remaining_days_exact_date/security/ir.model.access.csv @@ -0,0 +1,5 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_disable_remaining_days_rule_user","access_disable_remaining_days_rule_user","model_disable_remaining_days_rule","base.group_user",1,0,0,0 +"access_disable_remaining_days_rule_manager","access_disable_remaining_days_rule_manager","model_disable_remaining_days_rule","base.group_system",1,1,1,1 +"access_disable_remaining_days_rule_wizard_manager","access_disable_remaining_days_rule_wizard_manager","model_disable_remaining_days_rule_wizard","base.group_system",1,1,1,1 +"access_disable_remaining_days_rule_line_wizard_manager","access_disable_remaining_days_rule_line_wizard_manager","model_disable_remaining_days_rule_line_wizard","base.group_system",1,1,0,0 diff --git a/web_widget_remaining_days_exact_date/static/description/icon.png b/web_widget_remaining_days_exact_date/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/web_widget_remaining_days_exact_date/static/description/icon.png differ diff --git a/web_widget_remaining_days_exact_date/static/description/index.html b/web_widget_remaining_days_exact_date/static/description/index.html new file mode 100644 index 000000000000..cf85142003b9 --- /dev/null +++ b/web_widget_remaining_days_exact_date/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +Web Widget Remaining Days Exact Date + + + +
+ + + +Odoo Community Association + +
+

Web Widget Remaining Days Exact Date

+ +

Alpha License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

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

+
+

Table of contents

+ +
+

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

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

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

+
    +
  • Tecnativa
  • +
  • Trescloud
  • +
+
+
+

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.

+

Current maintainers:

+

CarlosRoca13 CILC98

+

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_widget_remaining_days_exact_date/static/src/widgets/remaining_days_fields.esm.js b/web_widget_remaining_days_exact_date/static/src/widgets/remaining_days_fields.esm.js new file mode 100644 index 000000000000..0daa44317aee --- /dev/null +++ b/web_widget_remaining_days_exact_date/static/src/widgets/remaining_days_fields.esm.js @@ -0,0 +1,47 @@ +import {RemainingDaysField} from "@web/views/fields/remaining_days/remaining_days_field"; +import {patch} from "@web/core/utils/patch"; +import {session} from "@web/session"; + +patch(RemainingDaysField.prototype, { + setup() { + super.setup(...arguments); + this.disable_remaining_days_rule = session.disable_remaining_days_rule; + }, + /** + * @override + */ + get diffString() { + /* Check if the remaining days field is disabled for the current model */ + const disable_rules = this.disable_remaining_days_rule; + + // If disable_rules is boolean true, disable for all models + if (disable_rules === true) { + return this.formattedValue; + } + // Check by models + if ( + disable_rules && // Check if the config variable exists + this.props.record.resModel in disable_rules && // Check if the model is in the disable_rules + typeof disable_rules[this.props.record.resModel].model === "boolean" && // Check if the value is a boolean + disable_rules[this.props.record.resModel].model === true // Check if the value is true + ) { + return this.formattedValue; + } + // Check by view types + if ( + disable_rules && // Check if the config variable exists + this.props.record.resModel in disable_rules && // Check if the model is in the disable_rules + typeof disable_rules[this.props.record.resModel].view_types === "object" && // Check if the value is an list + (disable_rules[this.props.record.resModel].view_types.includes( + this.env.config.viewType + ) || // Check if the view type is in the list + disable_rules[this.props.record.resModel].fields.includes( + this.props.name + )) // Check if the field is in the list + ) { + return this.formattedValue; + } + + return super.diffString; + }, +}); diff --git a/web_widget_remaining_days_exact_date/tests/__init__.py b/web_widget_remaining_days_exact_date/tests/__init__.py new file mode 100644 index 000000000000..6c9812dc2f73 --- /dev/null +++ b/web_widget_remaining_days_exact_date/tests/__init__.py @@ -0,0 +1 @@ +from . import test_main diff --git a/web_widget_remaining_days_exact_date/tests/test_main.py b/web_widget_remaining_days_exact_date/tests/test_main.py new file mode 100644 index 000000000000..eea789a7c291 --- /dev/null +++ b/web_widget_remaining_days_exact_date/tests/test_main.py @@ -0,0 +1,108 @@ +from odoo import exceptions +from odoo.tests import tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("post_install", "-at_install") +class TestWidgetRemainingDaysExactDate(BaseCommon): + def test_global_disable(self): + company_id = self.env.company + company_id.disable_remaining_days = True + response = self.env["disable.remaining.days.rule"].get_all_rules() + self.assertTrue(response) + company_id.disable_remaining_days = False + response = self.env["disable.remaining.days.rule"].get_all_rules() + self.assertFalse(response) + + def test_rule_per_model(self): + self.env.company.disable_remaining_days = False + model_name = "res.partner" + model = self.env["ir.model"].search([("model", "=", model_name)], limit=1) + self.env["disable.remaining.days.rule"].create( + { + "res_model_id": model.id, + "active": True, + } + ) + with self.assertRaises(exceptions.UserError) as e: + self.env["disable.remaining.days.rule"].create( + { + "res_model_id": model.id, + "active": True, + } + ) + # Check that creating another rule for the same model raises an error + self.assertIn("There is already a rule for the model", e.exception.args[0]) + # Check rules + # Expect: "{'res.partner': {'model': True, 'view_types': [], 'fields': []}}" + rules = self.env["disable.remaining.days.rule"].get_all_rules() + self.assertIn(model_name, rules) + self.assertTrue(rules[model_name]["model"]) + self.assertEqual(rules[model_name]["view_types"], []) + self.assertEqual(rules[model_name]["fields"], []) + + def test_rule_per_model_and_view_type(self): + self.env.company.disable_remaining_days = False + model_name = "res.partner" + model = self.env["ir.model"].search([("model", "=", model_name)], limit=1) + rule = self.env["disable.remaining.days.rule"].create( + { + "res_model_id": model.id, + "active": True, + } + ) + action = rule.action_open_set_disable_remaining_days_rule_wizard() + wizard = self.env["disable.remaining.days.rule.wizard"].browse(action["res_id"]) + # Activate 'form' and 'list' view types + for line in wizard.line_ids: + if line.technical_name in ["list", "form"]: + line.selected = True + wizard.action_define_remaining_days_rule_by_view_type() + # Check rules + # Expect: " + # { + # 'res.partner': { + # 'model': True, + # 'view_types': ['list', 'form'], + # 'fields': [] + # } + rules = self.env["disable.remaining.days.rule"].get_all_rules() + self.assertIn(model_name, rules) + self.assertFalse(rules[model_name]["model"]) + self.assertEqual(rules[model_name]["view_types"], ["list", "form"]) + self.assertEqual(rules[model_name]["fields"], []) + + def test_rule_per_model_and_fields(self): + self.env.company.disable_remaining_days = False + model_name = "ir.module.module" + model = self.env["ir.model"].search([("model", "=", model_name)], limit=1) + rule = self.env["disable.remaining.days.rule"].create( + { + "res_model_id": model.id, + "active": True, + } + ) + field_1 = self.env["ir.model.fields"].search( + [("model_id", "=", model.id), ("name", "=", "create_date")], limit=1 + ) + field_2 = self.env["ir.model.fields"].search( + [("model_id", "=", model.id), ("name", "=", "write_date")], limit=1 + ) + rule.date_type_fields_ids = [(6, 0, [field_1.id, field_2.id])] + # Check rules + # Expect: " + # { + # 'ir.module.module': { + # 'model': False, + # 'view_types': [], + # 'fields': ['create_date', 'write_date'] + # } + # }" + rules = self.env["disable.remaining.days.rule"].get_all_rules() + self.assertIn(model_name, rules) + self.assertFalse(rules[model_name]["model"]) + self.assertEqual(rules[model_name]["view_types"], []) + self.assertEqual( + sorted(rules[model_name]["fields"]), sorted(["create_date", "write_date"]) + ) diff --git a/web_widget_remaining_days_exact_date/views/disable_remaining_days_rule_views.xml b/web_widget_remaining_days_exact_date/views/disable_remaining_days_rule_views.xml new file mode 100644 index 000000000000..de33f2757c4b --- /dev/null +++ b/web_widget_remaining_days_exact_date/views/disable_remaining_days_rule_views.xml @@ -0,0 +1,43 @@ + + + + disable.remaining.days.rule.view.list + disable.remaining.days.rule + + + + + +