[FIX] website: _view_obj in multi websites
First 'key' and 'website_id' fields must be checked to retrieve the right view. Then if no view is found, it falls back on xml_id. To choose the right ir_ui_view, _view_obj must take into account the 'website_id' set in the context. Inspired from function "get_view_id" in addons/website/models/ir_ui_view.py
This commit is contained in:
@@ -35,18 +35,16 @@ class view(osv.osv):
|
||||
|
||||
def _view_obj(self, cr, uid, view_id, context=None):
|
||||
if isinstance(view_id, basestring):
|
||||
try:
|
||||
return self.pool['ir.model.data'].xmlid_to_object(
|
||||
cr, uid, view_id, raise_if_not_found=True, context=context
|
||||
)
|
||||
except:
|
||||
# Try to fallback on key instead of xml_id
|
||||
if 'website_id' in context:
|
||||
domain = [('key', '=', view_id), '|', ('website_id', '=', False), ('website_id', '=', context.get('website_id'))]
|
||||
rec_id = self.search(cr, uid, domain, order='website_id', context=context)
|
||||
else:
|
||||
rec_id = self.search(cr, uid, [('key', '=', view_id)], context=context)
|
||||
if rec_id:
|
||||
_logger.info("Could not find view with `xml_id' '%s', fallback on `key'" % (view_id))
|
||||
return self.browse(cr, uid, rec_id, context=context)[0]
|
||||
else:
|
||||
raise
|
||||
if rec_id:
|
||||
return self.browse(cr, uid, rec_id, context=context)[0]
|
||||
else:
|
||||
return self.pool['ir.model.data'].xmlid_to_object(
|
||||
cr, uid, view_id, raise_if_not_found=True, context=context)
|
||||
elif isinstance(view_id, (int, long)):
|
||||
return self.browse(cr, uid, view_id, context=context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user