diff --git a/base_force_record_noupdate/README.rst b/base_force_record_noupdate/README.rst new file mode 100644 index 00000000000..8d22d29e78c --- /dev/null +++ b/base_force_record_noupdate/README.rst @@ -0,0 +1,87 @@ +====================== +Force Record No-update +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:da312318da6a5b90118144f6d5b265f86380b4c6d6c26eb129b5a534839bdc0e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/15.0/base_force_record_noupdate + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-base_force_record_noupdate + :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-tools&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a boolean field on models form view, allowing to force +``noupdate=True`` to data linked to those models. + +Upon setting the field to ``True`` on a given model, ``noupdate=True`` will be set upon +existing data linked to it. When creating new data linked to that model, they will +always have ``noupdate=True`` (unless the field is reset on the model itself). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to open the models' form view and check field "Force No-Update" + +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 +~~~~~~~ + +* Camtocamp + +Contributors +~~~~~~~~~~~~ + +* Italo Lopes +* Silvio Gregorini + +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. + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_force_record_noupdate/__init__.py b/base_force_record_noupdate/__init__.py new file mode 100644 index 00000000000..88bdfee2c65 --- /dev/null +++ b/base_force_record_noupdate/__init__.py @@ -0,0 +1,22 @@ +from . import models + + +def post_init_hook(cr, registry): + """Configure a list of models having ``force_noupdate`` set by default""" + from odoo import SUPERUSER_ID, api + + env = api.Environment(cr, SUPERUSER_ID, {}) + mods = env["ir.model"].sudo() + for model_name in [ + "res.lang", + "ir.rule", + "ir.model.access", + "res.groups", + "mail.template", + "res.users.role", # Don't care if the module providing this is installed + ]: + mod = env["ir.model"]._get(model_name) + if mod and mod.exists(): + mods |= mod + if mods: + mods.write({"force_noupdate": True}) diff --git a/base_force_record_noupdate/__manifest__.py b/base_force_record_noupdate/__manifest__.py new file mode 100644 index 00000000000..53c989a63e7 --- /dev/null +++ b/base_force_record_noupdate/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +{ + "name": "Force Record No-update", + "summary": "Manually force noupdate=True on models", + "author": "Camtocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/server-tools", + "category": "Hidden", + "version": "15.0.1.0.0", + "license": "AGPL-3", + "depends": ["base"], + "data": ["views/ir_model.xml"], + "installable": True, + "post_init_hook": "post_init_hook", +} diff --git a/base_force_record_noupdate/i18n/base_force_record_noupdate.pot b/base_force_record_noupdate/i18n/base_force_record_noupdate.pot new file mode 100644 index 00000000000..68525fb9e5b --- /dev/null +++ b/base_force_record_noupdate/i18n/base_force_record_noupdate.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_force_record_noupdate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_force_record_noupdate +#: model:ir.model.fields,field_description:base_force_record_noupdate.field_ir_model__force_noupdate +msgid "Force No-Update" +msgstr "" + +#. module: base_force_record_noupdate +#: model:ir.model,name:base_force_record_noupdate.model_ir_model_data +msgid "Model Data" +msgstr "" + +#. module: base_force_record_noupdate +#: model:ir.model,name:base_force_record_noupdate.model_ir_model +msgid "Models" +msgstr "" + +#. module: base_force_record_noupdate +#: model:ir.actions.server,name:base_force_record_noupdate.action_run_ir_action_todo +msgid "Toggle Force Noupdate" +msgstr "" diff --git a/base_force_record_noupdate/models/__init__.py b/base_force_record_noupdate/models/__init__.py new file mode 100644 index 00000000000..11b44d76dae --- /dev/null +++ b/base_force_record_noupdate/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_model +from . import ir_model_data diff --git a/base_force_record_noupdate/models/ir_model.py b/base_force_record_noupdate/models/ir_model.py new file mode 100644 index 00000000000..44dd1302b34 --- /dev/null +++ b/base_force_record_noupdate/models/ir_model.py @@ -0,0 +1,53 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import api, fields, models +from odoo.tools.cache import ormcache + + +class Model(models.Model): + _inherit = "ir.model" + + force_noupdate = fields.Boolean("Force No-Update") + + @api.model_create_multi + def create(self, vals_list): + mods = super().create(vals_list) + type(self)._get_noupdate_model_ids.clear_cache(self.browse()) + self._propagate_noupdate_to_model_data() + return mods + + def write(self, vals): + res = super().write(vals) + if "force_noupdate" in vals: + type(self)._get_noupdate_model_ids.clear_cache(self.browse()) + self._propagate_noupdate_to_model_data() + return res + + def unlink(self): + res = super().unlink() + type(self)._get_noupdate_model_ids.clear_cache(self.browse()) + return res + + def _get_noupdate_models(self): + return self.browse(self._get_noupdate_model_ids()) + + @ormcache() + def _get_noupdate_model_ids(self): + return self.search([("force_noupdate", "=", True)]).ids + + @api.model + def _propagate_noupdate_to_model_data(self): + noupdate = self._get_noupdate_models().mapped("model") + imd = self.env["ir.model.data"].sudo() + model_data = imd.search([("model", "in", noupdate), ("noupdate", "=", False)]) + if model_data: + model_data.write({"noupdate": True}) + + def toggle_force_noupdate(self): + true_to_false = self.filtered("force_noupdate") + if true_to_false: + true_to_false.write({"force_noupdate": False}) + false_to_true = self - true_to_false + if false_to_true: + false_to_true.write({"force_noupdate": True}) diff --git a/base_force_record_noupdate/models/ir_model_data.py b/base_force_record_noupdate/models/ir_model_data.py new file mode 100644 index 00000000000..cb18f166b32 --- /dev/null +++ b/base_force_record_noupdate/models/ir_model_data.py @@ -0,0 +1,18 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import api, models + + +class IrModelData(models.Model): + _inherit = "ir.model.data" + + @api.model_create_multi + def create(self, vals_list): + noupdate_models = self.env["ir.model"].sudo()._get_noupdate_models() + if noupdate_models: + noupdate_model_names = set(noupdate_models.mapped("model")) + for vals in vals_list: + if vals.get("model") in noupdate_model_names: + vals["noupdate"] = True + return super().create(vals_list) diff --git a/base_force_record_noupdate/readme/CONTRIBUTORS.rst b/base_force_record_noupdate/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..5a20d7cc198 --- /dev/null +++ b/base_force_record_noupdate/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Italo Lopes +* Silvio Gregorini diff --git a/base_force_record_noupdate/readme/DESCRIPTION.rst b/base_force_record_noupdate/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..8312bf94aab --- /dev/null +++ b/base_force_record_noupdate/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module adds a boolean field on models form view, allowing to force +``noupdate=True`` to data linked to those models. + +Upon setting the field to ``True`` on a given model, ``noupdate=True`` will be set upon +existing data linked to it. When creating new data linked to that model, they will +always have ``noupdate=True`` (unless the field is reset on the model itself). diff --git a/base_force_record_noupdate/readme/USAGE.rst b/base_force_record_noupdate/readme/USAGE.rst new file mode 100644 index 00000000000..ff19b776fc0 --- /dev/null +++ b/base_force_record_noupdate/readme/USAGE.rst @@ -0,0 +1 @@ +To use this module, you need to open the models' form view and check field "Force No-Update" diff --git a/base_force_record_noupdate/static/description/icon.png b/base_force_record_noupdate/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/base_force_record_noupdate/static/description/icon.png differ diff --git a/base_force_record_noupdate/static/description/index.html b/base_force_record_noupdate/static/description/index.html new file mode 100644 index 00000000000..026f89046b9 --- /dev/null +++ b/base_force_record_noupdate/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +Force Record No-update + + + +
+

