我实现了fields_view_get,以从表单中的一个树视图中删除一些元素。 在同一视图中单击按钮时执行的条件下,将删除这些元素。 现在的问题是,即使我从fields_view_get中获得了正确的结果,视图(one2many树视图)在单击按钮时也没有更新
以下是屏幕截图:View with button and one2many
单击按钮后要隐藏on2many中的空白列。 fields_view_get更新视图,即删除元素,但是前端中的视图未更新。
这是我的fields_view得到的内容:
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(client_quote, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
"""update this method to change the string of fields in different tab of client quote if it changes from vfx sheet """
if view_type == 'form' and ('vfx_shots_ids' in res['fields']):
if self._context.get('quote_id'):
vfx_quote_id = self.env['vfx.quote'].browse(self._context['quote_id'])
o2m_field_dict = {'vfx.shots' : 'vfx_shots_ids', 'vfx.assets' : 'asset_ids', 'vfx.rd' : 'rd_ids', 'vfx.onset.sup' : 'on_set_sup_ids'}
for o2m_field in o2m_field_dict:
o2m_field_name = o2m_field_dict[o2m_field]
doc = etree.XML(res['fields'][o2m_field_name]['views']['tree']['arch'])
for field in res['fields'][o2m_field_name]['views']['tree']['fields']:
for node in doc.xpath("//field[@name='%s']" % field):
if field == 'date':
res_ids = self.env[o2m_field].search(
[(field, '!=', False), ('quote_id', '=', vfx_quote_id.client_quote_id.id)])
else:
res_ids = self.env[o2m_field].search([(field, '!=', ''), ('quote_id', '=', vfx_quote_id.client_quote_id.id)])
if not res_ids:
doc.remove(node)
res['fields'][o2m_field_name]['views']['tree']['arch'] = etree.tostring(doc)
return res
代码的重要部分是:
for field in res['fields'][o2m_field_name]['views']['tree']['fields']:
for node in doc.xpath("//field[@name='%s']" % field):
if field == 'date':
res_ids = self.env[o2m_field].search(
[(field, '!=', False), ('quote_id', '=', vfx_quote_id.client_quote_id.id)])
else:
res_ids = self.env[o2m_field].search([(field, '!=', ''), ('quote_id', '=', vfx_quote_id.client_quote_id.id)])
if not res_ids:
doc.remove(node)
res['fields'][o2m_field_name]['views']['tree']['arch'] = etree.tostring(doc)
当我打印arch(一个人很多的树视图)时,我得到了正确的结果,但是更改未反映在视图中
我认为,由于它具有与保留按钮相同的视图,因此不会更新该视图。