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)
17 changes: 16 additions & 1 deletion document_page_approval/models/document_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,24 @@ def _compute_user_has_drafts(self):

def _create_history(self, vals):
res = super()._create_history(vals)
res.action_to_approve()
if not (
self.env.context.get("document_page_copy") and res.is_approval_required
):
res.action_to_approve()
return res

def copy(self, default=None):
self.ensure_one()
# Duplicating a page writes its content, whose inverse creates a
# change request through _create_history. When the page requires
# approval, that request must remain in draft so the copy starts
# the approval workflow from scratch instead of firing approval
# requests or inheriting the state of the original history. When
# approval is not required, the record is auto-approved as usual,
# so the duplicated page keeps displaying its content.
self = self.with_context(document_page_copy=True)
return super().copy(default=default)

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