This question has been flagged
2 Replies
5000 Views

Hello ,

I installed the module eCommerce in odoo v 11 ,  and i want to  modify the price  like only the prices that aren't equal to  zero will be displayed in the view . I'm just a beginner . I don't know how to make this condition in the xml file .

Avatar
Discard
Best Answer

Which view exactly?
You can use conditionals with "<t>"

I think it could be:

<t t-if="your_field != '0'">
<field name="your_field"/>
</t>

Check this post for more examples:
https://www.odoo.com/forum/help-1/question/qweb-if-else-condition-88902

Let me show you an example from one of my modules - it hides price for not logged users:

    <template id="product_price_hide1" inherit_id="website_sale.product_price" name="Product price hide for not logged" active="True">
      <xpath expr="//div[@class='product_price mt16']" position="replace">
  <t t-if="uid is not None">
    <!--if user is other than not logged -->
    <div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
          <h4 class="oe_price_h4 css_editable_mode_hidden">
              <span class="text-danger oe_default_price" style="text-decoration: line-through; white-space: nowrap;" t-esc="compute_currency(product.website_public_price)" t-options="{'widget': 'monetary', 'display_currency': website.get_current_pricelist().currency_id, 'from_currency': website.currency_id}" t-att-style="'text-decoration: line-through; white-space: nowrap; ' + '' if product.website_price_difference and website.get_current_pricelist().discount_policy == 'without_discount' else 'display: none;'"/>
              <b class="oe_price" style="white-space: nowrap;" t-esc="product.website_price" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
              <span itemprop="price" style="display:none;" t-esc="product.website_price"/>
              <span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>
          </h4>
         <h4 class="css_non_editable_mode_hidden decimal_precision" t-att-data-precision="str(product.currency_id.decimal_places)">
            <span t-field="product.lst_price" t-options="{                    &quot;widget&quot;: &quot;monetary&quot;,                    &quot;display_currency&quot;: product.currency_id,                }"/>
          </h4>
          <h4 class="hidden oe_not_available bg-warning">Product not available</h4>
      </div>
  </t>
  </xpath>
      </template>

Editing this <t t-if="uid is not None"> would be the answer. It could be:

<t t-if="product.website_price !=0 ">

So the price would be displayed only if it is different than 0. Remember to edit also the kanban view.
Mentioned module can be found in odoo ap store: \https://apps.odoo.com/apps/modules/11.0/hide_price_shop/ 

Avatar
Discard
Author Best Answer

Thank you Mr Piotr Cierkosz , let me  give you some details so as to understand my question very well:

in brief this is what i have in the "product"  View :

              <t t-call="website_sale.product_price"/>
<p t-if="len(product.product_variant_ids) &gt; 1" class="css_not_available_msg bg-danger" style="padding: 15px;">This combination does not exist.</p>
<a id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit" href="#">Add to Cart</a>
</div>
</form>
<hr t-if="product.description_sale"/>
<div class="o_not_editable">
<p t-field="product.description_sale" class="text-muted"/>
</div>
<hr/>
<p class="text-muted">
30-day money-back guarantee<br/>
Free Shipping in U.S.<br/>
Buy now, get in 2 days
</p>

  As you know this  operation  <t t-call="website_sale.product_price"/>  will call the QWeb view  "product_price"

here it is the view :

<?xml version="1.0"?>
<t t-name="website_sale.product_price">
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
<h4 class="oe_price_h4 css_editable_mode_hidden">
<span class="text-danger oe_default_price" style="text-decoration: line-through; white-space: nowrap;" t-esc="compute_currency(product.website_public_price)" t-options="{'widget': 'monetary', 'display_currency': website.get_current_pricelist().currency_id, 'from_currency': website.currency_id}" t-att-style="'text-decoration: line-through; white-space: nowrap; ' + '' if product.website_price_difference and website.get_current_pricelist().discount_policy == 'without_discount' else 'display: none;'"/>
<b class="oe_price" style="white-space: nowrap;" t-esc="product.website_price" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<span itemprop="price" style="display:none;" t-esc="product.website_price"/>
<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>
</h4>
<h4 class="css_non_editable_mode_hidden decimal_precision" t-att-data-precision="str(product.currency_id.decimal_places)">
<span t-field="product.lst_price" t-options="{ &quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: product.currency_id, }"/>

</h4>
<h4 class="hidden oe_not_available bg-warning">Product not available</h4>
</div>
</t>


At the end i tried some solutions like yours but the problem  is maybe i didn't add the condition in the right file or the right fields  .

Avatar
Discard

I have updated my response with an example

Author

Thank you so much