From 9977bdeaa7293e3bed1f941a515c216daacb9808 Mon Sep 17 00:00:00 2001 From: Yann Papouin Date: Tue, 30 May 2023 09:32:30 +0200 Subject: [PATCH] [FIX] document_page: Broken recomputation lead to invalid history head --- document_page/models/document_page.py | 5 ++++- document_page/tests/test_document_page.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/document_page/models/document_page.py b/document_page/models/document_page.py index 9aa39df3..79f00374 100644 --- a/document_page/models/document_page.py +++ b/document_page/models/document_page.py @@ -164,7 +164,10 @@ class DocumentPage(models.Model): def _compute_history_head(self): for rec in self: if rec.history_ids: - rec.history_head = rec.history_ids[0] + # do not rely on the history_ids default order here as odoo 14.0 does + # not seems to comply with the default model order when recomputing. + # fixing it by running a new sort (basically a new search). + rec.history_head = rec.history_ids.sorted()[0] else: rec.history_head = False diff --git a/document_page/tests/test_document_page.py b/document_page/tests/test_document_page.py index fbc0ab2c..4b994bb1 100644 --- a/document_page/tests/test_document_page.py +++ b/document_page/tests/test_document_page.py @@ -22,6 +22,10 @@ class TestDocumentPage(common.TransactionCase): self.assertEqual(len(page.history_ids), 1) page.content = "New content for Demo Page" self.assertEqual(len(page.history_ids), 2) + page.content = "Another new content for Demo Page" + self.assertEqual(len(page.history_ids), 3) + # ensure history head is the latest revision (default sort order is ID DESC) + self.assertEqual(page.history_head.id, max(page.history_ids.ids)) def test_category_template(self): page = self.page_obj.create(