تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4286 أدوات العرض

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.

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
يونيو 18
3822
0
مايو 25
1310
2
مارس 23
3981
1
مارس 19
6499
0
مارس 19
3887