Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
4281 Переглядів

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)

Аватар
Відмінити
Автор Найкраща відповідь

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.

Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Автор

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 Відповіді Переглядів Дія
3
черв. 18
3819
0
трав. 25
1307
2
бер. 23
3981
1
бер. 19
6497
0
бер. 19
3883