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
1 change: 1 addition & 0 deletions document_page/models/document_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DocumentPage(models.Model):
"page_id",
"History",
readonly=True,
copy=False,
)
menu_id = fields.Many2one("ir.ui.menu", "Menu", readonly=True)
content_date = fields.Datetime(
Expand Down
1 change: 1 addition & 0 deletions document_page/tests/test_document_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ def test_page_copy(self):
self.assertEqual(page_copy.content, page.content)
self.assertEqual(page_copy.draft_name, "1.0")
self.assertEqual(page_copy.draft_summary, "summary")
self.assertFalse(page_copy.history_ids & page.history_ids)
18 changes: 18 additions & 0 deletions document_page_approval/models/document_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ def _create_history(self, vals):
res.action_to_approve()
return res

def copy(self, default=None):
self.ensure_one()
# Do not trigger _inverse_content during copy; otherwise _create_history
# would move the new record straight to "to approve". Create the initial
# change request as draft so the duplicated page starts in the approval
# workflow.
default = dict(default or {}, content=False)
new_page = super().copy(default=default)
self.env["document.page.history"].create(
{
"page_id": new_page.id,
"name": new_page.draft_name,
"summary": new_page.draft_summary,
"content": self.content,
}
)
return new_page

def action_changes_pending_approval(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
Expand Down
5 changes: 3 additions & 2 deletions document_page_approval/models/document_page_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ class DocumentPageHistory(models.Model):
"Status",
default="draft",
readonly=True,
copy=False,
)

approved_date = fields.Datetime()
approved_date = fields.Datetime(copy=False)

approved_uid = fields.Many2one("res.users", "Approved by")
approved_uid = fields.Many2one("res.users", "Approved by", copy=False)

is_approval_required = fields.Boolean(
related="page_id.is_approval_required", string="Approval required"
Expand Down
28 changes: 28 additions & 0 deletions document_page_approval/tests/test_document_page_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,31 @@ def test_cache_has_changes_pending_approval(self):

# Approver user evaluates it.
self.assertTrue(page.with_user(self.user2).has_changes_pending_approval)

def test_history_copy(self):
"""Duplicating a page must not copy history or approval metadata."""
page = self.page2
chreq = self.history_obj.with_user(self.user2).create(
{
"page_id": page.id,
"content": "<p>Version 1</p>",
"state": "approved",
"approved_date": "2026-07-31 10:00:00",
"approved_uid": self.user2.id,
}
)
original_history = page.history_ids
page_copy = page.copy()
self.assertFalse(page_copy.history_ids & original_history)
# The duplicated page starts with a single draft change request that
# carries the original content but no approval metadata.
all_copy_hist = self.history_obj.search([("page_id", "=", page_copy.id)])
self.assertEqual(len(all_copy_hist), 1)
self.assertEqual(all_copy_hist.state, "draft")
self.assertEqual(all_copy_hist.content, page.content)
self.assertFalse(all_copy_hist.approved_date)
self.assertFalse(all_copy_hist.approved_uid)
chreq_copy = chreq.copy()
self.assertEqual(chreq_copy.state, "draft")
self.assertFalse(chreq_copy.approved_date)
self.assertFalse(chreq_copy.approved_uid)
Loading