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

I want to retrieve the current configuration of a module that uses the class config.settings to store the configuration. But how can we retrieve the current state of the configuration ? From what I saw, each time the configuration is updated, a new line is inserted in the database. So doing something like 

    self.pool.get('sale.config.settings').browse(cr,uid,ids)[0]

won't work because I need to fetch the current state, not the first configuration stored. What is the correct way of doing it ?

الصورة الرمزية
إهمال
الكاتب

Your solution works, thanks. However when the settings were not changed (default settings), there is no row in the table. Then, how do we read the default configuration ?

الكاتب أفضل إجابة

In fact I realized that the class res.config.settings is of type osv_memory meaning that lines in the database are not kept ! The correct way of using this class is to name fields 'default_xxx'. The execute method will store the default value in the ir_values table so that we can retrieve them by calling the default_get method on the model object. Here is an example :

class mysql_config(osv.osv_memory):
    _inherit = 'res.config.settings'
    _name = 'mysql.config.settings'
    
    _columns = {
        'default_mysql_host' : fields.char('MySQL Host', default_model='mysql.config.settings')
    }

الصورة الرمزية
إهمال
أفضل إجابة

Here is a good tutorial on how doing this: http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html

الصورة الرمزية
إهمال
أفضل إجابة

Emanuel,

While doing the search, try to use the order id desc.

IDS = self.pool.get('sale.config.settings').search(cr, uid, [], order='id desc', limit=1)

result_obj = self.pool.get('sale.config.settings').browse(cr,uid,IDS[0])

Thanks.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
ديسمبر 23
10816
2
أبريل 25
3962
5
مارس 25
19333
1
يونيو 24
1968
1
مايو 24
2007