In Odoo, a system parameter is a model used to store settings. Odoo examines the previously saved web.base.url every time a user logs into your Odoo instance to verify if it matches the URL the user used to log in. If not, Odoo updates the web.base.url.
How to create a system parameters in odoo 15:
In odoo we have the option to create the system parameters in different ways. We can create system parameters in the user interface or we can create system parameters from the module.
Creating system parameters in user interface:
To create system parameters in the user interface we need to activate the developer mode. The system parameters menu is located in the settings >> Technical >> system parameters here we can create new system parameters.
Here we have the system parameters model. We can create new records from here by clicking on the create button. Add unique text values to the key field and add the values in the values field. For multiple values we can use commas for seperation.
Creating system parameters in module:
We can create system parameters directly from the module it will execute when the module is installed. To create a record in system parameters we can add a record inside the xml file on the module.
<odoo>
<data noupdate="0">
<record id="auth_password_minlength" model="ir.config_parameter>
<field name="key">auth_password_minlength</field>
<field name="value">10</field>
</record>
</data>
</odoo>
In python we can read the system parameters record by using the get param method. We can read the system parameters by the key in the model. The value will be stored in string so we can convert it to another datatype for our requirement. If the record does not exist the result will be none.
from odoo import fields, models, api
class ModelName(models.Model):
_name = 'ProjectName.TableName'
_description = 'Description'
@api.model
def function(self):
System_parameters = self.env['ir.config_parameter'].get_param('system_parameters_key', '')
Also we can change the values of the system parameters from module by using the set params method.
from odoo import fields, models, api
class ModelName(models.Model):
_name = 'ProjectName.TableName'
_description = 'Description'
@api.model
def function(self):
custom_value = 10 #add custom value to update
System_parameters = self.env['ir.config_parameter'].set_param('system_parameters_key', custom_value)
If your Odoo instance can be accessed from two different URLs, such as example_url_1.com and example_url_2.com, this could create a problem. The web.base.url will remain "example_url_2.com" if a user logs in from that address. The same thing will happen if you use IP to access Odoo. This update will happen only for admin logged in time, not for all users login. In this case, the web.base.url and the IP value will both be saved. There are two options that could work. Either you guarantee that Odoo can only be accessed through the specific URL you desire (so yourwebsite.com) or you guarantee that Odoo won't alter the web.base.url. By including a new parameter named "web.base.url.freeze" and setting its value to "True," you may prevent this from occurring.