【问题标题】:What is the "Fields view get" option in the Odoo 11 developer menu?Odoo 11 开发者菜单中的“Fields view get”选项是什么?
【发布时间】:2019-02-22 10:18:17
【问题描述】:

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

我不明白多余的物品是从哪里来的。字段定义中有几个附加属性,通常有 item 修饰符="{...}"。

这些附加属性从何而来?

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

字段视图获取

<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】:

    关于字段 view_get

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

    @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)。

    结论

    总之,回答您的问题,您在 Edit form view 中看到的是视图的纯 XML 代码,与您在 Odoo 模块的 XML 文件中看到的相同,而 Fields view get是加载并转换为在客户端呈现后的代码。

    【讨论】:

    • 谢谢,这对它有所启发。这是否意味着我在“字段视图获取”显示中看到的每个单词“修饰符”只能通过覆盖函数来访问,并且我发现的每个额外属性都源自另一个 xml 视图(我必须找到并继承它才能覆盖属性)?
    • @thopy 完全正确。您可以在 Inherited views 选项卡的 Edit X View(其中 X 是表单、树、看板...)中轻松找到添加的修改。但是这些视图中的每一个都有自己的 Inherited views 选项卡,其中包含自己的修改,因此,根据视图,查看所有修改可能需要一些时间。顺便说一句,如果这个答案对您有帮助,请检查它是否有用或正确答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 2021-12-02
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多