Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to read a configuration setting ?

By
Emanuel Cino
on 7/1/14, 8:26 AM 2,167 views

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 ?

Emanuel Cino
on 7/2/14, 1:58 AM
1
Emanuel Cino
On 8/15/14, 10:17 AM

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')
    }

0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 7/1/14, 11:19 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/1/14, 8:26 AM
Seen: 2167 times
Last updated: 3/16/15, 8:10 AM