Community: Framework mailing list archives

expert-framework@mail.odoo.com

Re: Configuration settings - creates a new record every time.

by
Michael Telahun
- 09/26/2014 10:03:07
Hi Maxim,

I had the same problem you had. For a long time I didn't know how to use
res.config.settings to store my own configuration parameters. Bug I
finally after reading the forums I figured out that what I have to do is
use the default_get_* method to get the list of settings ordered by id
and then read the value of my field for the last id in the list.

Here's a snippet:

from openerp.osv import fields, orm
class hr_config_settings(orm.Model):

    _inherit = 'hr.config.settings'

    _columns = {
        'hr_manager_id': fields.many2one('hr.employee', 'HR Manager'),
    }

    def get_default_hr_manager_id(self, cr, uid, fields, context=None):

        employee_id = False
        ids = self.search(cr, uid, [], order='id', context=context)
        if len(ids) > 0:
            config = self.browse(cr, uid, ids[-1], context=context)
            if config.hr_manager_id:
                employee_id = config.hr_manager_id.id
        return {'hr_manager_id': employee_id}

Regards,
Mike.

On 09/26/2014 04:14 AM, Maxim Litnitskiy wrote:
> Spent already more then 3 hours trying to understand how Configuration
> pages work.
> 
> res_config_settings - Base configuration wizard for application
> settings.  It provides support for setting
>         default values, assigning groups to employee users.
> 
> So I am trying to store my app settings using res.config.settings.
> 
> But it:
> 1) Creates a new record on every Apply.
> 2) Does not read stored values.
> 
> Where I missed?
> Thanks!
> 
> Here is the model
> - https://github.com/litnimax/odoo-asterisk-dialer/blob/master/models/res_config.py
> And here is the view
> - https://github.com/litnimax/odoo-asterisk-dialer/blob/master/views/res_config_view.xml
> 
> odoo=# SELECT * from asterisk_server_settings;
>  id | create_uid |        create_date         | ari_user |      
>  ari_url        | write_uid |         write_date         | context_name
> | default_ari_url | ari_pass 
> ----+------------+----------------------------+----------+-----------------------+-----------+----------------------------+--------------+-----------------+----------
>   1 |          1 | 2014-09-25 22:22:57.624627 | aaaa     |
> http://localhost:8088 |         1 | 2014-09-25 22:22:57.624627 | dialer
>       |                 | aaa
>   2 |          1 | 2014-09-25 22:31:33.396451 | 1        |
> http://localhost:1111 |         1 | 2014-09-25 22:31:33.396451 | dialer
>       |                 | 1
>   3 |          1 | 2014-09-25 22:33:51.800946 | d        |
> http://localhost:8088 |         1 | 2014-09-25 22:33:51.800946 | dialer
>       |                 | d
>   4 |          1 | 2014-09-25 22:45:18.303018 | s        |
> http://localhost:8088 |         1 | 2014-09-25 22:45:18.303018 | dialer
>       |                 | s
>   5 |          1 | 2014-09-25 22:45:32.1802   | s        |
> http://localhost:8088 |         1 | 2014-09-25 22:45:32.1802   | dialer
>       |                 | s
>   6 |          1 | 2014-09-25 22:45:46.820791 | s        |
> http://localhost:8088 |         1 | 2014-09-25 22:45:46.820791 | dialer
>       |                 | s
> (6 rows)
> 
> 
> 
> 
> _______________________________________________
> Mailing-List: https://www.odoo.com/groups/community-framework-62
> Post to: mailto:expert-framework@mail.odoo.com
> Unsubscribe: https://www.odoo.com/groups?unsubscribe
>