How can I delete the “sheet” node keeping its content intact?

元气小坏坏 提交于 2020-01-02 11:00:49

问题


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?

Maybe something similar to:

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

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.


回答1:


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

improved in case of oe_chatting presence




回答2:


I am from the future. I found a module time ago that made wider forms in a much easier way: web_sheet_full_width. It works for all the forms. The sheet is not removed, but the result is almost the same because the form fits in the entire screen with full width.



来源:https://stackoverflow.com/questions/32694804/how-can-i-delete-the-sheet-node-keeping-its-content-intact

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!