Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4282 Tampilan

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
Buang
Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Penulis

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.

Post Terkait Replies Tampilan Aktivitas
3
Jun 18
3819
0
Mei 25
1308
2
Mar 23
3981
1
Mar 19
6497
0
Mar 19
3884