替换视图形式的正确方法

时间:2017-04-05 10:30:02

标签: openerp odoo-9

我需要覆盖account.account_aged_balance_view才能隐藏字段(Period Length (days))以及同时添加新字段。

我在自定义模块视图中尝试了以下内容:

<openerp>
  <data>
    <record id="account_aged_balance_view" model="ir.ui.view">
        <field name="name">Aged Partner Balance</field>
        <field name="model">account.aged.trial.balance</field>
        <field name="inherit_id" ref="account.account_aged_balance_view" />
        <field name="arch" type="xml">
            <form string="Report Options">
                <separator string="Aged Partner Balance"/>
                <label string="Dariel Partner Balance is a more detailed report of your receivables by intervals. When opening that report, Odoo asks for the name of the company, the Start Date and the size of the interval to be analyzed (in days). Odoo then calculates a table of credit balance by start Date. So if you request an interval of 30 days Odoo generates an analysis of creditors for the past month, past two months, and so on. "/>
                <group col="4">
                    <field name="date_from"/>
                    <newline/>
                    <field name="result_selection" widget="radio"/>
                    <field name="target_move" widget="radio"/>
                </group>
                <field name="journal_ids" required="0" invisible="1"/>
            </form>
        </field>
    </record>
  </data>
</openerp>

那些XML附加到模态表单而不是替换原始表单,如图中所示。 enter image description here

所以,我做得对吗(当然是不对的)或者这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您既可以替换整个表单视图,也可以删除并仅添加所需的字段。您必须使用 xpath 来执行此操作。

替换整个视图:

<record id="account_aged_balance_view" model="ir.ui.view">
    <field name="name">Aged Partner Balance</field>
    <field name="model">account.aged.trial.balance</field>
    <field name="inherit_id" ref="account.account_aged_balance_view" />
    <field name="arch" type="xml">
        <xpath expr='//form' position='replace'>

            < your form view >

        </xpath>
    </field>
</record>

或者你只能删除你不想要的东西并添加你想要的东西:

<record id="account_aged_balance_view" model="ir.ui.view">
    <field name="name">Aged Partner Balance</field>
    <field name="model">account.aged.trial.balance</field>
    <field name="inherit_id" ref="account.account_aged_balance_view" />
    <field name="arch" type="xml">

        <xpath expr='//field[@name="period_length"]' position='replace'/>

        <xpath expr='//field[@name=" < name of the field you want to put yours after > "]' position='after'>
            <field name=' < your field name > '/>
        </xpath>

    </field>
</record>

我没试过,但它应该有用。