Merge PR #563 into 18.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2025-12-17 16:06:03 +00:00
15 changed files with 153 additions and 108 deletions

View File

@@ -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 Document Page
============= =============
@@ -17,7 +13,7 @@ Document Page
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status :target: https://odoo-community.org/page/development-status
:alt: Beta :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 :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
@@ -61,6 +57,12 @@ To use this module, you need to:
- Click on Pages to create pages and select the previous category to use - Click on Pages to create pages and select the previous category to use
the template the template
Improve diff of history
-----------------------
If you want to improve how history is shown, you can install html_diff
python library. A new comparison method will be installed.
Bug Tracker Bug Tracker
=========== ===========
@@ -83,23 +85,34 @@ Contributors
------------ ------------
- Gervais Naoussi <gervaisnaoussi@gmail.com> - Gervais Naoussi <gervaisnaoussi@gmail.com>
- Maxime Chambreuil <mchambreuil@ursainfosystems.com> - Maxime Chambreuil <mchambreuil@ursainfosystems.com>
- Iván Todorovich <ivan.todorovich@gmail.com> - Iván Todorovich <ivan.todorovich@gmail.com>
- Jose Maria Alzaga <jose.alzaga@aselcis.com> - Jose Maria Alzaga <jose.alzaga@aselcis.com>
- Lois Rilo <lois.rilo@forgeflow.com> - Lois Rilo <lois.rilo@forgeflow.com>
- Simone Orsi <simone.orsi@camptocamp.com> - Simone Orsi <simone.orsi@camptocamp.com>
- `Tecnativa <https://www.tecnativa.com>`__: - `Tecnativa <https://www.tecnativa.com>`__:
- Ernesto Tejeda - Ernesto Tejeda
- Víctor Martínez - Víctor Martínez
Trobz - Trobz
- Dung Tran <dungtd@trobz.com> - Dung Tran <dungtd@trobz.com>
- `Sygel <https://www.sygel.es>`__: - `Sygel <https://www.sygel.es>`__:
- Ángel García de la Chica Herrera - Ángel García de la Chica Herrera
- `Dixmit <https://www.dixmit.com>`__:
- Enric Tobella
Other credits Other credits
------------- -------------

View File

