From 769a52a5876dd77ff299a32d7678a48e15fbf049 Mon Sep 17 00:00:00 2001 From: David Beal Date: Mon, 1 Jul 2019 19:17:57 +0200 Subject: [PATCH 1/2] ADD set command to apply settings --- click_odoo_contrib/set.py | 44 +++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 45 insertions(+) create mode 100644 click_odoo_contrib/set.py diff --git a/click_odoo_contrib/set.py b/click_odoo_contrib/set.py new file mode 100644 index 0000000..c4c2e69 --- /dev/null +++ b/click_odoo_contrib/set.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..ebd7828 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-set=click_odoo_contrib.set:main """, ) From a558918f045c9b27f6bec0c88b5ab392c26081c1 Mon Sep 17 00:00:00 2001 From: David Beal Date: Thu, 12 Sep 2019 10:53:18 +0200 Subject: [PATCH 2/2] FIX setting: entrypoint name and complete doc --- README.rst | 21 +++++++++++++++++++++ click_odoo_contrib/{set.py => setting.py} | 18 +++++++++--------- setup.py | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) rename click_odoo_contrib/{set.py => setting.py} (67%) 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/set.py b/click_odoo_contrib/setting.py similarity index 67% rename from click_odoo_contrib/set.py rename to click_odoo_contrib/setting.py index c4c2e69..9d382a2 100644 --- a/click_odoo_contrib/set.py +++ b/click_odoo_contrib/setting.py @@ -4,17 +4,16 @@ # 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 + default_log_level="info", with_database=True, with_rollback=False ) -@click.argument('settings_file_name', type=click.Path(exists=True)) +@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 { @@ -24,17 +23,18 @@ def main(env, settings_file_name): } to apply on your odoo database """ - with open(settings_file_name, 'r') as erp_settings: + 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([]): + 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') + [("company_id", "=", cpny.id)], limit=1, order="id desc" + ) if not config: # first configuration - config = settings_model.create({'company_id': cpny.id}) + 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() diff --git a/setup.py b/setup.py index ebd7828..87961e0 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +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-set=click_odoo_contrib.set:main + click-odoo-setting=click_odoo_contrib.setting:main """, )