xpath reference in Odoo 15 and 16, how to resolve it

52 views Asked by At

ver.15 template:

<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 expression to above template which works fine:

<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>

this will open a Modal page.

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

there are changes in ver.16 on Odoo provided modules.

ver.16 template:

<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 expression:

how i can use xpath for this in ver.16? i tried below but it is showing error while Upgrading module through UI (Apps).

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

Error:

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

kindly guide to resolve this. regards

1

There are 1 answers

2
CZoellner On

A pragmatic way to set the redirect_url variable to the desired one would be by setting it again right after the first creation of it:

<xpath expr="//t[@t-set='redirect_url']" position="after">
    <t t-set="redirect_url" t-value="my desired url in python expression"/>
</xpath>