Skip to Content
Menu
This question has been flagged
2 Replies
3199 Views

Hi guys!

We would like to set some app settings (eg, like the ones present in the General Settings section) via a custom add-on. What would be the right way to achieve this?

So far we have tried to update the base.config.settings model but even though the database table base_config_settings is correctly updated with our new values, those are not really picked up (don't show updated on the Odoo screen) and do not have any effect

We have also tried to apply the base.config.settings.execute() method but this has the unexpected effected to uninstall many add-ons.

Is there any example where this has been done already?

(using Odoo 10)

Avatar
Discard
Author Best Answer

Thanks. Couldn't make that work though. For example, I am trying to uncheck the group_multi_currency setting

Here is what I've done:

model = env["ir.values"]
result = model.sudo().set_default(
    'base.config.settings','group_multi_currency','f'
)

This will update the ir_values table:

id | model_id |         name         |   key   | value
----+----------+----------------------+---------+-------
 70 |          | group_multi_currency | default | S'f'  +
   

And this does not affect the value of the property.

Furthermore, anytime the module is started, the record in ir_table will be deleted and a new one created.

Avatar
Discard
Best Answer

Hello @Romain Buisson,

If you are trying to save something in the settings you can do it like this.


_inherit="base.config.settings"


@api.multi

def set_field_name_default(self):    

    return self.env['ir.values'].sudo().set_default(

            'base.config.settings', 'field_name', self.field_name)

Then to access the saved value in the settings,




ir_values = request.env['ir.values']

field_value = ir_values.get_default('base.config.settings', 'field_name')


Can you please mark this as a resolved if you are satisfied with my answer.

Avatar
Discard
Author

Thanks. Couldn't make that work though. For example, I am trying to uncheck the group_multi_currency setting

Here is what I've done:

model = env["ir.values"]

result = model.sudo().set_default(

'base.config.settings','group_multi_currency','f'

)

This will update the ir_values table:

id | model_id | name | key | value

----+----------+----------------------+---------+-------

70 | | group_multi_currency | default | S'f' +

And this does not affect the value of the property.

Furthermore, anytime the module is started, the record in ir_table will be deleted and a new one created.

Related Posts Replies Views Activity
3
Jun 18
2904
0
Oct 24
119
2
Mar 23
2374
1
Mar 19
5312
0
Mar 19
2946