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 change settings on module installation?

By
Christoph
on 1/9/15, 5:08 AM 1,657 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?

1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 1/9/15, 8:26 AM

 

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

 

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
on 1/9/15, 8:31 AM

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

Yenthe
on 1/9/15, 8:32 AM

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

Temur
on 1/9/15, 8:37 AM

The same principle works also in odoo 10

Audrius
on 11/30/16, 4:38 AM
0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 1/9/15, 6:43 AM

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

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.

Yenthe
on 1/9/15, 7:39 AM

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.

Yenthe
on 1/9/15, 7:40 AM

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
on 1/9/15, 8:35 AM
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

Yenthe
on 1/9/15, 8:47 AM

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...

Bole
on 1/9/15, 8:54 AM

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

2 follower(s)

Stats

Asked: 1/9/15, 5:08 AM
Seen: 1657 times
Last updated: 3/16/15, 8:10 AM