Erwin
Erwin

Reputation: 33

How to call a system parameter from custom Python code in Odoo?

I'm running Odoo 12 and I'd like to set up an automated action after a new Opportunity is created. This automated action would be some custom Python code which calls a system parameter, gets its value and stores it in a field in the new opportunity's record. Afterwards, that system parameter should be increased by 1 so another new opportunity doesn't have the same number.

How do you get/set a system parameter from python code?

I've created a system parameter with key "customParameter"and value 10122. The field where this parameter should be put is called "x_studio_deal_quotation_id", within a new opportunity.

I've got a little experience in Python, so I've no idea how to call upon this parameter. Can someone help me out? Or is there an easier way to achieve the same? A big thanks in advance.

Upvotes: 2

Views: 1138

Answers (1)

Erwin
Erwin

Reputation: 33

I managed to find what I'm looking for on my own, this is the code I used:

record[("x_studio_deal_quotation_id")] = record.env['ir.config_parameter'].get_param('customParameter')
var = record.env['ir.config_parameter'].get_param('customParameter')
var = int(var)
var += 1
record.env['ir.config_parameter'].set_param('customParameter', var)

In this function I called my system parameter by using record.env['ir.config_parameter'].get_param('customParameter') I had to convert it to int because I got some error that the type wasn't right. Finally, I add 1 to my variable value and write the same system parameter with the new value by using:record.env['ir.config_parameter'].set_param('customParameter', var)

Upvotes: 1

Related Questions