Skip to content

Commit

Permalink
[IMP] w_s_product_availability: name html tags
Browse files Browse the repository at this point in the history
This improvement allow to style the availability and also to perform
other xpath on this element.

It allow also to move or add the availability elsewhere for design or
readability purposes.
  • Loading branch information
remytms committed Dec 14, 2023
1 parent 4a98206 commit e285b17
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions website_sale_product_availability/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
expr="//div[@itemscope='itemscope']//div[hasclass('product_price')]//b"
position="after"
>
<span t-if="product.inventory_availability == 'always'">
<!--
FIXME: This doesn't seem like good i18n practice to me. What
if another language says e.g. 'available $qty $uom'?
However, it's also done like this in
website_sale_stock.product_availability, so it's probably
fine.
-->
<t t-esc="product.sudo().virtual_available" /> <t t-esc="product.uom_name" /> available
</span>
<span t-if="product.inventory_availability == 'threshold'">
<t t-if="product.sudo().virtual_available &lt;= product.available_threshold">
<i class="fa fa-exclamation-triangle" title="Warning" role="img" aria-label="Warning"/>
<t t-esc="product.sudo().virtual_available" /> <t t-esc="product.uom_name" /> available
</t>
<t t-if="product.sudo().virtual_available &gt; product.available_threshold">In stock</t>
<span name="product_availability" class="product_availability">
<t t-call="website_sale_product_availability.product_availability" />
</span>
</xpath>
</template>

<template id="product_availability">
<span t-if="product.inventory_availability == 'always'">
<!--
FIXME: This doesn't seem like good i18n practice to me. What
if another language says e.g. 'available $qty $uom'?
However, it's also done like this in
website_sale_stock.product_availability, so it's probably
fine.
-->
<t t-esc="product.sudo().virtual_available" /> <t t-esc="product.uom_name" /> available
</span>
<span t-if="product.inventory_availability == 'threshold'">
<t t-if="product.sudo().virtual_available &lt;= product.available_threshold">
<i class="fa fa-exclamation-triangle" title="Warning" role="img" aria-label="Warning"/>
<t t-esc="product.sudo().virtual_available" /> <t t-esc="product.uom_name" /> available
</t>
<t t-if="product.sudo().virtual_available &gt; product.available_threshold">In stock</t>
</span>
</template>
</odoo>

0 comments on commit e285b17

Please sign in to comment.