This question has been flagged

Hi guys,

I was trying to figure out how to automatically configure app settings with erppeek but I don't seem to find a working way for it. I woud like to automatically check on the option "Discounts" on the sales settings for example:

import erppeek

database = 'Mydb'
server = 'http://localhost:8069'
admin_password = 'password'
client = erppeek.Client(server=server)
def configure_app():
config_params = client.model('res.config.settings').browse([]) if config_params:
config_params[0].write({'group_discount_per_so_line': True})
else:
config_params = client_model('res.config.settings').create({}) config_params[0].write({'group_discount_per_so_line': True})

While the record is found and is updated (the boolean is set to True in the database) I don't see it in the front-end and neither is the function activated. I would expect that by setting the boolean it would trigger all the needed behaviour to active the feature but this doesn't seem to be the case.

So, what am I missing here and how should I trigger the settings in order to apply them?

Regards,
Yenthe

Avatar
Discard
Author Best Answer

Alright so to answer my own question: You've need to call the execute() function in order to trigger the save and to apply everything to the settings. The code:

# We only need the last configuration record so let us set a limit and order it desc
config_id = client.model('res.config.settings').search([], limit=1, order='id desc')
if config_id:
    # This means there is already a configuration - let us write on it.
    config_rec = client.model('res.config.settings').browse(config_id[0])
    # 'group_discount_per_so_line' is the field name (in the settings) that I want to use
    config_rec.write({'group_discount_per_so_line': True,
        'group_uom': True,
        'multi_sales_price': True'})
    # Execute the record in order to trigger the save and to apply everything
    config_rec.execute()
else:
# This means there is no configuration yet - let us make one! config_params = client.model('res.config.settings').create({}) config_params.write({'group_discount_per_so_line': True, 'group_uom': True, 'multi_sales_price': True}) # Execute the record in order to trigger the save and to apply everything config_params.execute()


Dave Lasley gave me a good pointer at https://twitter.com/dlasley88/status/929371108448464896 and Jérémy (JKE-be from Odoo) gave another tip, so a big thank you to these guys. They deserve the credit.

Regards,
Yenthe

Avatar
Discard