[FIX] web_planner: prepare_backend_url give a bad URL
opw-1920590 Before this commit, the function prepare_backend_url forced in the url the view_type 'form'. This occurs because a misunderstand between the fields ir.actions.act_window.view_type (That indicate if an hierarchy in the view list exists, with as possible values : form and tree, which can be mistaken as views types) and ir.actions.act_window.view_mode (which is a list of allowed views). Now, if not ask otherwise, the function give the url of the first (the default) allowed view; or one of the allowed view if asked for it. closes odoo/odoo#29882
This commit is contained in:
@@ -46,7 +46,7 @@ class Planner(models.Model):
|
||||
return self.env['ir.ui.view'].browse(template_id).render(values=values)
|
||||
|
||||
@api.model
|
||||
def prepare_backend_url(self, action_xml_id, view_type='list', module_name=None):
|
||||
def prepare_backend_url(self, action_xml_id, view_type=None, module_name=None):
|
||||
""" prepare the backend url to the given action, or to the given module view.
|
||||
:param action_xml_id : the xml id of the action to redirect to
|
||||
:param view_type : the view type to display when redirecting (form, kanban, list, ...)
|
||||
@@ -59,8 +59,41 @@ class Planner(models.Model):
|
||||
action = self.env.ref(action_xml_id, False)
|
||||
if action:
|
||||
params['action'] = action.id
|
||||
params['view_type'] = action.view_type or view_type
|
||||
# The semantics of 'view_type', 'type', 'view_mode' and 'mode' are little bewildering in
|
||||
# the different models : action (ir.actions.act_window); view (ir.ui.view);
|
||||
# ActWindowsView (ir.actions.act_window.view); in this function and in the URL :
|
||||
#
|
||||
# - In the action model (ir.actions.act_window):
|
||||
# * 'view_type' was used to indicate if a list had hierarchy or not
|
||||
# ('form' = withtout hierarchy, 'tree' = with hierarchy). It could be interesting
|
||||
# to remove the 'view_type' field from this model as is not used anymore
|
||||
# (ir.actions.act_window).
|
||||
# * 'view_mode' is the list of allowed views in that action (form, tree, kanban, etc.).
|
||||
# * 'views' is a list of tuples with the view 'id' and the view 'type'.
|
||||
#
|
||||
# - In the view model (ir.ui.view):
|
||||
# * 'type' is the kind of view (form, tree, kanban, graph, etc.).
|
||||
# * 'mode' is use to indicate if its an extended view or not ('Base view' of 'Extension View').
|
||||
#
|
||||
# - In the ActWindowsView (ir.actions.act_window.view):
|
||||
# * 'view_mode' is the view 'type'.
|
||||
#
|
||||
# - In this function, 'view_type', is the view to display if exists in the action 'view_mode' list
|
||||
#
|
||||
# - In the URL, view_type, is the 'type' of the view to displya.
|
||||
#
|
||||
# This caused a confusion in this function.
|
||||
#
|
||||
# we changed the function to use the action view_mode field insted of action view_type field.
|
||||
|
||||
modes = [x if x != 'tree' else 'list' for x in action.view_mode.split(',')] #change 'tree' to 'list' for the JS code
|
||||
if view_type and view_type in modes:
|
||||
params['view_type'] = view_type
|
||||
else:
|
||||
params['view_type'] = modes[0]
|
||||
else:
|
||||
# add the view_type for the 'ir.module.module' to preserve the behavior of this part of the function.
|
||||
params['view_type'] = 'list'
|
||||
params['model'] = 'ir.module.module'
|
||||
# setting the module
|
||||
if module_name:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import test_web_planner
|
||||
@@ -0,0 +1,105 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.addons.web_planner.models.web_planner import Planner
|
||||
|
||||
|
||||
class TestWebPlanner(TransactionCase):
|
||||
|
||||
def test_00(self):
|
||||
#default view
|
||||
action = self.env["ir.actions.act_window"].create(
|
||||
{
|
||||
"name": "test_web_planner_00",
|
||||
"res_model": "res.partner",
|
||||
"view_mode": "tree",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["ir.model.data"].create(
|
||||
{
|
||||
"name": "test_00",
|
||||
"module": "web_planner",
|
||||
"model": "ir.actions.act_window",
|
||||
"res_id": action.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
Planner.prepare_backend_url(self, "web_planner.test_00"),
|
||||
"/web#view_type=list&action=%s" % action.id,
|
||||
)
|
||||
|
||||
def test_01(self):
|
||||
#bad choise of view_type
|
||||
action = self.env["ir.actions.act_window"].create(
|
||||
{
|
||||
"name": "test_web_planner_01",
|
||||
"res_model": "res.partner",
|
||||
"view_mode": "tree",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["ir.model.data"].create(
|
||||
{
|
||||
"name": "test_01",
|
||||
"module": "web_planner",
|
||||
"model": "ir.actions.act_window",
|
||||
"res_id": action.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
Planner.prepare_backend_url(self, "web_planner.test_01", 'form'),
|
||||
"/web#view_type=list&action=%s" % action.id,
|
||||
)
|
||||
|
||||
def test_02(self):
|
||||
#choose the second view_mode
|
||||
action = self.env["ir.actions.act_window"].create(
|
||||
{
|
||||
"name": "test_web_planner_02",
|
||||
"res_model": "res.partner",
|
||||
"view_mode": "tree,form",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["ir.model.data"].create(
|
||||
{
|
||||
"name": "test_02",
|
||||
"module": "web_planner",
|
||||
"model": "ir.actions.act_window",
|
||||
"res_id": action.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
Planner.prepare_backend_url(self, "web_planner.test_02", 'form'),
|
||||
"/web#view_type=form&action=%s" % action.id,
|
||||
)
|
||||
|
||||
def test_03(self):
|
||||
#bad xml_id
|
||||
action = self.env["ir.actions.act_window"].create(
|
||||
{
|
||||
"name": "test_web_planner_03",
|
||||
"res_model": "res.partner",
|
||||
"view_mode": "tree,form",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["ir.model.data"].create(
|
||||
{
|
||||
"name": "test_03",
|
||||
"module": "web_planner",
|
||||
"model": "ir.actions.act_window",
|
||||
"res_id": action.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
Planner.prepare_backend_url(self, "web_planner.bad_xml_id", 'form'),
|
||||
"/web#view_type=list&model=ir.module.module",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user