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
87 changes: 87 additions & 0 deletions base_force_record_noupdate/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/server-tools/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/server-tools/issues/new?body=module:%20base_force_record_noupdate%0Aversion:%2015.0%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
~~~~~~~

* Camtocamp

Contributors
~~~~~~~~~~~~

* Italo Lopes <italo.lopes@camptocamp.com>
* Silvio Gregorini <silvio.gregorini@camptocamp.com>

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 <https://github.com/OCA/server-tools/tree/15.0/base_force_record_noupdate>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
22 changes: 22 additions & 0 deletions base_force_record_noupdate/__init__.py
Original file line number Diff line number Diff line change
@@ -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})
16 changes: 16 additions & 0 deletions base_force_record_noupdate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
34 changes: 34 additions & 0 deletions base_force_record_noupdate/i18n/base_force_record_noupdate.pot
Original file line number Diff line number Diff line change
@@ -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 ""
2 changes: 2 additions & 0 deletions base_force_record_noupdate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_model
from . import ir_model_data
53 changes: 53 additions & 0 deletions base_force_record_noupdate/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 30 in base_force_record_noupdate/models/ir_model.py

View check run for this annotation

Codecov / codecov/patch

base_force_record_noupdate/models/ir_model.py#L28-L30

Added lines #L28 - L30 were not covered by tests

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")

Check warning on line 48 in base_force_record_noupdate/models/ir_model.py

View check run for this annotation

Codecov / codecov/patch

base_force_record_noupdate/models/ir_model.py#L48

Added line #L48 was not covered by tests
if true_to_false:
true_to_false.write({"force_noupdate": False})
false_to_true = self - true_to_false

Check warning on line 51 in base_force_record_noupdate/models/ir_model.py

View check run for this annotation

Codecov / codecov/patch

base_force_record_noupdate/models/ir_model.py#L50-L51

Added lines #L50 - L51 were not covered by tests
if false_to_true:
false_to_true.write({"force_noupdate": True})

Check warning on line 53 in base_force_record_noupdate/models/ir_model.py

View check run for this annotation

Codecov / codecov/patch

base_force_record_noupdate/models/ir_model.py#L53

Added line #L53 was not covered by tests
18 changes: 18 additions & 0 deletions base_force_record_noupdate/models/ir_model_data.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions base_force_record_noupdate/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Italo Lopes <italo.lopes@camptocamp.com>
* Silvio Gregorini <silvio.gregorini@camptocamp.com>
6 changes: 6 additions & 0 deletions base_force_record_noupdate/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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).
1 change: 1 addition & 0 deletions base_force_record_noupdate/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To use this module, you need to open the models' form view and check field "Force No-Update"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading