diff --git a/document_page_approval/models/document_page_history.py b/document_page_approval/models/document_page_history.py index 085fb59190e..af7558813f4 100644 --- a/document_page_approval/models/document_page_history.py +++ b/document_page_approval/models/document_page_history.py @@ -4,6 +4,7 @@ from odoo import fields, models from odoo.exceptions import UserError +from odoo.tools.misc import clean_context from odoo.tools.translate import _ @@ -80,7 +81,10 @@ def action_to_approve(self): [("groups_id", "in", guids), ("groups_id", "in", approver_gid.id)] ) rec.message_subscribe(partner_ids=users.mapped("partner_id").ids) - rec.message_post_with_source(template) + # pylint: disable=W8121 + rec.with_context( + clean_context(self.env.context) + ).message_post_with_source(template) else: # auto-approve if approval is not required rec.action_approve() diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index 01a00a73505..de41f27da76 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -1,6 +1,7 @@ from odoo import Command from odoo.exceptions import UserError from odoo.tests import new_test_user +from odoo.tools import mute_logger from odoo.addons.base.tests.common import BaseCommon @@ -53,6 +54,7 @@ def test_approval_required(self): self.assertTrue(page.has_changes_pending_approval) self.assertEqual(len(page.history_ids), 0) + @mute_logger("odoo.models.unlink") def test_change_request_approve(self): """Test that an approver can approve a change request.""" page = self.page2 @@ -72,6 +74,11 @@ def test_change_request_approve(self): self.assertEqual(chreq.state, "approved") self.assertEqual(chreq.content, page.content) + # Remove the linked mail.message and define a specific context to simulate that + # when accessing from the category smart button, there is no error when creating + # the history and sending the email + self.env["mail.message"].browse(page.parent_id.id).unlink() + page = page.with_context(default_parent_id=page.parent_id.id) # Create new change request page.write({"content": "
New content
"}) page.invalidate_model() # Recompute fields @@ -90,6 +97,7 @@ def test_change_request_auto_approve(self): page.write({"content": "New content
"}) self.assertEqual(page.content, "New content
") + @mute_logger("odoo.models.unlink") def test_change_request_from_scratch(self): """Test a full change request lifecycle from draft to approval.""" page = self.page2 @@ -164,6 +172,7 @@ def test_can_user_approve_this_page(self): self.page2.with_user(self.user2).can_user_approve_this_page(self.user2) ) + @mute_logger("odoo.models.unlink") def test_pending_approval_detection(self): """Ensure the system detects pending approval changes""" # Reset page2 by removing previous history