Browse Source

Oct 10: [FIX] Bug fixed 'website_hide_button'

18.0
Risvana Cybro 4 days ago
parent
commit
cd863f33ad
  1. 4
      website_hide_button/__manifest__.py
  2. 36
      website_hide_button/controllers/website_sale.py
  3. 5
      website_hide_button/doc/RELEASE_NOTES.md
  4. 94
      website_hide_button/models/res_config_settings.py
  5. 34
      website_hide_button/views/product_templates.xml
  6. 79
      website_hide_button/views/res_config_settings_views.xml
  7. 6
      website_hide_button/views/shop_templates.xml
  8. 11
      website_hide_button/views/website_sale_comparison.xml

4
website_hide_button/__manifest__.py

@ -21,7 +21,7 @@
###############################################################################
{
'name': "Hide Price, Add To Cart And Quantity Button In Website",
'version': '18.0.1.0.1',
'version': '18.0.1.0.2',
'category': 'Website',
'summary': """Hide Price, Add To Cart and Quantity button for guest
users""",
@ -32,7 +32,7 @@
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
'website': 'https://www.cybrosys.com',
'depends': ['website_sale'],
'depends': ['website_sale','website_sale_comparison'],
'data': [
'views/product_templates.xml',
'views/shop_templates.xml',

36
website_hide_button/controllers/website_sale.py

@ -26,6 +26,30 @@ from odoo.addons.website_sale.controllers.main import WebsiteSale
class WebsiteSaleInherit(WebsiteSale):
"""class to hide price, add to cart and quantity"""
def should_show_price_for_current_website(self):
"""
Check if price should be SHOWN for the current website
Returns: True if price should be shown, False if should be hidden
"""
# If hide_price setting is not enabled, show price
if not request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'):
return True
hide_type = request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_type')
website_ids_param = request.env['ir.config_parameter'].sudo().get_param('website_hide_button.website_ids') or ''
website_ids = [int(w) for w in website_ids_param.split(',') if w]
current_website = request.env['website'].get_current_website()
if hide_type == 'all':
# Hide price on ALL websites
return False
else:
# Hide price only on specific websites
if current_website.id in website_ids:
return False # Hide on this website
else:
return True # Show on other websites
@http.route([
'''/shop''',
'''/shop/page/<int:page>''',
@ -39,9 +63,9 @@ class WebsiteSaleInherit(WebsiteSale):
res = super().shop(page, category, search, min_price,
max_price, ppg, **post)
res.qcontext.update({
'login_user': True if request.env.user._is_public() and request.env[
'ir.config_parameter'].sudo().get_param(
'website_hide_button.hide_cart') else False
'login_user': request.env.user._is_public() and request.env[
'ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart'),
'show_price': self.should_show_price_for_current_website() # True = show, False = hide
})
return res
@ -51,6 +75,7 @@ class WebsiteSaleInherit(WebsiteSale):
category,
search,
**kwargs)
res['show_price'] =self.should_show_price_for_current_website()
res['login_user'] = True if request.env.user._is_public() and \
request.env[
'ir.config_parameter'].sudo().get_param(
@ -63,10 +88,7 @@ class WebsiteSaleInherit(WebsiteSale):
creation will be disabled """
user = http.request.env.user
if (
not user._is_public() or user._is_public() and not request.env.user._is_public() and not
request.env[
'ir.config_parameter'].sudo().get_param(
'website_hide_button.hide_cart')) and user.has_group(
not user._is_public() or user._is_public() and not request.env.user._is_public() and self.should_show_price_for_current_website()) and user.has_group(
'base.group_portal') or \
user.has_group('base.group_user'):
res = super(WebsiteSaleInherit, self).shop_payment(**post)

5
website_hide_button/doc/RELEASE_NOTES.md

@ -14,3 +14,8 @@
#### Version 18.0.1.0.2
#### UPDT
- Commit for bug fix
#### 07.10.2025
#### Version 18.0.1.0.3
#### UPDT
- Updated the workflow to include new options in Website Settings, with support for multiple websites.

94
website_hide_button/models/res_config_settings.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
from odoo import api, fields, models
from odoo import api, fields, models, Command
class ResConfigSettings(models.TransientModel):
@ -28,28 +28,76 @@ class ResConfigSettings(models.TransientModel):
"""
_inherit = 'res.config.settings'
hide_price = fields.Boolean(string='Hide Price',
config_parameter='website_hide_button.hide_price',
help="If enabled, the price of product will not be visible to guest users in website")
hide_cart = fields.Boolean(string='Hide Cart',
config_parameter='website_hide_button.hide_cart',
help="If enabled, the Add to Cart button and Cart Icon will be visible to guest users")
hide_price = fields.Boolean(
string='Hide Price',
config_parameter='website_hide_button.hide_price',
help="If enabled, the price of product will not be visible to guest users in website"
)
hide_type = fields.Selection(
[('all', 'All Websites'), ('selected', 'Selected Websites')],
string='Apply To',
config_parameter='website_hide_button.hide_type',
default='all',
help="Choose whether to apply the hide settings to all websites or only selected websites"
)
# Changed from Many2many to Char to store comma-separated website IDs
website_ids = fields.Many2many(
'website',
string='Websites',
help="Select the websites where price and cart should be hidden for guest users"
)
hide_cart = fields.Boolean(
string='Hide Cart',
config_parameter='website_hide_button.hide_cart',
help="If enabled, the Add to Cart button and Cart Icon will be hidden from guest users"
)
def set_values(self):
"""Method for setting the parameters"""
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param(
'website_hide_button.hide_price', self.hide_price)
self.env['ir.config_parameter'].sudo().set_param(
'website_hide_button.hide_cart', self.hide_cart)
params = self.env['ir.config_parameter'].sudo()
params.set_param('website_hide_button.hide_price', self.hide_price)
params.set_param('website_hide_button.hide_cart', self.hide_cart)
params.set_param('website_hide_button.hide_type', self.hide_type)
# Store website_ids as comma-separated string
website_ids_str = ','.join(map(str, self.website_ids.ids)) if self.website_ids else ''
params.set_param('website_hide_button.website_ids', website_ids_str)
@api.model
def get_values(self):
"""Method for getting the parameters"""
res = super(ResConfigSettings, self).get_values()
params = self.env['ir.config_parameter'].sudo()
hide_price = params.get_param('website_hide_button.hide_price', default=False)
hide_cart = params.get_param('website_hide_button.hide_cart', default=False)
hide_type = params.get_param('website_hide_button.hide_type', default='all')
website_ids_str = params.get_param('website_hide_button.website_ids', default='')
# Convert string to list of integers
website_ids = []
if website_ids_str:
try:
website_ids = [int(x) for x in website_ids_str.split(',') if x]
except ValueError:
website_ids = []
res.update({
'hide_price': hide_price,
'hide_cart': hide_cart,
'hide_type': hide_type,
'website_ids': [(6, 0, website_ids)],
})
return res
@api.model
def get_smartsupp_details(self):
"""Method for get value"""
hide_price = self.env['ir.config_parameter'].sudo().get_param(
'website_hide_button.hide_price')
hide_cart = self.env['ir.config_parameter'].sudo().get_param(
'website_hide_button.hide_cart')
def get_hide_settings(self):
"""Method to get hide settings for current website"""
params = self.env['ir.config_parameter'].sudo()
hide_price = params.get_param('website_hide_button.hide_price')
hide_cart = params.get_param('website_hide_button.hide_cart')
return {
'hide_price': hide_price,
'hide_cart': hide_cart,
@ -57,6 +105,14 @@ class ResConfigSettings(models.TransientModel):
@api.onchange('hide_price')
def _onchange_hide_price(self):
"""Auto-enable hide_cart when hide_price is enabled"""
if self.hide_price:
self.env['ir.config_parameter'].sudo().set_param(
'website_hide_button.hide_cart', True)
self.hide_cart = True
else:
self.hide_cart = False
@api.onchange('hide_type')
def _onchange_hide_type(self):
"""Clear website_ids when changing to 'all' using Command format"""
if self.hide_type == 'all':
self.website_ids = [Command.clear()]

34
website_hide_button/views/product_templates.xml

@ -12,8 +12,7 @@
<xpath expr="//a[@id='add_to_cart']" position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
@ -27,8 +26,7 @@
<template id="product_price_hide" inherit_id="website_sale.product_price">
<xpath expr="//div[@itemprop='offers']" position="attributes">
<attribute name="t-if">not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
@ -37,15 +35,14 @@
inherit_id="website_sale.header_cart_link">
<xpath expr="//a[@href='/shop/cart']" position="attributes">
<attribute name="t-if">not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
<!-- Hide details section in search bar for hide price -->
<template id="search_hide" inherit_id="website_sale.search">
<xpath expr="//t[@t-set='display_detail']" position="replace">
<t t-if="not request.env.user._is_public() or (request.env.user._is_public() and not request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))">
<t t-if="not request.env.user._is_public() or (request.env.user._is_public() and show_price)">
<t t-set="display_detail" t-valuef="true"/>
</t>
<t t-else="">
@ -60,8 +57,7 @@
position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
@ -72,8 +68,7 @@
<attribute name="t-if">
product.product_variant_ids and (not
request.env.user._is_public() or (request.env.user._is_public()
and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price')))
and show_price))
</attribute>
</xpath>
<xpath expr="//div[hasclass('o_wsale_product_btn')]"
@ -81,8 +76,7 @@
<attribute name="t-if">
product.product_variant_ids and (not
request.env.user._is_public() or (request.env.user._is_public()
and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price')))
and show_price))
</attribute>
</xpath>
</template>
@ -93,8 +87,7 @@
position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
@ -104,8 +97,7 @@
<xpath expr="//input[@name='search']" position="attributes">
<attribute name="t-att-data-display-price">
website and (not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price')))
(request.env.user._is_public() and show_price))
</attribute>
</xpath>
</template>
@ -114,8 +106,7 @@
inherit_id="website_sale.price_dynamic_filter_template_product_product">
<xpath expr="//span[hasclass('fw-bold')]" position="attributes">
<attribute name="t-if">(not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price')))
(request.env.user._is_public() and show_price))
</attribute>
</xpath>
</template>
@ -125,9 +116,8 @@
<xpath expr="//t[@t-name='website_sale.badge_extra_price']"
position="attributes">
<attribute name="t-if">not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
</odoo>
</odoo>

79
website_hide_button/views/res_config_settings_views.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Inherited to add extra fields -->
<record id="res_config_settings_view_form" model="ir.ui.view">
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">
res.config.settings.view.form.inherit.website.hide.button
</field>
@ -9,16 +9,89 @@
<field name="inherit_id" ref="website.res_config_settings_view_form"/>
<field name="arch" type="xml">
<block id="sale_product_catalog_settings" position="inside">
<!-- Hide Product Prices Setting -->
<setting id="show_price_setting"
string="Hide Product Prices for Guests"
help="Hides product prices from guest users in Website">
<field name="hide_price"/>
<!-- Content group that appears when hide_price is enabled -->
<div class="content-group mt16" invisible="hide_price == False">
<!-- Apply To Selection Field -->
<div class="row mt16">
<label for="hide_type" class="col-lg-3 o_light_label" string="Apply To"/>
<field name="hide_type" class="col-lg-9" widget="radio" options="{'horizontal': true}"/>
</div>
<!-- Website Selection Field (visible only when hide_type = 'selected') -->
<div class="row mt16" invisible="hide_type != 'selected'">
<label for="website_ids" class="col-lg-3 o_light_label" string="Select Websites"/>
<field name="website_ids"
class="col-lg-9"
widget="many2many_tags"
placeholder="Select websites where prices should be hidden..."
required="hide_type == 'selected'"/>
</div>
<!-- Info message for All Websites -->
<div class="alert alert-info mt16" invisible="hide_type != 'all'">
<i class="fa fa-info-circle"/>
<span> Product prices and cart will be hidden for guest users on <strong>all websites</strong>.</span>
</div>
<!-- Info message for Selected Websites -->
<div class="alert alert-info mt16" invisible="hide_type != 'selected' or not website_ids">
<i class="fa fa-info-circle"/>
<span> Product prices and cart will be hidden for guest users on <strong>selected websites only</strong>.</span>
</div>
<!-- Warning message when no websites selected -->
<div class="alert alert-warning mt16" invisible="hide_type != 'selected' or website_ids">
<i class="fa fa-warning"/>
<span> Please select at least one website to apply this feature.</span>
</div>
</div>
</setting>
<setting id="show_cart_setting" string="Hide Cart from Guests"
<!-- Hide Cart Setting -->
<setting id="show_cart_setting"
string="Hide Cart from Guests"
help="Hide 'Add to Cart' button and Cart quick view for Guest users">
<field name="hide_cart" readonly="hide_price"/>
<field name="hide_cart" readonly="hide_price == True"/>
<!-- Info note about automatic enabling -->
<div class="text-muted mt8" invisible="hide_price == False">
<small>
<i class="fa fa-info-circle"/>
This option is automatically enabled when "Hide Product Prices" is enabled.
</small>
</div>
</setting>
</block>
</field>
</record>
<!-- <record id="res_config_settings_view_form" model="ir.ui.view">-->
<!-- <field name="name">-->
<!-- res.config.settings.view.form.inherit.website.hide.button-->
<!-- </field>-->
<!-- <field name="model">res.config.settings</field>-->
<!-- <field name="inherit_id" ref="website.res_config_settings_view_form"/>-->
<!-- <field name="arch" type="xml">-->
<!-- <block id="sale_product_catalog_settings" position="inside">-->
<!-- <setting id="show_price_setting"-->
<!-- string="Hide Product Prices for Guests"-->
<!-- help="Hides product prices from guest users in Website">-->
<!-- <field name="hide_price"/>-->
<!-- </setting>-->
<!-- -->
<!-- <setting id="show_cart_setting" string="Hide Cart from Guests"-->
<!-- help="Hide 'Add to Cart' button and Cart quick view for Guest users">-->
<!-- <field name="hide_cart" readonly="hide_price"/>-->
<!-- </setting>-->
<!-- </block>-->
<!-- </field>-->
<!-- </record>-->
</odoo>

6
website_hide_button/views/shop_templates.xml

@ -5,10 +5,8 @@
<xpath expr="//div[hasclass('product_price')]" position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or (
request.env.user._is_public() and not request.env[
'ir.config_parameter'].sudo().get_param(
'website_hide_button.hide_price'))
request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
</odoo>
</odoo>

11
website_hide_button/views/website_sale_comparison.xml

@ -5,15 +5,13 @@
<xpath expr='//td[@t-foreach="products"]//span[@class="o_comparison_price"][2]' position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
<xpath expr='//form[hasclass("o_add_cart_form_compare")]' position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
@ -22,9 +20,8 @@
<xpath expr='//span[1]' position="attributes">
<attribute name="t-if">
not request.env.user._is_public() or
(request.env.user._is_public() and not
request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))
(request.env.user._is_public() and show_price)
</attribute>
</xpath>
</template>
</odoo>
</odoo>
Loading…
Cancel
Save