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
10 changes: 5 additions & 5 deletions document_page_approval/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

======================
Document Page Approval
======================
Expand All @@ -17,7 +13,7 @@ Document Page Approval
.. |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/license-AGPL--3-blue.png
.. |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%2Fknowledge-lightgray.png?logo=github
Expand Down Expand Up @@ -106,6 +102,10 @@ Contributors

- Bhavesh Heliconia

- `NuoBiT Solutions SL <https://www.nuobit.com>`__:

- Deniz Gallo dgallo@nuobit.com

Maintainers
-----------

Expand Down
13 changes: 13 additions & 0 deletions document_page_approval/models/document_page_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# Copyright 2026 NuoBiT Solutions SL - Deniz Gallo <dgallo@nuobit.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


Expand Down Expand Up @@ -130,6 +131,18 @@ def action_approve(self):

def action_cancel(self):
"""Set a change request as cancelled."""
for rec in self:
if rec.state not in ["draft", "to approve"]:
raise UserError(
_("Can't cancel change requests in '%s' state.") % rec.state
)
if not (rec.am_i_owner or rec.am_i_approver):
raise UserError(
_(
"You are not authorized to do this.\r\n"
"Only owners or approvers can cancel Change Requests."
)
)
self.write({"state": "cancelled"})
for rec in self:
rec.message_post(
Expand Down
2 changes: 2 additions & 0 deletions document_page_approval/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
- Fernando La Chica \<<fernando.lachica@guadaltech.es>\>
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
- [NuoBiT Solutions SL](https://www.nuobit.com):
- Deniz Gallo <dgallo@nuobit.com>
33 changes: 16 additions & 17 deletions document_page_approval/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Document Page Approval</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="document-page-approval">
<h1 class="title">Document Page Approval</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="document-page-approval">
<h1>Document Page Approval</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:347ffb497be642e1f10188011bef36f3c3352dfc195b6aed70de618c0e7c79dc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/knowledge/tree/18.0/document_page_approval"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/knowledge-18-0/knowledge-18-0-document_page_approval"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/knowledge&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/knowledge/tree/18.0/document_page_approval"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/knowledge-18-0/knowledge-18-0-document_page_approval"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/knowledge&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a workflow to approve page modifications and show the
approved version by default.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -392,7 +387,7 @@ <h1>Document Page Approval</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure this module, you need to:</p>
<ol class="arabic simple">
<li>Set a valid email address on the company settings.</li>
Expand All @@ -402,7 +397,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
</ol>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to Knowledge &gt; Pages</li>
Expand All @@ -414,23 +409,23 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
</ol>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20document_page_approval%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Savoir-faire Linux</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul>
<li><p class="first">Odoo SA &lt;<a class="reference external" href="mailto:info&#64;odoo.com">info&#64;odoo.com</a>&gt;</p>
</li>
Expand Down Expand Up @@ -460,10 +455,15 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<li>Bhavesh Heliconia</li>
</ul>
</li>
<li><p class="first"><a class="reference external" href="https://www.nuobit.com">NuoBiT Solutions SL</a>:</p>
<ul class="simple">
<li>Deniz Gallo <a class="reference external" href="mailto:dgallo&#64;nuobit.com">dgallo&#64;nuobit.com</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -476,6 +476,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions document_page_approval/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_document_page_approval
from . import test_document_page_history
203 changes: 203 additions & 0 deletions document_page_approval/tests/test_document_page_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Copyright 2026 NuoBiT Solutions SL - Deniz Gallo <dgallo@nuobit.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from lxml import etree

from odoo import Command
from odoo.exceptions import UserError
from odoo.tests import new_test_user
from odoo.tools.safe_eval import safe_eval

from odoo.addons.base.tests.common import BaseCommon


class TestDocumentPageHistory(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.history_obj = cls.env["document.page.history"]
cls.page_approvers = cls.env["res.groups"].create({"name": "Page approvers"})
cls.owner = new_test_user(
cls.env,
login="test_owner",
groups="document_knowledge.group_document_user,"
"document_page.group_document_editor",
name="Test owner",
)
cls.approver = new_test_user(
cls.env,
login="test_approver",
groups="document_page_approval.group_document_approver_user",
name="Test approver",
)
cls.approver.write({"groups_id": [Command.link(cls.page_approvers.id)]})
cls.other_approver = new_test_user(
cls.env,
login="test_other_approver",
groups="document_page_approval.group_document_approver_user",
name="Test other approver",
)
cls.manager = new_test_user(
cls.env,
login="test_manager",
groups="document_page.group_document_manager",
name="Test manager",
)
category = cls.env["document.page"].create(
{
"name": "This category requires approval",
"type": "category",
"approval_required": True,
"approver_gid": cls.page_approvers.id,
}
)
cls.page = cls.env["document.page"].create(
{"name": "This page requires approval", "parent_id": category.id}
)

def _create_change_request(self, user):
return self.history_obj.with_user(user).create(
{
"page_id": self.page.id,
"summary": "Changed something",
"content": "<p>New content</p>",
}
)

def _with_user(self, record, user):
# a request of that user starts with an empty cache
self.env.invalidate_all()
return record.with_user(user)

def _visible_buttons(self, record, string):
"""Methods of the buttons labelled `string` that the record's user sees."""
arch = record.get_views([(False, "form")])["views"]["form"]["arch"]
values = {
"am_i_owner": record.am_i_owner,
"am_i_approver": record.am_i_approver,
"is_approval_required": record.is_approval_required,
"state": record.state,
}
names = []
for button in etree.fromstring(arch).iter("button"):
if button.get("string") == string and not safe_eval(
button.get("invisible", "False"), values
):
names.append(button.get("name"))
return names

def _click(self, record, string):
names = self._visible_buttons(record, string)
self.assertEqual(len(names), 1, names)
return getattr(record, names[0])()

def test_manager_owner_back_to_draft_pending(self):
"""Ensure a manager sends their own pending request back to draft"""
chreq = self._create_change_request(self.manager)
chreq.action_to_approve()
self._click(chreq, "Back to draft")
self.assertEqual(chreq.state, "draft")
self.assertIn("has been cancelled by Test manager.", chreq.message_ids[0].body)

def test_manager_back_to_draft_pending(self):
"""Ensure a manager sends someone else's pending request back to draft"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
chreq = self._with_user(chreq, self.manager)
self._click(chreq, "Back to draft")
self.assertEqual(chreq.state, "draft")
self.assertIn("has been cancelled by Test manager.", chreq.message_ids[0].body)

def test_other_approver_no_back_to_draft_pending(self):
"""Ensure Back to draft is hidden from who is neither owner nor approver"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
self.assertEqual(chreq.state, "to approve")
chreq = self._with_user(chreq, self.other_approver)
self.assertEqual(self._visible_buttons(chreq, "Back to draft"), [])

def test_manager_back_to_draft_cancelled(self):
"""Ensure Back to draft still reopens a cancelled request"""
chreq = self._create_change_request(self.manager)
chreq.action_to_approve()
chreq.action_cancel()
self._click(chreq, "Back to draft")
self.assertEqual(chreq.state, "draft")

def test_other_approver_no_cancel_and_draft_pending(self):
"""Ensure who is neither owner nor approver cannot cancel and reopen"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
chreq = self._with_user(chreq, self.other_approver)
with self.assertRaises(UserError) as error:
chreq.action_cancel_and_draft()
self.assertEqual(
error.exception.args[0],
"You are not authorized to do this.\r\n"
"Only owners or approvers can cancel Change Requests.",
)
self.assertEqual(chreq.state, "to approve")

def test_owner_no_cancel_approved(self):
"""Ensure an approved request cannot be cancelled"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
self._with_user(chreq, self.approver).action_approve()
chreq = self._with_user(chreq, self.owner)
with self.assertRaises(UserError) as error:
chreq.action_cancel()
self.assertEqual(
error.exception.args[0],
"Can't cancel change requests in 'approved' state.",
)
self.assertEqual(chreq.state, "approved")

def test_owner_no_cancel_cancelled(self):
"""Ensure a cancelled request cannot be cancelled again"""
chreq = self._create_change_request(self.owner)
chreq.action_cancel()
with self.assertRaises(UserError) as error:
chreq.action_cancel()
self.assertEqual(
error.exception.args[0],
"Can't cancel change requests in 'cancelled' state.",
)
self.assertEqual(chreq.state, "cancelled")

def test_other_approver_no_cancel_pending(self):
"""Ensure who is neither owner nor approver cannot cancel"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
chreq = self._with_user(chreq, self.other_approver)
with self.assertRaises(UserError) as error:
chreq.action_cancel()
self.assertEqual(
error.exception.args[0],
"You are not authorized to do this.\r\n"
"Only owners or approvers can cancel Change Requests.",
)
self.assertEqual(chreq.state, "to approve")

def test_owner_cancel_draft(self):
"""Ensure the owner cancels their draft request"""
chreq = self._create_change_request(self.owner)
self._click(chreq, "Cancel")
self.assertEqual(chreq.state, "cancelled")
self.assertIn("has been cancelled by Test owner.", chreq.message_ids[0].body)

def test_owner_cancel_pending(self):
"""Ensure the owner cancels their pending request"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
self._click(chreq, "Cancel")
self.assertEqual(chreq.state, "cancelled")
self.assertIn("has been cancelled by Test owner.", chreq.message_ids[0].body)

def test_approver_cancel_pending(self):
"""Ensure an approver cancels a pending request"""
chreq = self._create_change_request(self.owner)
chreq.action_to_approve()
chreq = self._with_user(chreq, self.approver)
self._click(chreq, "Cancel")
self.assertEqual(chreq.state, "cancelled")
self.assertIn("has been cancelled by Test approver.", chreq.message_ids[0].body)
12 changes: 11 additions & 1 deletion document_page_approval/views/document_page_approval.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2026 NuoBiT Solutions SL - Deniz Gallo <dgallo@nuobit.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- History Form View -->
<record id="wiki_history_form_inherit" model="ir.ui.view">
Expand Down Expand Up @@ -44,7 +46,15 @@
name="action_draft"
type="object"
string="Back to draft"
invisible="(not am_i_owner or not am_i_approver) and (state not in ('cancelled', 'to approve'))"
invisible="(not am_i_owner and not am_i_approver) or state != 'cancelled'"
groups="document_page.group_document_manager"
/>
<!-- cancel & reopen, if i am owner or approver -->
<button
name="action_cancel_and_draft"
type="object"
string="Back to draft"
invisible="(not am_i_owner and not am_i_approver) or state != 'to approve'"
groups="document_page.group_document_manager"
/>
<field name="am_i_owner" invisible="1" />
Expand Down
Loading