@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
# 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 ) :
class ResConfigSettings ( models . TransientModel ) :
@ -28,28 +28,76 @@ class ResConfigSettings(models.TransientModel):
"""
"""
_inherit = ' res.config.settings '
_inherit = ' res.config.settings '
hide_price = fields . Boolean ( string = ' Hide Price ' ,
hide_price = fields . Boolean (
string = ' Hide Price ' ,
config_parameter = ' website_hide_button.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 " )
help = " If enabled, the price of product will not be visible to guest users in website "
hide_cart = fields . Boolean ( string = ' Hide Cart ' ,
)
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 ' ,
config_parameter = ' website_hide_button.hide_cart ' ,
help = " If enabled, the Add to Cart button and Cart Icon will be visible to guest users " )
help = " If enabled, the Add to Cart button and Cart Icon will be hidden from guest users "
)
def set_values ( self ) :
def set_values ( self ) :
""" Method for setting the parameters """
""" Method for setting the parameters """
super ( ResConfigSettings , self ) . set_values ( )
super ( ResConfigSettings , self ) . set_values ( )
self . env [ ' ir.config_parameter ' ] . sudo ( ) . set_param (
params = self . env [ ' ir.config_parameter ' ] . sudo ( )
' website_hide_button.hide_price ' , self . hide_price )
self . env [ ' ir.config_parameter ' ] . sudo ( ) . set_param (
params . set_param ( ' website_hide_button.hide_price ' , self . hide_price )
' website_hide_button.hide_cart ' , self . hide_cart )
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
@api . model
def get_smartsupp_details ( self ) :
def get_hide_settings ( self ) :
""" Method for get value """
""" Method to get hide settings for current website """
hide_price = self . env [ ' ir.config_parameter ' ] . sudo ( ) . get_param (
params = self . env [ ' ir.config_parameter ' ] . sudo ( )
' website_hide_button.hide_price ' )
hide_price = params . get_param ( ' website_hide_button.hide_price ' )
hide_cart = self . env [ ' ir.config_parameter ' ] . sudo ( ) . get_param (
hide_cart = params . get_param ( ' website_hide_button.hide_cart ' )
' website_hide_button.hide_cart ' )
return {
return {
' hide_price ' : hide_price ,
' hide_price ' : hide_price ,
' hide_cart ' : hide_cart ,
' hide_cart ' : hide_cart ,
@ -57,6 +105,14 @@ class ResConfigSettings(models.TransientModel):
@api . onchange ( ' hide_price ' )
@api . onchange ( ' hide_price ' )
def _onchange_hide_price ( self ) :
def _onchange_hide_price ( self ) :
""" Auto-enable hide_cart when hide_price is enabled """
if self . hide_price :
if self . hide_price :
self . env [ ' ir.config_parameter ' ] . sudo ( ) . set_param (
self . hide_cart = True
' website_hide_button.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 ( ) ]