mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 03:56:56 -06:00
document_page: improve link using menu
This commit is contained in:
parent
264075e351
commit
587f119d81
@ -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')
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user