如何删除“工作表"节点保持其内容完整无缺? [英] How can I delete the "sheet" node keeping its content intact?

查看:59
本文介绍了如何删除“工作表"节点保持其内容完整无缺?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从表单视图中删除节点<sheet></sheet>.例如,我有以下视图:

I would like to remove the node <sheet></sheet> from a form view. For instance, I have this view:

<record id="view_account_period_form" model="ir.ui.view">
    <field name="name">account.period.form</field>
    <field name="model">account.period</field>
    <field name="arch" type="xml">
        <form string="Account Period">
            <header>
                [...]
            </header>
            <sheet>
                <group>
                    <group>
                        <field name="name"/>
                        <field name="fiscalyear_id" widget="selection"/>
                        <label for="date_start" string="Duration"/>
                        <div>
                            <field name="date_start" class="oe_inline" nolabel="1"/> -
                            <field name="date_stop" nolabel="1" class="oe_inline"/>
                        </div>
                    </group>
                    <group>
                        <field name="code"/>
                        <field name="special"/>
                        <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                    </group>
                </group>
            </sheet>
        </form>
    </field>
</record>

我想在没有节点的其他视图中进行转换,但将所有元素保留在其中:

I would like to convert it in this other view without the node, but keeping all the elements within it:

<record id="view_account_period_form" model="ir.ui.view">
    <field name="name">account.period.form</field>
    <field name="model">account.period</field>
    <field name="arch" type="xml">
        <form string="Account Period">
            <header>
                [...]
            </header>

            <group>
                <group>
                    <field name="name"/>
                    <field name="fiscalyear_id" widget="selection"/>
                    <label for="date_start" string="Duration"/>
                    <div>
                        <field name="date_start" class="oe_inline" nolabel="1"/> -
                        <field name="date_stop" nolabel="1" class="oe_inline"/>
                    </div>
                </group>
                <group>
                    <field name="code"/>
                    <field name="special"/>
                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                </group>
            </group>

        </form>
    </field>
</record>

有可能还是我需要再次覆盖完整的代码?

Is that possible or I need to override the complete code again?

也许类似于:

<xpath expr="//form/sheet" position="replace">
    <!-- [...] -->
</xpath>

Git Hub中有一个未解决的问题,要求在此处解决,但我认为也许有人知道如何在不编写Odoo新功能的情况下做到这一点.

There is an open issue in Git Hub asking for solving this here, but I think that maybe anyone knows how to do it without programming a new feature in Odoo.

推荐答案

只需使用fields_view_get:

Just use fields_view_get:

    from lxml import etree
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
        if view_type == 'form':
            doc = etree.XML(res['arch'])
            for sheet in doc.xpath("//sheet"):
                parent = sheet.getparent()
                index = parent.index(sheet)
                for child in sheet:
                    parent.insert(index, child)
                    index += 1
                parent.remove(sheet)
            res['arch'] = etree.tostring(doc)
        return res

在发生oe_chatting的情况下得到改善

improved in case of oe_chatting presence

这篇关于如何删除“工作表"节点保持其内容完整无缺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