document_page: improve link using menu

This commit is contained in:
Simone Orsi 2019-07-11 08:44:59 +02:00
parent 264075e351
commit 587f119d81
3 changed files with 20 additions and 4 deletions

View File

@ -107,11 +107,20 @@ class DocumentPage(models.Model):
compute='_compute_backend_url',
)
@api.depends()
@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:
rec.backend_url = tmpl.format(rec.id)
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):
@ -128,11 +137,9 @@ class DocumentPage(models.Model):
r = ''
if link:
r = '<a href="{}">{}</a>'.format(self.backend_url, self.name)
if index:
r += "<ul>" + "".join(index) + "</ul>"
return r
@api.multi
@api.depends('history_head')

View File

@ -3,3 +3,4 @@
* Iván Todorovich <ivan.todorovich@gmail.com>
* Jose Maria Alzaga <jose.alzaga@aselcis.com>
* Lois Rilo <lois.rilo@eficent.com>
* Simone Orsi <simone.orsi@camptocamp.com>

View File

@ -47,3 +47,11 @@ class TestDocumentPage(common.TransactionCase):
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
)
)