diff --git a/document_page/models/document_page.py b/document_page/models/document_page.py
index 0eff4ffc..4cfe4b42 100644
--- a/document_page/models/document_page.py
+++ b/document_page/models/document_page.py
@@ -101,6 +101,26 @@ class DocumentPage(models.Model):
index=True,
ondelete='cascade',
)
+ backend_url = fields.Char(
+ string='Backend URL',
+ help='Use it to link resources univocally',
+ compute='_compute_backend_url',
+ )
+
+ @api.depends('menu_id', 'parent_id.menu_id')
+ def _compute_backend_url(self):
+ tmpl = '/web#id={}&model=document.page&view_type=form'
+ for rec in self:
+ url = tmpl.format(rec.id)
+ # retrieve action
+ action = None
+ parent = rec
+ while not action and parent:
+ action = parent.menu_id.action
+ parent = parent.parent_id
+ if action:
+ url += '&action={}'.format(action.id)
+ rec.backend_url = url
@api.constrains('parent_id')
def _check_parent_id(self):
@@ -116,8 +136,7 @@ class DocumentPage(models.Model):
index += ["
" + subpage._get_page_index() + ""]
r = ''
if link:
- r = '%s' % (self.id, self.name)
-
+ r = '{}'.format(self.backend_url, self.name)
if index:
r += ""
return r
diff --git a/document_page/readme/CONTRIBUTORS.rst b/document_page/readme/CONTRIBUTORS.rst
index 835f2d15..2061bdb5 100644
--- a/document_page/readme/CONTRIBUTORS.rst
+++ b/document_page/readme/CONTRIBUTORS.rst
@@ -3,3 +3,4 @@
* Iván Todorovich
* Jose Maria Alzaga
* Lois Rilo
+* Simone Orsi
diff --git a/document_page/tests/test_document_page.py b/document_page/tests/test_document_page.py
index c087623e..3a67f08e 100644
--- a/document_page/tests/test_document_page.py
+++ b/document_page/tests/test_document_page.py
@@ -37,3 +37,21 @@ class TestDocumentPage(common.TransactionCase):
})
page.content = 'New content'
self.assertIsNotNone(page.history_ids[0].diff)
+
+ def test_page_link(self):
+ page = self.page_obj.create({
+ 'name': 'Test Page 3',
+ 'content': 'Test content'
+ })
+ self.assertEqual(
+ page.backend_url,
+ '/web#id={}&model=document.page&view_type=form'.format(page.id)
+ )
+ menu = self.env.ref('knowledge.menu_document')
+ page.menu_id = menu
+ self.assertEqual(
+ page.backend_url,
+ '/web#id={}&model=document.page&view_type=form&action={}'.format(
+ page.id, menu.action.id
+ )
+ )