我尝试使用xpath替换标签。但这没有用,我不知道怎么了?我只想删除条件t-if =“ record.planned_revenue.raw_value”。我尝试了这篇文章:https://odedrabhavesh.blogspot.com/2015/01/how-to-replace-kanban-image-in-odoo.html enter code here
和https://www.odoo.com/forum/help-1/question/how-to-inherit-from-a-kanban-view-in-odoo9-102568
但是它们没有达到我的期望。
这是原始模板:
<record id="crm_case_kanban_view_leads" model="ir.ui.view">
<field name="name">crm.lead.kanban.lead</field>
<field name="model">crm.lead</field>
<field name="arch" type="xml">
<kanban default_group_by="stage_id" class="o_kanban_small_column o_opportunity_kanban"
on_create="crm.create_opportunity_simplified">
<field name="stage_id"
options='{"group_by_tooltip": {"requirements": "Description", "legend_priority": "Use of stars"}}'/>
<field name="color"/>
<field name="priority"/>
<field name="planned_revenue"/>
<field name="kanban_state"/>
<field name="date_action"/>
<field name="user_email"/>
<field name="user_id"/>
<field name="partner_address_email"/>
<field name="message_needaction_counter"/>
<field name="tag_ids"/>
<field name="partner_id"/>
<field name="title_action"/>
<field name="active"/>
<field name="company_currency"/>
<templates>
<field name="date_deadline"/>
<t t-name="kanban-box">
<div t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click">
<div class="o_dropdown_kanban dropdown">
<a class="dropdown-toggle btn" data-toggle="dropdown" href="#">
<span class="fa fa-bars fa-lg"/>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<t t-if="widget.editable">
<li>
<a type="edit">Edit</a>
</li>
</t>
<t t-if="widget.deletable">
<li>
<a type="delete">Delete</a>
</li>
</t>
<li t-if="! record.active.value">
<a name="action_set_active" type="object">Unarchive</a>
</li>
<li t-if="record.active.value">
<a name="action_set_unactive" type="object">Archive</a>
</li>
<li>
<ul class="oe_kanban_colorpicker" data-field="color"/>
</li>
</ul>
</div>
<div class="oe_kanban_content">
<div>
<field name="tag_ids"/>
</div>
<div>
<strong>
<field name="name"/>
</strong>
</div>
<div class="text-muted">
<t t-if="record.planned_revenue.raw_value">
<field name="planned_revenue" widget="monetary"
options="{'currency_field': 'company_currency'}"/>
<span t-if="record.partner_id.value">,</span>
</t>
<span t-if="record.partner_id.value">
<t t-esc="record.partner_id.value"/>
</span>
</div>
<div class="o_kanban_footer">
<field name="priority" widget="priority" groups="base.group_user"/>
<t t-if="record.message_needaction_counter.raw_value">
<span class='oe_kanban_mail_new' title='Unread Messages'>
<i class='fa fa-comments'/>
<t t-raw="record.message_needaction_counter.raw_value"/>
</span>
</t>
<div>
<a name="%(crm.crm_activity_log_action)d" type="action"
t-if="record.kanban_state.raw_value!='grey'">
<span
t-att-title="record.date_action.value + ': '+ record.title_action.value"
t-attf-class="oe_kanban_status oe_kanban_status_#{record.kanban_state.raw_value}"/>
</a>
<a name="%(crm.crm_activity_schedule_action)d" type="action"
t-if="record.kanban_state.raw_value=='grey'">
<span
class="oe_kanban_status oe_kanban_status_grey"/>
</a>
<img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)"
t-att-title="record.user_id.value" width="24" height="24"
class="oe_kanban_avatar pull-right"/>
</div>
</div>
</div>
<div class="oe_clear"></div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
我想替换为:
<t t-if="record.planned_revenue.raw_value">
作者:
<t>
这是我的习惯:
<record id="crm_case_kanban_view_leads_custom" model="ir.ui.view">
<field name="name">crm.lead.kanban.lead.extends</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_kanban_view_leads"/>
<field name="arch" type="xml">
<xpath expr='//kanban/templates/t/div/div/div/t[0]' position="replace">
<t>
<field name="planned_revenue" widget="monetary"
options="{'currency_field': 'company_currency'}"/>
<span t-if="record.partner_id.value">,</span>
</t>
</xpath>
</field>
</record>
它不起作用,怎么了?
答案 0 :(得分:0)
我已经使用xpath解决了这个问题:
<xpath expr="//t/div/div[@class='oe_kanban_content']/div[@class='text-muted']/t" position="replace">
答案 1 :(得分:0)
您的代码将无法工作,因为您基本上是在替换整个<t>
内容,而不仅仅是属性。除非您打算将replace
与原始内容一起使用,否则这是不明智的做法。
您只需要选择要更改的属性:
<t t-if="record.planned_revenue.raw_value" position="attributes">
<attribute name="t-if">True</attribute>
</t>
或使用经典的xpath
语法:
<xpath expr="//t[@t-if='record.planned_revenue.raw_value']" position="attributes">
<attribute name="t-if">True</attribute>
</xpath>