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
104 changes: 104 additions & 0 deletions maintenance_request_done_readonly/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
==================================
Maintenance Request Done Read-only
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:878934f590ae604ed42cdc4a74c23b91b357b91fe17730356a8e08983b8fa828
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fmaintenance-lightgray.png?logo=github
:target: https://github.com/OCA/maintenance/tree/18.0/maintenance_request_done_readonly
:alt: OCA/maintenance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/maintenance-18-0/maintenance-18-0-maintenance_request_done_readonly
: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/maintenance&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module makes completed maintenance requests read-only.

Once a request reaches a done stage, it can no longer be edited,
reopened or deleted: any attempt to change its fields (including moving
it back out of the done stage) or to delete it is blocked. Only members
of the *Maintenance: Edit Completed Requests* group keep full access to
completed requests. *Equipment Manager* users get that group by default,
so it can also be granted to users who should be able to correct
completed requests without being maintenance managers.

The restriction is enforced on write and unlink, so every field is
locked by default, without having to enumerate them. Completing a
request and its follow-up (commenting, following, scheduling activities)
keep working.

If some fields should stay editable after completion, edit the
``maintenance_request_done_readonly.editable_fields`` system parameter
(*Settings > Technical > Parameters > System Parameters*, created on
install) and set a comma-separated list of their technical names.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/maintenance/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/maintenance/issues/new?body=module:%20maintenance_request_done_readonly%0Aversion:%2018.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
-------

* Quartile

Contributors
------------

- `Quartile <https://www.quartile.co>`__:

- Shinnosuke Morita

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-smorita7749| image:: https://github.com/smorita7749.png?size=40px
:target: https://github.com/smorita7749
:alt: smorita7749

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-smorita7749|

This module is part of the `OCA/maintenance <https://github.com/OCA/maintenance/tree/18.0/maintenance_request_done_readonly>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions maintenance_request_done_readonly/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions maintenance_request_done_readonly/__manifest__.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add yourself as a maintainer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Maintenance Request Done Read-only",
"summary": "Restrict editing of completed maintenance requests to an allowed group",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/maintenance",
"maintainers": ["smorita7749"],
"depends": ["maintenance"],
"data": [
"security/res_groups.xml",
"data/ir_config_parameter.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="editable_fields_param" model="ir.config_parameter">
<field name="key">maintenance_request_done_readonly.editable_fields</field>
<field name="value" />
</record>
</odoo>
1 change: 1 addition & 0 deletions maintenance_request_done_readonly/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import maintenance_request
67 changes: 67 additions & 0 deletions maintenance_request_done_readonly/models/maintenance_request.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please check if we should add @api.ondelete method to block unlink operations on done requests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is necessary.
I changed to only the Maintenance: Edit Completed Requests group can delete done requests.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import UserError


class MaintenanceRequest(models.Model):
_inherit = "maintenance.request"

def _writable_fields_when_done(self):
"""Fields a user without the edit group may still write when completed.

``message_main_attachment_id`` is written by the chatter when a file is
attached, so it is always allowed to keep commenting with attachments
working. Extra fields come from the
``maintenance_request_done_readonly.editable_fields`` system parameter;
every other field is locked.
"""
names = (
self.env["ir.config_parameter"]
.sudo()
.get_param("maintenance_request_done_readonly.editable_fields", "")
)
return {"message_main_attachment_id"} | {
name.strip() for name in names.split(",") if name.strip()
}

def _can_edit_done(self):
return self.env.user.has_group(
"maintenance_request_done_readonly.group_maintenance_request_edit_done"
)

def write(self, vals):
# A completed (done) request can only be edited by users in the edit
# group. Checked pre-write, so everyone can still complete a request
# (move it to done).
if (
not self.env.context.get("mnt_done_bypass_lock")
and not self._can_edit_done()
and (set(vals) - self._writable_fields_when_done())
and (locked := self.filtered("done"))
):
raise UserError(
_(
"'%s' is completed and can only be edited by users in the "
"'Maintenance: Edit Completed Requests' group.",
locked[0].display_name,
)
Comment thread
smorita7749 marked this conversation as resolved.
)
# When completing a request, let the internal close_date write (done by
# core maintenance) bypass the lock above so completion isn't blocked.
stage_id = vals.get("stage_id")
if stage_id and self.env["maintenance.stage"].browse(stage_id).done:
self = self.with_context(mnt_done_bypass_lock=True)
return super().write(vals)

@api.ondelete(at_uninstall=False)
def _unlink_except_done(self):
if not self._can_edit_done() and (locked := self.filtered("done")):
raise UserError(
_(
"'%s' is completed and can only be deleted by users in the "
"'Maintenance: Edit Completed Requests' group.",
locked[0].display_name,
)
)
3 changes: 3 additions & 0 deletions maintenance_request_done_readonly/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions maintenance_request_done_readonly/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Quartile](https://www.quartile.co):
- Shinnosuke Morita
18 changes: 18 additions & 0 deletions maintenance_request_done_readonly/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This module makes completed maintenance requests read-only.

Once a request reaches a done stage, it can no longer be edited, reopened or
deleted: any attempt to change its fields (including moving it back out of the
done stage) or to delete it is blocked. Only members of the *Maintenance: Edit
Completed Requests* group keep full access to completed requests. *Equipment
Manager* users get that group by default, so it can also be granted to users
who should be able to correct completed requests without being maintenance
managers.

The restriction is enforced on write and unlink, so every field is locked by
default, without having to enumerate them. Completing a request and its
follow-up (commenting, following, scheduling activities) keep working.

If some fields should stay editable after completion, edit the
``maintenance_request_done_readonly.editable_fields`` system parameter
(*Settings > Technical > Parameters > System Parameters*, created on install)
and set a comma-separated list of their technical names.
18 changes: 18 additions & 0 deletions maintenance_request_done_readonly/security/res_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="group_maintenance_request_edit_done" model="res.groups">
<field name="name">Maintenance: Edit Completed Requests</field>
<field name="category_id" ref="base.module_category_usability" />
<field name="implied_ids" eval="[Command.link(ref('base.group_user'))]" />
<field
name="comment"
>The user will be able to edit completed maintenance requests.</field>
</record>
<!-- Equipment managers keep editing completed requests, as before. -->
<record id="maintenance.group_equipment_manager" model="res.groups">
<field
name="implied_ids"
eval="[Command.link(ref('group_maintenance_request_edit_done'))]"
/>
</record>
</odoo>
Loading
Loading