Odoofields_view_get添加动态组

时间:2018-08-08 13:17:34

标签: python-2.7 odoo odoo-10

我想覆盖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

这是我的课程和领域,我想根据条件更改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")

1 个答案:

答案 0 :(得分:0)

您必须使用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的行为并没有太大改变。