如何删除"表"节点保持其内容完整?

时间:2015-09-21 12:05:26

标签: odoo odoo-8

我想从表单视图中删除节点<sheet></sheet>。例如,我有这个观点:

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

我想在没有节点的情况下在其他视图中转换它,但保留其中的所有元素:

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

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

也许类似于:

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

Git Hub中有一个未解决的问题,要求解决这个问题here,但我认为如果没有在Odoo中编写新功能,也许有人知道怎么做。

2 个答案:

答案 0 :(得分:5)

只需使用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存在的情况下得到改善

答案 1 :(得分:0)

我来自未来。我前段时间找到了一个模块,它以一种更容易的方式制作了更广泛的表格:web_sheet_full_width。它适用于所有形式。不会删除工作表,但是结果几乎是一样的,因为表单可以全屏显示在整个屏幕上。

full_width

相关问题