diff --git a/README.rst b/README.rst index ab5f043..09af7c2 100644 --- a/README.rst +++ b/README.rst @@ -192,6 +192,25 @@ click-odoo-update (beta) --if-exists Don't report error if database doesn't exist --help Show this message and exit. +click-odoo-setting (alfa) +------------------------ + +.. code:: + + Usage: click-odoo-setting SOURCE + + Apply settings to all companies of an odoo instance. + Useful to quick start your dev configuration. + Settings are provided as python file SOURCE argument. + This source file only contains a dict mapping fields with their values + + { + ... + 'group_uom': True, + ... + } + + click-odoo-upgrade (deprecated, see click-odoo-update) ------------------------------------------------------ @@ -244,9 +263,11 @@ Contributors: - Benjamin Willig (ACSONE_) - Jairo Llopis (Tecnativa_) - Laurent Mignon (ACSONE_) +- David Béal (Akretion_) .. _ACSONE: https://acsone.eu .. _Tecnativa: https://tecnativa.com +.. _Akretion: https://akretion.com Maintainer ~~~~~~~~~~ diff --git a/click_odoo_contrib/setting.py b/click_odoo_contrib/setting.py new file mode 100644 index 0000000..9d382a2 --- /dev/null +++ b/click_odoo_contrib/setting.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# coding: utf-8 +# © 2019 David BEAL @ Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import ast + +import click +import click_odoo + + +@click.command() +@click_odoo.env_options( + default_log_level="info", with_database=True, with_rollback=False +) +@click.argument("settings_file_name", type=click.Path(exists=True)) +def main(env, settings_file_name): + """ Use a dict of settings provided with a python file + { + ... + 'group_uom': True, + ... + } + to apply on your odoo database + """ + with open(settings_file_name, "r") as erp_settings: + settings = {} + settings = ast.literal_eval(erp_settings.read()) + settings_model = env["res.config.settings"] + for cpny in env["res.company"].search([]): + # We only need the last configuration record + config = settings_model.search( + [("company_id", "=", cpny.id)], limit=1, order="id desc" + ) + if not config: + # first configuration + config = settings_model.create({"company_id": cpny.id}) + config.write(settings) + # Execute the record in order to trigger save and to apply settings + config.execute() + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/setup.py b/setup.py index 75de574..87961e0 100644 --- a/setup.py +++ b/setup.py @@ -45,5 +45,6 @@ click-odoo-initdb=click_odoo_contrib.initdb:main click-odoo-backupdb=click_odoo_contrib.backupdb:main click-odoo-makepot=click_odoo_contrib.makepot:main + click-odoo-setting=click_odoo_contrib.setting:main """, )