为了账号安全,请及时绑定邮箱和手机立即绑定

Odoo 11 开发人员菜单中的“字段视图获取”选项是什么?

Odoo 11 开发人员菜单中的“字段视图获取”选项是什么?

潇湘沐 2021-11-16 15:16:19
我正在尝试使用开发人员模式和可以使用错误符号打开的菜单来调试模块。如果您想查看表单的源代码,有一个菜单项“编辑表单视图”非常方便。还有菜单项“字段视图获取”,它以略有不同的方式显示相同的表单。我不明白多余的物品来自哪里。字段定义中有几个附加属性,通常还有项修饰符="{...}"。这些附加属性从何而来?来自定义合作伙伴的表单的示例代码:字段视图获取<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>
查看完整描述

1 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

关于字段 view_get


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


@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和其他属性(readonly、required、invisible)。目前,它们与这些属性并存。引入它们的原因是为了简化新的 Web 客户端,使其只能查看一个地方。评估也modifiers将发生在服务器端,放弃对 python(类似)解释器客户端的需求。最后,修饰符的具体语法将是json(信息取自https://answers.launchpad.net/openobject-server/+question/168924)。


结论


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


查看完整回答
反对 回复 2021-11-16
  • 1 回答
  • 0 关注
  • 397 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号