不能在one2many_list小部件中的xpath字段

时间:2018-02-09 08:03:56

标签: python xml xpath odoo odoo-9

我尝试xpath在one2many_list小部件内的字段partner_id。不知何故,我试过的路径都没有引起任何变化。

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    res = super(AccountMove, self).fields_view_get(
        view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
    doc = etree.XML(res['arch'])
    for node in doc.xpath("//page//field//tree//field[@name='partner_id']"):
        if not self._is_group_8():
            node.set('options', "{'no_open': True ,'no_create_edit': True}")
    res['arch'] = etree.tostring(doc)
    return res

这是包含上述字段的整个视图。

<?xml version="1.0"?>
<form string="Account Entry">
    <header>
        <button name="post" states="draft" string="Post" type="object" class="oe_highlight" groups="account.group_account_invoice"/>
        <button name="131" states="posted" string="Reverse Entry" type="action" groups="account.group_account_invoice"/>
        <button name="button_cancel" states="posted" string="Cancel Entry" type="object" groups="account.group_account_invoice"/>
        <field name="state" widget="statusbar"/>
    </header>
    <sheet>
        <div class="oe_button_box">
            <button name="open_reconcile_view" class="oe_stat_button" icon="fa-bars" type="object" string="View reconciled entries">
            </button>
        </div>
        <label for="name" class="oe_edit_only" attrs="{'invisible':[('name','=','/')]}"/>
        <h1>
            <field name="name" readonly="True" attrs="{'invisible':[('name','=','/')]}"/>
        </h1>
        <group>
            <group>
                <field name="journal_id" options="{'no_open': True, 'no_create': True}"/>
                <field name="company_id" required="1" groups="base.group_multi_company"/>
                <field name="partner_id" domain="['|',('parent_id', '=', False), ('is_company', '=', True)]"/>
            </group>
            <group>
                <field name="date"/>
                <field name="ref"/>
                <field name="amount" invisible="1"/>
                <field name="currency_id" invisible="1"/>
            </group>
        </group>
        <notebook>
            <page string="Journal Items">
                <field name="line_ids" widget="one2many_list" context="{'line_ids': line_ids, 'journal_id': journal_id }">
                    <tree editable="bottom" string="Journal Items">
        This one -->    <field name="partner_id" domain="['|', ('parent_id', '=', False), ('is_company', '=', True)]"/>
                        <field name="account_id" domain="[('company_id', '=', parent.company_id), ('deprecated', '=', False)]"/>
                        <field name="name"/>
                        <field name="analytic_account_id" groups="analytic.group_analytic_accounting" domain="[('account_type', '=', 'normal')]"/>
                        <field name="amount_currency" groups="base.group_multi_currency"/>
                        <field name="company_currency_id" invisible="1"/>
                        <field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
                        <field name="debit" sum="Total Debit"/>
                        <field name="credit" sum="Total Credit"/>
                    </tree>
                </field>
                <field name="narration" colspan="4" placeholder="Add an internal note..." nolabel="1" height="50"/>
            </page>
         </notebook>
    </sheet>
</form>

python代码本身正在工作,因为我在其他字段中使用相同的代码。

有任何建议如何解决这个问题?

编辑:可以使用xml文件中的xpath方法修改字段,如下所示:

<xpath expr="//page/field[1]/tree/field[@name='partner_id']" position="replace">
                <field name="partner_id" options="{'no_open': True ,'no_create_edit': True}" domain="['|', ('parent_id', '=', False), ('is_company', '=', True)]"/>
            </xpath>

但是这条路径在我的python方法中不起作用,该字段不会改变。

有谁知道如何用python完成这项工作?

2 个答案:

答案 0 :(得分:0)

pagefield之间,只应有一个斜杠:

//page/field[1]/tree/field[@name='partner_id']

无论如何,如果某个xpath不起作用,请尝试尽可能清楚,也可以试试这个表达式:

/form/sheet/notebook/page[1]/field[@name='line_ids']/tree/field[@name='partner_id']

答案 1 :(得分:0)

你必须使用这个xpath ...

<xpath expr="//form//sheet//notebook//page//field[@name='line_ids']//
    tree//field[@name='partner_id']" position="replace"/>