替换视图表单的正确方法
proper way to replace view form
我需要覆盖 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
附加到模态形式而不是替换原始形式,如图所示。
所以,我这样做对吗(当然不对)或者正确的做法是怎样的?
您既可以替换整个表单视图,也可以删除并仅添加所需的字段。你必须使用 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>
我没试过,但应该可以。
我需要覆盖 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
附加到模态形式而不是替换原始形式,如图所示。
所以,我这样做对吗(当然不对)或者正确的做法是怎样的?
您既可以替换整个表单视图,也可以删除并仅添加所需的字段。你必须使用 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>
我没试过,但应该可以。