[FIX] base: fix dev mode for inherits view

Before this commit, model that create ir_ui_view via _inheritS was ignored in --dev xml
The arch_fs was not set. Because it was not ir.ui.view, and because xml_id was suffixed by _ir_ui_view.

Now we manage the case of inherits. So if model model.name inherits ir_ui_view

class MyClass(models.Model):
    _name = 'model.name'
    _inherits = {'ir.ui.view': 'view_id'}

    view_id = fields.Many2one('ir.ui.view', string='View', required=True, ondelete="cascade")
    ...

<record name='model.name' xmlid='pok'>
    <field name='arch' type='xml'>content</field>
</record>

will be read from xml in dev mode.

parsing the xml file for xml_id pok_ir_ui_view and pok.
The orm by default will add this suffix.

The 'dynamic' view created when we update the groups is a special case, which we don't want the arch_fs
for dev mode because the xml only contains by default and an empty container and btw the imd was wrong
since we had the res.group model a xml_id into the _inverse_arch.

The page create via a template (method new_page) will automatically remove the arch_fs since we don't
want to see the empty container if we are in dev_mode.
This commit is contained in:
Jeremy Kersten
2018-03-08 10:22:21 +01:00
parent 9fdbbb816c
commit b4f8ca0a34
3 changed files with 40 additions and 36 deletions
+4
View File
@@ -119,6 +119,10 @@ class Website(models.Model):
'arch': template_record.arch.replace(template, key),
'name': name,
})
if view.arch_fs:
view.arch_fs = False
if ispage:
page = self.env['website.page'].create({
'url': page_url,
+31 -35
View File
@@ -115,33 +115,31 @@ def _hasclass(context, *cls):
def get_view_arch_from_file(filename, xmlid):
doc = etree.parse(filename)
node = None
for n in doc.xpath('//*[@id="%s"]' % (xmlid)):
if n.tag in ('template', 'record'):
node = n
break
if node is None:
# fallback search on template with implicit module name
for n in doc.xpath('//*[@id="%s"]' % (xmlid.split('.')[1])):
if n.tag in ('template', 'record'):
node = n
break
if node is not None:
if node.tag == 'record':
field = node.find('field[@name="arch"]')
_fix_multiple_roots(field)
inner = u''.join([etree.tostring(child, encoding='unicode') for child in field.iterchildren()])
return field.text + inner
elif node.tag == 'template':
# The following dom operations has been copied from convert.py's _tag_template()
if not node.get('inherit_id'):
node.set('t-name', xmlid)
node.tag = 't'
else:
node.tag = 'data'
node.attrib.pop('id', None)
return etree.tostring(node, encoding='unicode')
_logger.warning("Could not find view arch definition in file '%s' for xmlid '%s'", filename, xmlid)
xmlid_search = (xmlid, xmlid.split('.')[1])
# when view is created from model with inheritS of ir_ui_view, the xml id has been suffixed by '_ir_ui_view'
suffix = '_ir_ui_view'
if xmlid.endswith(suffix):
xmlid_search += (xmlid.rsplit(suffix, 1)[0], xmlid.split('.')[1].rsplit(suffix, 1)[0])
for node in doc.xpath('//*[%s]' % ' or '.join(["@id='%s'" % _id for _id in xmlid_search])):
if node.tag in ('template', 'record'):
if node.tag == 'record':
field = node.find('field[@name="arch"]')
_fix_multiple_roots(field)
inner = u''.join([etree.tostring(child, encoding='unicode') for child in field.iterchildren()])
return field.text + inner
elif node.tag == 'template':
# The following dom operations has been copied from convert.py's _tag_template()
if not node.get('inherit_id'):
node.set('t-name', xmlid)
node.tag = 't'
else:
node.tag = 'data'
node.attrib.pop('id', None)
return etree.tostring(node, encoding='unicode')
_logger.warning("Could not find view arch definition in file '%s' for xmlid '%s'", filename, xmlid_search)
return None
def add_text_before(node, text):
@@ -258,14 +256,12 @@ actual arch.
data = dict(arch_db=view.arch)
if 'install_mode_data' in self._context:
imd = self._context['install_mode_data']
if '.' not in imd['xml_id']:
imd['xml_id'] = '%s.%s' % (imd['module'], imd['xml_id'])
if self._name == imd['model'] and (not view.xml_id or view.xml_id == imd['xml_id']):
# we store the relative path to the resource instead of the absolute path, if found
# (it will be missing e.g. when importing data-only modules using base_import_module)
path_info = get_resource_from_path(imd['xml_file'])
if path_info:
data['arch_fs'] = '/'.join(path_info[0:2])
# we store the relative path to the resource instead of the absolute path, if found
# (it will be missing e.g. when importing data-only modules using base_import_module)
path_info = get_resource_from_path(imd['xml_file'])
if path_info:
data['arch_fs'] = '/'.join(path_info[0:2])
view.write(data)
@api.depends('arch')
+5 -1
View File
@@ -752,7 +752,11 @@ class GroupsView(models.Model):
xml = E.field(E.group(*(xml1), col="2"), E.group(*(xml2), col="4"), name="groups_id", position="replace")
xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS"))
xml_content = etree.tostring(xml, pretty_print=True, encoding="unicode")
view.with_context(lang=None).write({'arch': xml_content, 'arch_fs': False})
new_context = dict(view._context)
new_context.pop('install_mode_data', None) # don't set arch_fs for this computed view
new_context['lang'] = None
view.with_context(new_context).write({'arch': xml_content})
def get_application_groups(self, domain):
""" Return the non-share groups that satisfy ``domain``. """