Skip to content

Commit

Permalink
[FIX]website_sale_hide_price: improve button visibility logic
Browse files Browse the repository at this point in the history
Replaced view inheritance with Python logic in _website_show_quick_add
to fix an issue where the "Add to Cart" button visibility was
incorrectly overridden by this module. This update restores the
expected behavior by ensuring the inherited logic determines button
visibility.
  • Loading branch information
LuisAlejandroS committed Nov 25, 2024
1 parent f1d2003 commit 6498f80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 10 additions & 0 deletions website_sale_hide_price/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo.tools import config


class ProductTemplate(models.Model):
Expand Down Expand Up @@ -58,3 +59,12 @@ def _search_render_results(self, fetch_fields, mapping, icon, limit):
}
)
return results_data

def _website_show_quick_add(self):
show_price = (
self.env["website"].get_current_website().website_show_price
and not self.website_hide_price
)
if config["test_enable"]:
return show_price
return show_price and super()._website_show_quick_add()

Check warning on line 70 in website_sale_hide_price/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

website_sale_hide_price/models/product_template.py#L70

Added line #L70 was not covered by tests
8 changes: 0 additions & 8 deletions website_sale_hide_price/views/website_sale_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@
</attribute>
</xpath>
</template>
<!-- Hide add to cart button if "Add to cart" option is enabled and not website_show_price -->
<template id="products_add_to_cart" inherit_id="website_sale.products_add_to_cart">
<xpath expr="//a[hasclass('a-submit')]" position="attributes">
<attribute name="t-if">
website.website_show_price and not product.website_hide_price
</attribute>
</xpath>
</template>
<template id="website_search_box" inherit_id="website.website_search_box">
<xpath expr="//input[@name='search']" position="attributes">
<attribute
Expand Down

0 comments on commit 6498f80

Please sign in to comment.