Odoo fields_view_get 添加动态组

Odoo fields_view_get add dynamic groups

我想重写 odoo 的 fields_view_get 以根据条件动态地将组添加到字段。

@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']):
        for field in res['fields']['vfx_shots_ids']['views']['tree']['fields']:
            if self._context.get('quote_id'):
                vfx_quote_id = self.env['vfx.quote'].browse(self._context['quote_id'])
                field_id = self.env['field.name'].search([('name', '=', field)])
                if field_id:
                    line_id = self.env['mapping.template.line'].search([('template_id', '=', vfx_quote_id.template_id.id),
                                                                        ('field_id', '=', field_id.id),
                                                                        ('model_name', '=', 'vfx.shots')
                                                                        ])
                    if line_id:
                        string = line_id.heading_id.name
                        res['fields']['vfx_shots_ids']['views']['tree']['fields'][field]['string'] = _(string)
                        res['fields']['vfx_shots_ids']['views']['tree']['fields'][field]['groups'] = str('vfx_quote_template.group_empty_fields')
    return res

这是我的 class 和字段,我想根据条件更改 vfx_quote_template.group_executive_producer 组。 目前 fields_view_get 代码似乎没有效果。

class vfx_shots(models.Model):
    _name = 'vfx.shots'

    item_number = fields.Char('Item',groups="vfx_quote_template.group_executive_producer")

您必须使用 lxml 库在 fields_view_get() 方法中修改视图的 XML 架构。 您还可以通过覆盖 fields_get() 方法来覆盖字段定义。

您可以在此处获取示例:https://bazaar.launchpad.net/~unifield-team/unifield-server/trunk/view/head:/bin/addons/consumption_calculation/history_consumption.py#L457

我知道它在代码的 v6 版本中,但 fields_view_get 行为自此版本以来并没有太大变化。