@@ -17,7 +17,7 @@
], ],
"website": "https://github.com/OCA/knowledge", "website": "https://github.com/OCA/knowledge",
"license": "AGPL-3", "license": "AGPL-3",
"depends": ["mail", "document_knowledge"], "depends": ["mail", "document_knowledge", "web_editor"],
"data": [ "data": [
"security/document_page_security.xml", "security/document_page_security.xml",
"security/ir.model.access.csv", "security/ir.model.access.csv",
@@ -30,6 +30,9 @@
], ],
"demo": ["demo/document_page.xml"], "demo": ["demo/document_page.xml"],
"assets": { "assets": {
"web._assets_primary_variables": [
"document_page/static/src/**/document_page_variables.scss",
],
"web.assets_backend": [ "web.assets_backend": [
"document_page/static/src/scss/document_page.scss", "document_page/static/src/scss/document_page.scss",
"document_page/static/src/js/document_page_kanban_controller.esm.js", "document_page/static/src/js/document_page_kanban_controller.esm.js",

View File

@@ -1,10 +1,13 @@
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import difflib
from odoo import api, fields, models from odoo import api, fields, models
from odoo.addons.web_editor.models.diff_utils import (
generate_comparison,
)
class DocumentPageHistory(models.Model): class DocumentPageHistory(models.Model):
"""This model is necessary to manage a document history.""" """This model is necessary to manage a document history."""
@@ -17,7 +20,7 @@ class DocumentPageHistory(models.Model):
name = fields.Char(index=True) name = fields.Char(index=True)
summary = fields.Char(index=True) summary = fields.Char(index=True)
content = fields.Html(sanitize=False) content = fields.Html(sanitize=False)
diff = fields.Html(compute="_compute_diff") diff = fields.Html(compute="_compute_diff", sanitize_tags=False)
company_id = fields.Many2one( company_id = fields.Many2one(
"res.company", "res.company",
@@ -43,28 +46,10 @@ class DocumentPageHistory(models.Model):
) )
rec.diff = self._get_diff(prev.id, rec.id) rec.diff = self._get_diff(prev.id, rec.id)
@api.model
def _get_diff(self, v1, v2): def _get_diff(self, v1, v2):
"""Return the difference between two version of document version."""
text1 = v1 and self.browse(v1).content or "" text1 = v1 and self.browse(v1).content or ""
text2 = v2 and self.browse(v2).content or "" text2 = v2 and self.browse(v2).content or ""
# Include line breaks to make it more readable return generate_comparison(text1, text2)
# TODO: consider using a beautify library directly on the content
text1 = text1.replace("</p><p>", "</p>\r\n<p>")
text2 = text2.replace("</p><p>", "</p>\r\n<p>")
line1 = text1.splitlines(True)
line2 = text2.splitlines(True)
if line1 == line2:
return self.env._("There are no changes in revisions.")
else:
diff = difflib.HtmlDiff()
return diff.make_table(
line1,
line2,
f"Revision-{v1}",
f"Revision-{v2}",
context=True,
)
@api.depends("page_id") @api.depends("page_id")
def _compute_display_name(self): def _compute_display_name(self):

View File

@@ -8,8 +8,11 @@
- Ernesto Tejeda - Ernesto Tejeda
- Víctor Martínez - Víctor Martínez
Trobz - Trobz
- Dung Tran \<<dungtd@trobz.com>\> - Dung Tran \<<dungtd@trobz.com>\>
- [Sygel](https://www.sygel.es): - [Sygel](https://www.sygel.es):
- Ángel García de la Chica Herrera - Ángel García de la Chica Herrera
- [Dixmit](https://www.dixmit.com):
- Enric Tobella

View File

@@ -5,3 +5,8 @@ To use this module, you need to:
the template the template
- Click on Pages to create pages and select the previous category to use - Click on Pages to create pages and select the previous category to use
the template the template
## Improve diff of history
If you want to improve how history is shown, you can install html_diff python library.
A new comparison method will be installed.

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" /> <meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title> <title>Document Page</title>
<style type="text/css"> <style type="text/css">
/* /*
@@ -360,49 +360,47 @@ ul.auto-toc {
</style> </style>
</head> </head>
<body> <body>
<div class="document"> <div class="document" id="document-page">
<h1 class="title">Document Page</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">
<h1>Document Page</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:029a3933b3eea6e056988a1f6fb36f83a4539b5a7d32e7bef7b60dfc3f871c98 !! source digest: sha256:029a3933b3eea6e056988a1f6fb36f83a4539b5a7d32e7bef7b60dfc3f871c98
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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"><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"><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"><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"><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 allows you to write web pages for internal documentation.</p> <p>This module allows you to write web pages for internal documentation.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
<li><a class="reference internal" href="#installation" id="toc-entry-1">Installation</a></li> <li><a class="reference internal" href="#installation" id="toc-entry-1">Installation</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li> <li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-3">Usage</a></li> <li><a class="reference internal" href="#usage" id="toc-entry-3">Usage</a><ul>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li> <li><a class="reference internal" href="#improve-diff-of-history" id="toc-entry-4">Improve diff of history</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul> </ul>
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li> </li>
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li> <li><a class="reference internal" href="#bug-tracker" id="toc-entry-5">Bug Tracker</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-8">Other credits</a></li> <li><a class="reference internal" href="#credits" id="toc-entry-6">Credits</a><ul>
<li><a class="reference internal" href="#maintainers" id="toc-entry-9">Maintainers</a></li> <li><a class="reference internal" href="#authors" id="toc-entry-7">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-8">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-9">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
<div class="section" id="installation"> <div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2> <h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>This module depends on module knowledge. So make sure to have it in your <p>This module depends on module knowledge. So make sure to have it in your
addons list.</p> addons list.</p>
</div> </div>
<div class="section" id="configuration"> <div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2> <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>No configuration required.</p> <p>No configuration required.</p>
</div> </div>
<div class="section" id="usage"> <div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2> <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<p>To use this module, you need to:</p> <p>To use this module, you need to:</p>
<ul class="simple"> <ul class="simple">
<li>Go to Knowledge menu</li> <li>Go to Knowledge menu</li>
@@ -411,9 +409,14 @@ the template</li>
<li>Click on Pages to create pages and select the previous category to use <li>Click on Pages to create pages and select the previous category to use
the template</li> the template</li>
</ul> </ul>
<div class="section" id="improve-diff-of-history">
<h2><a class="toc-backref" href="#toc-entry-4">Improve diff of history</a></h2>
<p>If you want to improve how history is shown, you can install html_diff
python library. A new comparison method will be installed.</p>
</div>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2> <h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>. <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. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
@@ -421,15 +424,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2> <h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
<div class="section" id="authors"> <div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3> <h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>OpenERP SA</li> <li>OpenERP SA</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3> <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Gervais Naoussi &lt;<a class="reference external" href="mailto:gervaisnaoussi&#64;gmail.com">gervaisnaoussi&#64;gmail.com</a>&gt;</li> <li>Gervais Naoussi &lt;<a class="reference external" href="mailto:gervaisnaoussi&#64;gmail.com">gervaisnaoussi&#64;gmail.com</a>&gt;</li>
<li>Maxime Chambreuil &lt;<a class="reference external" href="mailto:mchambreuil&#64;ursainfosystems.com">mchambreuil&#64;ursainfosystems.com</a>&gt;</li> <li>Maxime Chambreuil &lt;<a class="reference external" href="mailto:mchambreuil&#64;ursainfosystems.com">mchambreuil&#64;ursainfosystems.com</a>&gt;</li>
@@ -442,18 +445,22 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Víctor Martínez</li> <li>Víctor Martínez</li>
</ul> </ul>
</li> </li>
</ul> <li>Trobz<ul>
<p>Trobz</p>
<ul class="simple">
<li>Dung Tran &lt;<a class="reference external" href="mailto:dungtd&#64;trobz.com">dungtd&#64;trobz.com</a>&gt;</li> <li>Dung Tran &lt;<a class="reference external" href="mailto:dungtd&#64;trobz.com">dungtd&#64;trobz.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.sygel.es">Sygel</a>:<ul> <li><a class="reference external" href="https://www.sygel.es">Sygel</a>:<ul>
<li>Ángel García de la Chica Herrera</li> <li>Ángel García de la Chica Herrera</li>
</ul> </ul>
</li> </li>
<li><a class="reference external" href="https://www.dixmit.com">Dixmit</a>:<ul>
<li>Enric Tobella</li>
</ul>
</li>
</ul> </ul>
</div> </div>
<div class="section" id="other-credits"> <div class="section" id="other-credits">
<h3><a class="toc-backref" href="#toc-entry-8">Other credits</a></h3> <h2><a class="toc-backref" href="#toc-entry-9">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p> <p>The development of this module has been financially supported by:</p>
<ul class="simple"> <ul class="simple">
<li>Odoo SA &lt;<a class="reference external" href="http://www.odoo.com">http://www.odoo.com</a>&gt;</li> <li>Odoo SA &lt;<a class="reference external" href="http://www.odoo.com">http://www.odoo.com</a>&gt;</li>
@@ -462,7 +469,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3> <h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"> <a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> <img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -475,6 +482,5 @@ promote its widespread use.</p>
</div> </div>
</div> </div>
</div> </div>
</div>
</body> </body>
</html> </html>

View File

@@ -1,9 +1,10 @@
.o_document_page_diff {
table.diff { table.diff {
font-family: Courier; font-family: Courier;
border: medium; border: medium;
.diff_header { .diff_header {
background-color: #e0e0e0; background-color: $o_document_page_diff_header_background;
} }
td.diff_header { td.diff_header {
@@ -11,18 +12,29 @@ table.diff {
} }
.diff_next { .diff_next {
background-color: #c0c0c0; background-color: $o_document_page_diff_next_background;
} }
.diff_add { .diff_add {
background-color: #aaffaa; background-color: $o_document_page_diff_add_background;
} }
.diff_chg { .diff_chg {
background-color: #ffff77; background-color: $o_document_page_diff_change_background;
} }
.diff_sub { .diff_sub {
background-color: #ffaaaa; background-color: $o_document_page_diff_subtract_background;
}
}
removed {
display: inline;
text-decoration: line-through;
opacity: 0.5;
background-color: $o_document_page_diff_subtract_background;
}
added {
display: inline;
background-color: $o_document_page_diff_add_background;
} }
} }

View File

@@ -0,0 +1,5 @@
$o_document_page_diff_header_background: #e0e0e0;
$o_document_page_diff_next_background: #c0c0c0;
$o_document_page_diff_add_background: #aaffaa;
$o_document_page_diff_change_background: #ffff77;
$o_document_page_diff_subtract_background: #ffaaaa;

View File

@@ -31,12 +31,16 @@ class TestDocumentPage(common.TransactionCase):
self.assertEqual(page.content, self.category1.template) self.assertEqual(page.content, self.category1.template)
def test_page_history_diff(self): def test_page_history_diff(self):
page = self.page_obj.create({"name": "Test Page 3", "content": "Test content"}) page = self.page_obj.create(
page.content = "New content" {"name": "Test Page 3", "content": "<div>Test content</div>"}
)
page.content = "<div>New content</div>"
self.assertIsNotNone(page.history_ids[0].diff) self.assertIsNotNone(page.history_ids[0].diff)
def test_page_link(self): def test_page_link(self):
page = self.page_obj.create({"name": "Test Page 3", "content": "Test content"}) page = self.page_obj.create(
{"name": "Test Page 3", "content": "<div>Test content</div>"}
)
self.assertEqual( self.assertEqual(
page.backend_url, page.backend_url,
f"/web#id={page.id}&model=document.page&view_type=form", f"/web#id={page.id}&model=document.page&view_type=form",
@@ -49,7 +53,9 @@ class TestDocumentPage(common.TransactionCase):
) )
def test_page_copy(self): def test_page_copy(self):
page = self.page_obj.create({"name": "Test Page 3", "content": "Test content"}) page = self.page_obj.create(
{"name": "Test Page 3", "content": "<div>Test content</div>"}
)
page_copy = page.copy() page_copy = page.copy()
self.assertEqual(page_copy.name, page.name + " (copy)") self.assertEqual(page_copy.name, page.name + " (copy)")
self.assertEqual(page_copy.content, page.content) self.assertEqual(page_copy.content, page.content)

View File

@@ -6,14 +6,15 @@ class TestDocumentPageHistory(common.TransactionCase):
def test_page_history_demo_page1(self): def test_page_history_demo_page1(self):
"""Test page history demo page1.""" """Test page history demo page1."""
page = self.env.ref("document_page.demo_page1") page = self.env["document.page"].create(
page.content = "Test content updated" {
"name": "Test Page",
"content": "<div>Initial content</div>",
}
)
page.content = "<div>Test content updated</div>"
history_document = self.env["document.page.history"] history_document = self.env["document.page.history"]
history_pages = history_document.search([("page_id", "=", page.id)]) history_pages = history_document.search([("page_id", "=", page.id)])
active_ids = [i.id for i in history_pages] active_ids = [i.id for i in history_pages]
result = history_document._get_diff(active_ids[0], active_ids[0]) result = history_document._get_diff(active_ids[0], active_ids[0])
self.assertEqual(result, "There are no changes in revisions.") self.assertEqual(result, page.content)
result = history_document._get_diff(active_ids[0], active_ids[1])
self.assertNotEqual(result, "There are no changes in revisions.")

View File

@@ -8,7 +8,12 @@ class TestDocumentPageShowDiff(common.TransactionCase):
def test_show_demo_page1_diff(self): def test_show_demo_page1_diff(self):
"""Show test page history difference.""" """Show test page history difference."""
page = self.env.ref("document_page.demo_page1") page = self.env["document.page"].create(
{
"name": "Test Page",
"content": "<div>Initial content</div>",
}
)
show_diff_object = self.env["wizard.document.page.history.show_diff"] show_diff_object = self.env["wizard.document.page.history.show_diff"]
@@ -21,8 +26,8 @@ class TestDocumentPageShowDiff(common.TransactionCase):
)._get_diff() )._get_diff()
) )
page.write({"content": "Text content updated"}) page.write({"content": "<div>Text content updated</div>"})
page.write({"content": "Text updated"}) page.write({"content": "<div>Text updated</div>"})
history_pages = history_document.search([("page_id", "=", page.id)]) history_pages = history_document.search([("page_id", "=", page.id)])

View File

@@ -69,6 +69,7 @@
<field <field
name="diff" name="diff"
widget="html" widget="html"
class="o_document_page_diff"
style="overflow-x: scroll" style="overflow-x: scroll"
/> />
</page> </page>

View File

@@ -27,4 +27,4 @@ class DocumentPageShowDiff(models.TransientModel):
raise UserError(self.env._("Select one or maximum two history revisions!")) raise UserError(self.env._("Select one or maximum two history revisions!"))
return diff return diff
diff = fields.Html(readonly=True, default=_get_diff) diff = fields.Html(readonly=True, default=_get_diff, sanitize_tags=False)

View File

@@ -42,7 +42,7 @@ class TestDocumentPageApproval(BaseCommon):
{ {
"name": "This page requires approval", "name": "This page requires approval",
"parent_id": cls.category2.id, "parent_id": cls.category2.id,
"content": "This content will require approval", "content": "<p>This content will require approval</p>",
} }
) )
@@ -73,7 +73,7 @@ class TestDocumentPageApproval(BaseCommon):
self.assertEqual(chreq.content, page.content) self.assertEqual(chreq.content, page.content)
# Create new change request # Create new change request
page.write({"content": "New content"}) page.write({"content": "<p>New content</p>"})
page.invalidate_model() # Recompute fields page.invalidate_model() # Recompute fields
chreq = self.history_obj.search( chreq = self.history_obj.search(
[("page_id", "=", page.id), ("state", "!=", "approved")], limit=1 [("page_id", "=", page.id), ("state", "!=", "approved")], limit=1
@@ -81,14 +81,14 @@ class TestDocumentPageApproval(BaseCommon):
# Approve new changes # Approve new changes
chreq.with_user(self.user2).action_approve() chreq.with_user(self.user2).action_approve()
self.assertEqual(page.content, "New content") self.assertEqual(page.content, "<p>New content</p>")
def test_change_request_auto_approve(self): def test_change_request_auto_approve(self):
"""Test that a page without approval required auto-approves changes.""" """Test that a page without approval required auto-approves changes."""
page = self.page1 page = self.page1
self.assertFalse(page.is_approval_required) self.assertFalse(page.is_approval_required)
page.write({"content": "New content"}) page.write({"content": "<p>New content</p>"})
self.assertEqual(page.content, "New content") self.assertEqual(page.content, "<p>New content</p>")
def test_change_request_from_scratch(self): def test_change_request_from_scratch(self):
"""Test a full change request lifecycle from draft to approval.""" """Test a full change request lifecycle from draft to approval."""
@@ -104,7 +104,7 @@ class TestDocumentPageApproval(BaseCommon):
{ {
"page_id": page.id, "page_id": page.id,
"summary": "Changed something", "summary": "Changed something",
"content": "New content", "content": "<p>New content</p>",
} }
) )
@@ -245,7 +245,7 @@ class TestDocumentPageApproval(BaseCommon):
self.history_obj.create( self.history_obj.create(
{ {
"page_id": self.page2.id, "page_id": self.page2.id,
"content": "Version 1", "content": "<p>Version 1</p>",
"state": "approved", "state": "approved",
} }
) )
@@ -253,7 +253,7 @@ class TestDocumentPageApproval(BaseCommon):
chreq2 = self.history_obj.create( chreq2 = self.history_obj.create(
{ {
"page_id": self.page2.id, "page_id": self.page2.id,
"content": "Version 2", "content": "<p>Version 2</p>",
} }
) )
chreq2._compute_diff() chreq2._compute_diff()

View File

@@ -51,8 +51,8 @@ class TestDocumentReference(BaseCommon):
new_page_duplicated_name = self.page_obj.create( new_page_duplicated_name = self.page_obj.create(
{ {
"name": "test page with no reference", "name": "test page with no reference",
"content": "this should have an empty reference " "content": "<p>this should have an empty reference "
"because reference must be unique", "because reference must be unique</p>",
} }
) )
self.assertFalse(new_page_duplicated_name.reference) self.assertFalse(new_page_duplicated_name.reference)