+1 vote

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.

in Back-end by (10.5k points) | 240 views

1 Answer

0 votes
Try this
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 intbecause 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)

by (8.8k points)
205 questions
180 answers
221,423 users