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')