This question has been flagged
2 Replies
9829 Views

I want to change a value in the settings of sale.config.settings. For this I created a XML file which I added to the __openerp__.py:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="sale.config.settings" id="activate_dropshipping_sale">
      <field name="group_route_so_lines">True</field>
    </record>
  </data>
</openerp>

The problem is that this value is not changed in the settings. Maybe it's the problem that there is no entry in that table because the settings were not changed at this time.

How can I change a settings value like this?

Avatar
Discard
Best Answer

 

xml ===================

<?xml version="1.0"?>
<openerp>
<data>

<function model="my.model.init" name="_init_settings" />

</data>
</openerp>

 

python ======================

class my_model_init(osv.osv_memory):

    _name = ''my.model.init"
    _columns = {}
    _defaults = {}

    def _init_settings(self, cr, uid, ids=None, context=None):
        sale_settings_pool = self.pool.get('sale.config.settings')
        sale_settings_id = sale_settings_pool.create(cr, uid, {'group_route_so_lines':True}, context=context)
        sale_settings_obj = sale_settings_pool.browse(cr, uid, sale_settings_id, context=context)
        sale_settings_obj.execute()  # this call is actually changes the setting, you're missing this step @Yenthe ...
        return True

 

Avatar
Discard

You can add "_init_settings" function to an existing class in your module, rather than make separate class for it. But then you must adjust "function" entry in XML, by changing the "model" property accordingly.

@Temur what exactly do you mean with return True? Where exactly should this come then? :o

Just convention for successful termination, You can omit that, if the rest of code works for you ))

The same principle works also in odoo 10

Best Answer

The reason nothing happens is : sale.config.settings is a transient model,
so no values stored there are permanenet. It works a bit different with application settings

If you want something like setting some choices ... you should check yml files.. 
It can be done that way.. 

In your case you shold look at sale_stock module, res_config.py 
In your xml you can achieve desired solution with adding a new property to your company default_picking_policy 
( take a look at method set_sale_defaults )

hope this will help a bit...
Here is some resurce links for yaml usage:
odoo / openerp documentation
zbeanztech-blog: how-effective-yaml-testing-openerp
slideshare presentation from camp to caml

Avatar
Discard

Hey Bole could you add an example? I'm trying to do the same as Cristoph at the moment but without succes. I was thinking like this: !python {model: account.config.settings}: | value_obj = self.pool.get('account.config.settings') if value_obj: vals = { 'module_account_followup': 'True', } value_obj.write(cr, uid, vals, context) But that does not seem to work.

Note: I'm doing it for a checkmark on the account module, Christoph is trying it for the sale module, but the concept is identical.

Your idea (from linkedin) is good example... The rest is in correct usage and understanding how res.config works... here is mentioned sales module... so why not check res_config.py in sales module.... you will find out that there is few types of settings: boolean values are sometimes related to res_company properites, and some of them trigger module instalation... so for every value in congif you want to automate first check how it is defined in rec_config of module... from there... yml method can provide an easy tool to do the job... hope this helps... will post some examples as soon as i get the time to write and test them on v8...

Hi Bole

i've tried this in two ways and both did not work sadly.. I tried id 0 and id 1 too. I've been looking at the .py file too but I'm not quite sure exactly what I should trigger to get everything going though!

    !python {model: account.config.settings}: |
     value_obj = self.pool.get('account.config.settings')
     if value_obj:
       vals = {
        'module_account_followup': 'True',
       }
       value_obj.write(cr, uid, vals, context)
-
    test
-
    !python {model: account.config.settings}: |
     user_ids = self.pool.get('account.config.settings').search(cr, uid, [('id', '=', '1')], limit=1, context=context)
     if user_ids:
       self.write(cr, uid, user_ids, {
       'module_account_followup': 'True',
       }, context)

Any more ideas / guidance please? I'm still learning a lot in this!
Yenthe

2015-01-09 14:35 GMT+01:00 Bole <bole-dajmi5-com@mail.odoo.com>:

Your idea (from linkedin) is good example... The rest is in correct usage and understanding how res.config works... here is mentioned sales module... so why not check res_config.py in sales module.... you will find out that there is few types of settings: boolean values are sometimes related to res_company properites, and some of them trigger module instalation... so for every value in congif you want to automate first check how it is defined in rec_config of module... from there... yml method can provide an easy tool to do the job... hope this helps... will post some examples as soon as i get the time to write and test them on v8...

--
Bole
Sent by Odoo S.A. using Odoo about Forum Post False

well some hints... 1. there is no id=0 in any table.. all tables are indexed from 1. 2. res_config is transiend model and writing to it means nothing... 3. writing to res_config usualy triggers some other actions like: instaling module ( fileds named module_xxx ) , or setting some properties or defaults ( usualy on res_company object) ... try debugging save action on some config files and see what happens... and how odoo handes "saved" data... in fact.. what odoo DOES when you push SVAE on config view...