Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
4278 Widoki

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)

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

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.

Powiązane posty Odpowiedzi Widoki Czynność
3
cze 18
3818
0
maj 25
1307
2
mar 23
3981
1
mar 19
6497
0
mar 19
3882