Force Record No-update

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This module adds a boolean field on models form view, allowing to force +noupdate=True to data linked to those models.

+

Upon setting the field to True on a given model, noupdate=True will be set upon +existing data linked to it. When creating new data linked to that model, they will +always have noupdate=True (unless the field is reset on the model itself).

+

Table of contents

+ +
+

Usage

+

To use this module, you need to open the models’ form view and check field “Force No-Update”

+
+
+

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

+
    +
  • Camtocamp
  • +
+
+ +
+

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.

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_force_record_noupdate/tests/__init__.py b/base_force_record_noupdate/tests/__init__.py new file mode 100644 index 00000000000..106e3eed2d1 --- /dev/null +++ b/base_force_record_noupdate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_force_record_noupdate diff --git a/base_force_record_noupdate/tests/test_base_force_record_noupdate.py b/base_force_record_noupdate/tests/test_base_force_record_noupdate.py new file mode 100644 index 00000000000..aaba308b695 --- /dev/null +++ b/base_force_record_noupdate/tests/test_base_force_record_noupdate.py @@ -0,0 +1,75 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo.tests import TransactionCase + +MODULE = "base_force_record_noupdate" + + +class TestBaseForceRecordNoupdate(TransactionCase): + def test_00_test_model_create_noupdate_propagation(self): + # NB: we're only testing models created through UI, the feature is not + # supported yet for models created by the code itself + imd = self.env["ir.model.data"].create( + { + "module": MODULE, + "name": "test_ir_model_data_record", + "model": "x_my.model.test.00", + "noupdate": False, + } + ) + self.env["ir.model"].create( + { + "name": "My Model Test 00", + "state": "manual", + "model": "x_my.model.test.00", + "force_noupdate": True, + } + ) + self.assertTrue(imd.noupdate) + + def test_01_test_model_write_noupdate_propagation(self): + my_model = self.env["ir.model"].create( + { + "name": "My Model Test 01", + "state": "manual", + "model": "x_my.model.test.01", + "force_noupdate": False, + } + ) + imd = self.env["ir.model.data"].create( + { + "module": MODULE, + "name": "test_ir_model_data_record", + "model": "x_my.model.test.01", + "noupdate": False, + } + ) + my_model.force_noupdate = True + self.assertTrue(imd.noupdate) + + def test_02_test_model_data_create_noupdate(self): + self.env["ir.model"].create( + [ + { + "name": f"My Model Test 02.{n}", + "state": "manual", + "model": f"x_my.model.test.02.{n}", + "force_noupdate": force_noupdate, + } + for n, force_noupdate in [(1, True), (2, False)] + ] + ) + imd1, imd2 = self.env["ir.model.data"].create( + [ + { + "module": MODULE, + "name": f"test_ir_model_data_record_{n}", + "model": f"x_my.model.test.02.{n}", + "noupdate": False, + } + for n in (1, 2) + ] + ) + self.assertTrue(imd1.noupdate) + self.assertFalse(imd2.noupdate) diff --git a/base_force_record_noupdate/views/ir_model.xml b/base_force_record_noupdate/views/ir_model.xml new file mode 100644 index 00000000000..2540b0309eb --- /dev/null +++ b/base_force_record_noupdate/views/ir_model.xml @@ -0,0 +1,25 @@ + + + + + ir.model + + + + + + + + + + Toggle Force Noupdate + ir.actions.server + + code + +if records: + records.toggle_force_noupdate() + + + + diff --git a/setup/base_force_record_noupdate/odoo/addons/base_force_record_noupdate b/setup/base_force_record_noupdate/odoo/addons/base_force_record_noupdate new file mode 120000 index 00000000000..991c951d33e --- /dev/null +++ b/setup/base_force_record_noupdate/odoo/addons/base_force_record_noupdate @@ -0,0 +1 @@ +../../../../base_force_record_noupdate \ No newline at end of file diff --git a/setup/base_force_record_noupdate/setup.py b/setup/base_force_record_noupdate/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/base_force_record_noupdate/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)