Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD set command to apply settings #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------------------------------------------

Expand Down Expand Up @@ -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
~~~~~~~~~~
Expand Down
44 changes: 44 additions & 0 deletions click_odoo_contrib/setting.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
""",
)