Odoo 11开发人员菜单中的“Fields view get”选项是什么?

问题描述 投票:1回答:1

我正在尝试使用开发人员模式和可以使用错误符号打开的菜单来调试模块。有一个菜单项“编辑表单视图”,如果你想查看表单的源代码,这是非常方便的。还有菜单项“Fields view get”,它以稍微不同的方式显示相同的表单。

我不明白额外的物品来自哪里。字段定义中有几个附加属性,通常有item modifiers =“{...}”。

这些附加属性来自哪里?

定义合作伙伴的表单中的示例代码:

字段视图获取

<form string="Partner" modifiers="{}">
<sheet modifiers="{}">
    <div class="oe_button_box" name="button_box" modifiers="{}">
        <button class="oe_stat_button o_res_partner_tip_opp" type="action" attrs="{'invisible': [('customer', '=', False)]}" name="273" icon="fa-star" context="{'search_default_partner_id': active_id}" modifiers="{'invisible':[['customer','=',false]]}" options="{}">
            <field string="Verkaufschancen" name="opportunity_count" widget="statinfo" modifiers="{'readonly':true}"/>
        </button>

编辑表单视图

<form string="Partners">
            <sheet>
                <div class="oe_button_box" name="button_box">
                    <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
                        <field name="active" widget="boolean_button" options="{&quot;terminology&quot;: &quot;archive&quot;}"/>
                    </button>
python xml python-3.x odoo odoo-11
1个回答
0
投票

关于字段view_get

每个Odoo模型都有一个fields_view_get方法,你可以覆盖它。一旦加载视图的XML代码并在呈现为HTML之前执行此方法。这意味着您可以在视图中进行一些动态修改。在Odoo模块中寻找def fields_view_get,你会发现很多案例。一个例子:

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
                    submenu=False):
    result = super(AccountMoveLine, self).fields_view_get(view_id,
                                                          view_type,
                                                          toolbar=toolbar,
                                                          submenu=submenu)

    doc = etree.XML(result['arch'])
    if view_type == 'tree' and self._module == 'account_payment_order':
        if not doc.xpath("//field[@name='balance']"):
            for placeholder in doc.xpath(
                    "//field[@name='amount_currency']"):
                elem = etree.Element(
                    'field', {
                        'name': 'balance',
                        'readonly': 'True'
                    })
                orm.setup_modifiers(elem)
                placeholder.addprevious(elem)
        if not doc.xpath("//field[@name='amount_residual_currency']"):
            for placeholder in doc.xpath(
                    "//field[@name='amount_currency']"):
                elem = etree.Element(
                    'field', {
                        'name': 'amount_residual_currency',
                        'readonly': 'True'
                    })
                orm.setup_modifiers(elem)
                placeholder.addnext(elem)
        if not doc.xpath("//field[@name='amount_residual']"):
            for placeholder in doc.xpath(
                    "//field[@name='amount_currency']"):
                elem = etree.Element(
                    'field', {
                        'name': 'amount_residual',
                        'readonly': 'True'
                    })
                orm.setup_modifiers(elem)
                placeholder.addnext(elem)
        # Remove credit and debit data - which is irrelevant in this case
        for elem in doc.xpath("//field[@name='debit']"):
            doc.remove(elem)
        for elem in doc.xpath("//field[@name='credit']"):
            doc.remove(elem)
        result['arch'] = etree.tostring(doc)
    return result

关于修饰符

修饰符旨在取代attrs和其他属性(readonlyrequiredinvisible)。目前,它们存在于这些属性的一边。引入它们的原因是为新的Web客户端简化了事情,因此它只能查看一个地方。此外,modifiers的评估将在服务器端进行,放弃对python(类似)解释器客户端的需求。最后,修饰符的具体语法将是json(来自https://answers.launchpad.net/openobject-server/+question/168924的信息)。

结论

总之,在回答您的问题时,您在编辑表单视图中看到的是视图的纯XML代码,您将在Odoo模块的XML文件中看到相同的内容,而Fields视图获取的是加载并转换为在客户端呈现。

© www.soinside.com 2019 - 2024. All rights reserved.