diff --git a/website_hide_button/__manifest__.py b/website_hide_button/__manifest__.py index 0c41fc072..b8bcec4dc 100644 --- a/website_hide_button/__manifest__.py +++ b/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', diff --git a/website_hide_button/controllers/website_sale.py b/website_hide_button/controllers/website_sale.py index f62a8f6cf..b145f2551 100644 --- a/website_hide_button/controllers/website_sale.py +++ b/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/''', @@ -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) diff --git a/website_hide_button/doc/RELEASE_NOTES.md b/website_hide_button/doc/RELEASE_NOTES.md index 6b59afcb7..c8adebad0 100644 --- a/website_hide_button/doc/RELEASE_NOTES.md +++ b/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. diff --git a/website_hide_button/models/res_config_settings.py b/website_hide_button/models/res_config_settings.py index 202ac3a87..4bbc6bfae 100755 --- a/website_hide_button/models/res_config_settings.py +++ b/website_hide_button/models/res_config_settings.py @@ -19,7 +19,7 @@ # If not, see . # ################################################################################ -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()] \ No newline at end of file diff --git a/website_hide_button/views/product_templates.xml b/website_hide_button/views/product_templates.xml index cb464c188..3e35f2516 100644 --- a/website_hide_button/views/product_templates.xml +++ b/website_hide_button/views/product_templates.xml @@ -12,8 +12,7 @@ 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) @@ -27,8 +26,7 @@ @@ -37,15 +35,14 @@ inherit_id="website_sale.header_cart_link"> 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) @@ -72,8 +68,7 @@ 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)) 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)) @@ -93,8 +87,7 @@ position="attributes"> 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) @@ -104,8 +97,7 @@ 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)) @@ -114,8 +106,7 @@ inherit_id="website_sale.price_dynamic_filter_template_product_product"> (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)) @@ -125,9 +116,8 @@ 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) - + \ No newline at end of file diff --git a/website_hide_button/views/res_config_settings_views.xml b/website_hide_button/views/res_config_settings_views.xml index 56d8bd50f..77a6e4639 100755 --- a/website_hide_button/views/res_config_settings_views.xml +++ b/website_hide_button/views/res_config_settings_views.xml @@ -1,7 +1,7 @@ - + res.config.settings.view.form.inherit.website.hide.button @@ -9,16 +9,89 @@ + + + + +
+ + +
+
+ + +
+
+ + +
+ + Product prices and cart will be hidden for guest users on all websites. +
+ + +
+ + Product prices and cart will be hidden for guest users on selected websites only. +
+ + +
+ + Please select at least one website to apply this feature. +
+
- + - + + + +
+ + + This option is automatically enabled when "Hide Product Prices" is enabled. + +
+
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/website_hide_button/views/shop_templates.xml b/website_hide_button/views/shop_templates.xml index 0757ce323..0a6b2c971 100644 --- a/website_hide_button/views/shop_templates.xml +++ b/website_hide_button/views/shop_templates.xml @@ -5,10 +5,8 @@ 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) - + \ No newline at end of file diff --git a/website_hide_button/views/website_sale_comparison.xml b/website_hide_button/views/website_sale_comparison.xml index 937ca5763..a3b2ec0fc 100644 --- a/website_hide_button/views/website_sale_comparison.xml +++ b/website_hide_button/views/website_sale_comparison.xml @@ -5,15 +5,13 @@ 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) 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) @@ -22,9 +20,8 @@ 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) - + \ No newline at end of file