[ADD] application field & check during inheriting views read
This commit is contained in:
parent
d67161b649
commit
d82ffb8728
|
@ -146,9 +146,18 @@ class view(osv.osv):
|
|||
[('primary', "Base view"), ('extension', "Extension View")],
|
||||
string="View inheritance mode",
|
||||
required=True),
|
||||
|
||||
'application': fields.selection([
|
||||
('always', "Always applied"),
|
||||
('enabled', "Optional, enabled"),
|
||||
('disabled', "Optional, disabled"),
|
||||
], required=True, string="If this view is inherited, whether it can be"
|
||||
" toggled off, and whether it is currently"
|
||||
" enabled"),
|
||||
}
|
||||
_defaults = {
|
||||
'mode': 'primary',
|
||||
'application': 'always',
|
||||
'priority': 16,
|
||||
}
|
||||
_order = "priority,name"
|
||||
|
@ -304,7 +313,11 @@ class view(osv.osv):
|
|||
user = self.pool['res.users'].browse(cr, 1, uid, context=context)
|
||||
user_groups = frozenset(user.groups_id or ())
|
||||
|
||||
conditions = [['inherit_id', '=', view_id], ['model', '=', model]]
|
||||
conditions = [
|
||||
['inherit_id', '=', view_id],
|
||||
['model', '=', model],
|
||||
['application', 'in', ['always', 'enabled']],
|
||||
]
|
||||
if self.pool._init:
|
||||
# Module init currently in progress, only consider views from
|
||||
# modules whose code is already loaded
|
||||
|
|
|
@ -22,6 +22,13 @@ class ViewCase(common.TransactionCase):
|
|||
def create(self, value, context=None):
|
||||
return self.Views.create(self.cr, self.uid, value, context=context)
|
||||
|
||||
def read_combined(self, id):
|
||||
return self.Views.read_combined(
|
||||
self.cr, self.uid,
|
||||
id, ['arch'],
|
||||
context={'check_view_ids': self.Views.search(self.cr, self.uid, [])}
|
||||
)
|
||||
|
||||
def assertTreesEqual(self, n1, n2, msg=None):
|
||||
self.assertEqual(n1.tag, n2.tag, msg)
|
||||
self.assertEqual((n1.text or '').strip(), (n2.text or '').strip(), msg)
|
||||
|
@ -629,6 +636,7 @@ class test_views(ViewCase):
|
|||
"""Insert view into database via a query to passtrough validation"""
|
||||
kw.pop('id', None)
|
||||
kw.setdefault('mode', 'extension' if kw.get('inherit_id') else 'primary')
|
||||
kw.setdefault('application', 'always')
|
||||
|
||||
keys = sorted(kw.keys())
|
||||
fields = ','.join('"%s"' % (k.replace('"', r'\"'),) for k in keys)
|
||||
|
@ -999,13 +1007,6 @@ class TestViewCombined(ViewCase):
|
|||
'arch': '<xpath expr="//a1" position="after"><d1/></xpath>'
|
||||
})
|
||||
|
||||
def read_combined(self, id):
|
||||
return self.Views.read_combined(
|
||||
self.cr, self.uid,
|
||||
id, ['arch'],
|
||||
context={'check_view_ids': self.Views.search(self.cr, self.uid, [])}
|
||||
)
|
||||
|
||||
def test_basic_read(self):
|
||||
arch = self.read_combined(self.a1)['arch']
|
||||
self.assertEqual(
|
||||
|
@ -1052,6 +1053,50 @@ class TestViewCombined(ViewCase):
|
|||
E.a2(),
|
||||
), arch)
|
||||
|
||||
class TestOptionalViews(ViewCase):
|
||||
"""
|
||||
Tests ability to enable/disable inherited views, formerly known as
|
||||
inherit_option_id
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestOptionalViews, self).setUp()
|
||||
self.v0 = self.create({
|
||||
'model': 'a',
|
||||
'arch': '<qweb><base/></qweb>',
|
||||
})
|
||||
self.v1 = self.create({
|
||||
'model': 'a',
|
||||
'inherit_id': self.v0,
|
||||
'application': 'always',
|
||||
'arch': '<xpath expr="//base" position="after"><v1/></xpath>',
|
||||
})
|
||||
self.v2 = self.create({
|
||||
'model': 'a',
|
||||
'inherit_id': self.v0,
|
||||
'application': 'enabled',
|
||||
'arch': '<xpath expr="//base" position="after"><v2/></xpath>',
|
||||
})
|
||||
self.v3 = self.create({
|
||||
'model': 'a',
|
||||
'inherit_id': self.v0,
|
||||
'application': 'disabled',
|
||||
'arch': '<xpath expr="//base" position="after"><v3/></xpath>'
|
||||
})
|
||||
|
||||
def test_applied(self):
|
||||
""" mandatory and enabled views should be applied
|
||||
"""
|
||||
arch = self.read_combined(self.v0)['arch']
|
||||
self.assertEqual(
|
||||
ET.fromstring(arch),
|
||||
E.qweb(
|
||||
E.base(),
|
||||
E.v1(),
|
||||
E.v2(),
|
||||
)
|
||||
)
|
||||
|
||||
class TestXPathExtentions(common.BaseCase):
|
||||
def test_hasclass(self):
|
||||
tree = E.node(
|
||||
|
|
Loading…
Reference in New Issue