odoo 9 xpath 多个存在字段
odoo 9 xpath multiple existent field
我需要更改字段 "name" 的字符串,但该字段在视图中存在多个。那么我如何 xpath 所需的字段 "name"?
我用 ---------------------------------->
标记了它
我尝试了 expr="//group[6]/field[@name='name']" 和其他一些东西,但没有任何效果。
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<form string="Partners">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" groups="base.group_no_one"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/>
</button>
</div>
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
<div class="oe_title">
<field name="is_company" invisible="1"/>
<field name="company_type" widget="radio"
class="oe_edit_only"
on_change="on_change_company_type(company_type)"
options="{'horizontal': true}"/>
<h1>
<field name="name" default_focus="1" placeholder="Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
</h1>
<div class="o_row">
<field name="parent_id"
placeholder="Company"
domain="[('is_company', '=', True)]" context="{'default_is_company': True, 'default_supplier': supplier, 'default_customer': customer}"
attrs="{'invisible': [('is_company','=', True),('parent_id', '=', False)]}"
on_change="onchange_parent_id(parent_id)"/>
</div>
</div>
<group>
<group>
<field name="type" attrs="{'invisible': [('parent_id','=', False)]}" groups="base.group_no_one"/>
<label for="street" string="Address"/>
<div class="o_address_format">
<div class="oe_edit_only">
<button name="open_parent" type="object" string="(edit)" class="oe_link"
attrs="{'invisible': ['|', ('parent_id', '=', False), ('type', '!=', 'contact')]}"/>
</div>
<field name="street" placeholder="Street..." class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="street2" placeholder="Street 2..." class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="city" placeholder="City" class="o_address_city"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}' on_change="onchange_state(state_id)"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}" context="{'country_id': country_id, 'zip': zip}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
</div>
<field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
</group>
<group>
<field name="function" placeholder="e.g. Sales Director"
attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="fax"/>
<field name="user_ids" invisible="1"/>
<field name="email" widget="email" attrs="{'required': [('user_ids','!=', [])]}"/>
<field name="title" options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="lang"/>
<field name="category_id" widget="many2many_tags" placeholder="Tags..."/>
</group>
</group>
<notebook colspan="4">
<page string="Contacts & Addresses" autofocus="autofocus">
<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_lang': lang,}">
<kanban>
<field name="color"/>
<field name="name"/>
<field name="title"/>
<field name="type"/>
<field name="email"/>
<field name="parent_id"/>
<field name="is_company"/>
<field name="function"/>
<field name="phone"/>
<field name="street"/>
<field name="street2"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="mobile"/>
<field name="fax"/>
<field name="state_id"/>
<field name="image"/>
<field name="lang"/>
<templates>
<t t-name="kanban-box">
<t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
<div t-att-class="color + (record.title.raw_value == 1 ? ' oe_kanban_color_alert' : '') + ' oe_kanban_global_click'">
<a t-if="!read_only_mode" type="delete" class="fa fa-times pull-right"/>
<div class="o_kanban_image">
<img t-if="record.image.raw_value" t-att-src="'data:image/png;base64,'+record.image.raw_value"/>
<t t-if="!record.image.raw_value">
<img t-if="record.type.raw_value === 'delivery'" t-att-src='_s + "/base/static/src/img/truck.png"'/>
<img t-if="record.type.raw_value === 'invoice'" t-att-src='_s + "/base/static/src/img/money.png"'/>
<t t-if="record.type.raw_value !== 'invoice' && record.type.raw_value !== 'delivery'">
<img t-if="record.is_company.raw_value === true" t-att-src='_s + "/base/static/src/img/company_image.png"'/>
<img t-if="record.is_company.raw_value === false" t-att-src='_s + "/base/static/src/img/avatar.png"'/>
</t>
</t>
</div>
<div class="oe_kanban_details">
<field name="name"/>
<div t-if="record.function.raw_value"><field name="function"/></div>
<div t-if="record.email.raw_value"><field name="email"/></div>
<div t-if="record.type.raw_value != 'contact'">
<div>
<field name="zip"/>
<field name="city"/>
</div>
<field t-if="record.state_id.raw_value" name="state_id"/>
<field name="country_id"/>
</div>
<div t-if="record.phone.raw_value">Phone: <field name="phone"/></div>
<div t-if="record.mobile.raw_value">Mobile: <field name="mobile"/></div>
<div t-if="record.fax.raw_value">Fax: <field name="fax"/></div>
</div>
</div>
</t>
</templates>
</kanban>
<form string="Contact / Address">
<sheet>
<field name="type" required="1" widget="radio" options="{'horizontal': true}"/>
<hr/>
<group>
<group attrs="{'invisible': [('type','=', 'contact')]}">
<label for="street" string="Address"/>
<div>
<div class="o_address_format" name="div_address">
<field name="street" placeholder="Street..." class="o_address_street"/>
<field name="street2" placeholder="Street 2..." class="o_address_street"/>
<field name="city" placeholder="City" class="o_address_city"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}' on_change="onchange_state(state_id)" context="{'country_id': country_id, 'zip': zip}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
</div>
</div>
</group>
<group>
-----------------------------><field name="name" string="Contact Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
<field name="title" placeholder="e.g. Mr."
attrs="{'invisible': [('type','<>', 'contact')]}"/>
<field name="function" placeholder="e.g. Sales Director"
attrs="{'invisible': [('type','<>', 'contact')]}"/>
<field name="email"/>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="comment" placeholder="internal note..."/>
</group>
</group>
<field name="supplier" invisible="True"/>
<field name="customer" invisible="True"/>
<field name="lang" invisible="True"/>
</sheet>
</form>
</field>
</page>
<page name='internal_notes' string="Internal Notes">
<field name="comment" placeholder="Internal note..."/>
</page>
<page name='sales_purchases' string="Sales & Purchases">
<group name="container_row_2">
<group string="Sale" name="sale">
<field name="customer"/>
<field name="user_id"
context="{'default_groups_ref': ['base.group_partner_manager']}"/>
</group>
<group string="Purchase" name="purchase">
<field name="supplier"/>
</group>
<group string="Misc">
<field name="ref"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
我没试过这个,但我认为它会起作用
//notebook/page/field[@name='child_ids']/form//field[@name='name']
您可以使用以下方法完成。
<xpath expr="//field[@name='child_ids']/form/sheet/group/group[2]/field[@name='name']" position="attributes">
<attribute name='string'>Your String</attribute>
</xpath>
这可能对你有帮助。
我需要更改字段 "name" 的字符串,但该字段在视图中存在多个。那么我如何 xpath 所需的字段 "name"? 我用 ---------------------------------->
标记了它我尝试了 expr="//group[6]/field[@name='name']" 和其他一些东西,但没有任何效果。
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<form string="Partners">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" groups="base.group_no_one"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/>
</button>
</div>
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
<div class="oe_title">
<field name="is_company" invisible="1"/>
<field name="company_type" widget="radio"
class="oe_edit_only"
on_change="on_change_company_type(company_type)"
options="{'horizontal': true}"/>
<h1>
<field name="name" default_focus="1" placeholder="Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
</h1>
<div class="o_row">
<field name="parent_id"
placeholder="Company"
domain="[('is_company', '=', True)]" context="{'default_is_company': True, 'default_supplier': supplier, 'default_customer': customer}"
attrs="{'invisible': [('is_company','=', True),('parent_id', '=', False)]}"
on_change="onchange_parent_id(parent_id)"/>
</div>
</div>
<group>
<group>
<field name="type" attrs="{'invisible': [('parent_id','=', False)]}" groups="base.group_no_one"/>
<label for="street" string="Address"/>
<div class="o_address_format">
<div class="oe_edit_only">
<button name="open_parent" type="object" string="(edit)" class="oe_link"
attrs="{'invisible': ['|', ('parent_id', '=', False), ('type', '!=', 'contact')]}"/>
</div>
<field name="street" placeholder="Street..." class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="street2" placeholder="Street 2..." class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="city" placeholder="City" class="o_address_city"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}' on_change="onchange_state(state_id)"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}" context="{'country_id': country_id, 'zip': zip}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
</div>
<field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
</group>
<group>
<field name="function" placeholder="e.g. Sales Director"
attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="fax"/>
<field name="user_ids" invisible="1"/>
<field name="email" widget="email" attrs="{'required': [('user_ids','!=', [])]}"/>
<field name="title" options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="lang"/>
<field name="category_id" widget="many2many_tags" placeholder="Tags..."/>
</group>
</group>
<notebook colspan="4">
<page string="Contacts & Addresses" autofocus="autofocus">
<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_lang': lang,}">
<kanban>
<field name="color"/>
<field name="name"/>
<field name="title"/>
<field name="type"/>
<field name="email"/>
<field name="parent_id"/>
<field name="is_company"/>
<field name="function"/>
<field name="phone"/>
<field name="street"/>
<field name="street2"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="mobile"/>
<field name="fax"/>
<field name="state_id"/>
<field name="image"/>
<field name="lang"/>
<templates>
<t t-name="kanban-box">
<t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
<div t-att-class="color + (record.title.raw_value == 1 ? ' oe_kanban_color_alert' : '') + ' oe_kanban_global_click'">
<a t-if="!read_only_mode" type="delete" class="fa fa-times pull-right"/>
<div class="o_kanban_image">
<img t-if="record.image.raw_value" t-att-src="'data:image/png;base64,'+record.image.raw_value"/>
<t t-if="!record.image.raw_value">
<img t-if="record.type.raw_value === 'delivery'" t-att-src='_s + "/base/static/src/img/truck.png"'/>
<img t-if="record.type.raw_value === 'invoice'" t-att-src='_s + "/base/static/src/img/money.png"'/>
<t t-if="record.type.raw_value !== 'invoice' && record.type.raw_value !== 'delivery'">
<img t-if="record.is_company.raw_value === true" t-att-src='_s + "/base/static/src/img/company_image.png"'/>
<img t-if="record.is_company.raw_value === false" t-att-src='_s + "/base/static/src/img/avatar.png"'/>
</t>
</t>
</div>
<div class="oe_kanban_details">
<field name="name"/>
<div t-if="record.function.raw_value"><field name="function"/></div>
<div t-if="record.email.raw_value"><field name="email"/></div>
<div t-if="record.type.raw_value != 'contact'">
<div>
<field name="zip"/>
<field name="city"/>
</div>
<field t-if="record.state_id.raw_value" name="state_id"/>
<field name="country_id"/>
</div>
<div t-if="record.phone.raw_value">Phone: <field name="phone"/></div>
<div t-if="record.mobile.raw_value">Mobile: <field name="mobile"/></div>
<div t-if="record.fax.raw_value">Fax: <field name="fax"/></div>
</div>
</div>
</t>
</templates>
</kanban>
<form string="Contact / Address">
<sheet>
<field name="type" required="1" widget="radio" options="{'horizontal': true}"/>
<hr/>
<group>
<group attrs="{'invisible': [('type','=', 'contact')]}">
<label for="street" string="Address"/>
<div>
<div class="o_address_format" name="div_address">
<field name="street" placeholder="Street..." class="o_address_street"/>
<field name="street2" placeholder="Street 2..." class="o_address_street"/>
<field name="city" placeholder="City" class="o_address_city"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}' on_change="onchange_state(state_id)" context="{'country_id': country_id, 'zip': zip}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
</div>
</div>
</group>
<group>
-----------------------------><field name="name" string="Contact Name" attrs="{'required' : [('type', '=', 'contact')]}"/>
<field name="title" placeholder="e.g. Mr."
attrs="{'invisible': [('type','<>', 'contact')]}"/>
<field name="function" placeholder="e.g. Sales Director"
attrs="{'invisible': [('type','<>', 'contact')]}"/>
<field name="email"/>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="comment" placeholder="internal note..."/>
</group>
</group>
<field name="supplier" invisible="True"/>
<field name="customer" invisible="True"/>
<field name="lang" invisible="True"/>
</sheet>
</form>
</field>
</page>
<page name='internal_notes' string="Internal Notes">
<field name="comment" placeholder="Internal note..."/>
</page>
<page name='sales_purchases' string="Sales & Purchases">
<group name="container_row_2">
<group string="Sale" name="sale">
<field name="customer"/>
<field name="user_id"
context="{'default_groups_ref': ['base.group_partner_manager']}"/>
</group>
<group string="Purchase" name="purchase">
<field name="supplier"/>
</group>
<group string="Misc">
<field name="ref"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
我没试过这个,但我认为它会起作用
//notebook/page/field[@name='child_ids']/form//field[@name='name']
您可以使用以下方法完成。
<xpath expr="//field[@name='child_ids']/form/sheet/group/group[2]/field[@name='name']" position="attributes">
<attribute name='string'>Your String</attribute>
</xpath>
这可能对你有帮助。