使用xpath在odoo上进行字段替换

field replace on odoo using xpath

我试过 Odoo 9 并想用一个新字段替换 "Total" 字段 = amount_total,这是添加字段内容 (sum_of_total) 的结果XPath 表达式,但它失败并且没有返回任何结果。
这是我的 XML 代码:

<openerp>
    <data>
        <record id="purchase_order_form_training1" model="ir.ui.view">
            <field name="name">purchase.order.form1</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <field name="amount_tax" position="after">
                    <field name="down_payment" widget="monetary" options="{'currency_field':'currency_id'}"/>
                </field>
                <xpath expr="form1/sheet/page/group/field[@name='amount_total']" position="replace">
                    <field name="sum_of_total"/>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

odoo 日志没有显示任何语法错误。谁能帮我找出根本原因?

请参阅下文以了解 sum_of_total 是如何初始化的

from openerp import models, fields, api, _

class purchase_order(models.Model):
    _inherit = "purchase.order"

    @api.one
    @api.depends('down_payment', 'amount_total')
    def get_total_after_dp(self):
        dp = self.down_payment
        tot = selt.amount_total
        tota = tot + dp
        self.sum_of_total = tota

    sum_of_total = fields.Float('Total Amount',
                                    compute='get_total_after_dp')

    down_payment = fields.Float('Down Payment')

采购订单表单视图中没有form1。 试试这个:

<xpath expr="form/sheet/notebook/page/group/field[@name='amount_total']" position="replace">
     <field name="sum_of_total"/>
</xpath>

直接搜索只需添加双正斜杠,但如果同一视图中有许多同名项目,则应使用完整路径。

<xpath expr="//field[@name='amount_total']" position="after">
      <field name='sum_of_total'/>
</xpath>