Odoo 15 和 16 中的 xpath 引用,如何解决

问题描述 投票:0回答:1

ver.15 模板:

<a role="button" t-if="website_sale_order and website_sale_order.website_order_line" class="btn btn-primary float-right d-none d-xl-inline-block" href="/shop/checkout?express=1">
  <span class="">Process Checkout</span>
  <span class="fa fa-chevron-right" />
</a>

ver.15 xpath 表达式到上面的模板,效果很好:

<template id="zhen_product_cart_line_validate_button" inherit_id="website_sale.cart">
    <xpath expr="//a[@href='/shop/checkout?express=1']" position="attributes">
         <attribute name="t-att-style">'' if website.zhen_products_validation() else 'display:none;'</attribute>
    </xpath>
</template>

这将打开一个模态页面。

============================================

Odoo 提供的模块在 16 版中有变化。

ver.16 模板:

<t t-set="redirect_url" t-value="'/web/login?redirect=/shop/checkout' if redirect_to_sign_in else '/shop/checkout?express=1'"/>

ver.16 xpath 表达式:

我如何在版本 16 中使用 xpath 来实现此目的? 我尝试了下面,但通过 UI(应用程序)升级模块时显示错误。

<xpath expr="//t[@t-value='/shop/checkout?express=1']" position="attributes">

错误

Element '<xpath expr="//t[@t-value=&#39;/shop/checkout?express=1&#39;]">' cannot be located in parent view

请指导解决此问题。 问候

xpath odoo odoo-16
1个回答
0
投票

redirect_url
变量设置为所需变量的一种实用方法是在第一次创建它后立即再次设置它:

<xpath expr="//t[@t-set='redirect_url']" position="after">
    <t t-set="redirect_url" t-value="my desired url in python expression"/>
</xpath>
© www.soinside.com 2019 - 2024. All rights reserved.