-
-
Notifications
You must be signed in to change notification settings - Fork 220
[18.0][ADD] maintenance_request_done_readonly #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smorita7749
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
qrtl:18.0-add-maintenance-request-done-readonly
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| ================================== | ||
| 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 or | ||
| reopened: any attempt to change its fields (including moving it back out | ||
| of the done stage) 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, 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. | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # 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", | ||
| "depends": ["maintenance"], | ||
| "data": [ | ||
| "security/res_groups.xml", | ||
| "data/ir_config_parameter.xml", | ||
| ], | ||
| "installable": True, | ||
| } |
7 changes: 7 additions & 0 deletions
7
maintenance_request_done_readonly/data/ir_config_parameter.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import maintenance_request |
54 changes: 54 additions & 0 deletions
54
maintenance_request_done_readonly/models/maintenance_request.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import _, 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 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.env.user.has_group( | ||
| "maintenance_request_done_readonly." | ||
| "group_maintenance_request_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, | ||
| ) | ||
| ) | ||
| # 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - [Quartile](https://www.quartile.co): | ||
| - Shinnosuke Morita |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| This module makes completed maintenance requests read-only. | ||
|
|
||
| Once a request reaches a done stage, it can no longer be edited or reopened: | ||
| any attempt to change its fields (including moving it back out of the done | ||
| stage) 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, 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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="[(4, 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="[(4, ref('group_maintenance_request_edit_done'))]" | ||
| /> | ||
| </record> | ||
| </odoo> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.