[IMP] server_environment: pre-commit stuff
This commit is contained in:
parent
3bdf064def
commit
1748ef0a01
Binary file not shown.
|
|
@ -17,31 +17,31 @@ server configuration environment files
|
||||||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||||
:alt: License: LGPL-3
|
:alt: License: LGPL-3
|
||||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
|
||||||
:target: https://github.com/OCA/server-env/tree/16.0/server_environment
|
:target: https://github.com/OCA/server-env/tree/17.0/server_environment
|
||||||
:alt: OCA/server-env
|
:alt: OCA/server-env
|
||||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
:target: https://translation.odoo-community.org/projects/server-env-16-0/server-env-16-0-server_environment
|
:target: https://translation.odoo-community.org/projects/server-env-17-0/server-env-17-0-server_environment
|
||||||
:alt: Translate me on Weblate
|
:alt: Translate me on Weblate
|
||||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||||
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=16.0
|
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=17.0
|
||||||
:alt: Try me on Runboat
|
:alt: Try me on Runboat
|
||||||
|
|
||||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
This module provides a way to define an environment in the main Odoo
|
This module provides a way to define an environment in the main Odoo
|
||||||
configuration file and to read some configurations from files
|
configuration file and to read some configurations from files depending
|
||||||
depending on the configured environment: you define the environment in
|
on the configured environment: you define the environment in the main
|
||||||
the main configuration file, and the values for the various possible
|
configuration file, and the values for the various possible environments
|
||||||
environments are stored in the ``server_environment_files`` companion
|
are stored in the ``server_environment_files`` companion module.
|
||||||
module.
|
|
||||||
|
|
||||||
The ``server_environment_files`` module is optional, the values can be set using
|
The ``server_environment_files`` module is optional, the values can be
|
||||||
an environment variable with a fallback on default values in the database.
|
set using an environment variable with a fallback on default values in
|
||||||
|
the database.
|
||||||
|
|
||||||
The configuration read from the files are visible under the Configuration
|
The configuration read from the files are visible under the
|
||||||
menu. If you are not in the 'dev' environment you will not be able to
|
Configuration menu. If you are not in the 'dev' environment you will not
|
||||||
see the values contained in the defined secret keys
|
be able to see the values contained in the defined secret keys (by
|
||||||
(by default : '*passw*', '*key*', '*secret*' and '*token*').
|
default : '*passw*', '*key*', '*secret*' and '*token*').
|
||||||
|
|
||||||
**Table of contents**
|
**Table of contents**
|
||||||
|
|
||||||
|
|
@ -52,62 +52,70 @@ Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
By itself, this module does little. See for instance the
|
By itself, this module does little. See for instance the
|
||||||
``mail_environment`` addon which depends on this one to allow configuring
|
``mail_environment`` addon which depends on this one to allow
|
||||||
the incoming and outgoing mail servers depending on the environment.
|
configuring the incoming and outgoing mail servers depending on the
|
||||||
|
environment.
|
||||||
|
|
||||||
You can store your configuration values in a companion module called
|
You can store your configuration values in a companion module called
|
||||||
``server_environment_files``. You can copy and customize the provided
|
``server_environment_files``. You can copy and customize the provided
|
||||||
``server_environment_files_sample`` module for this purpose. Alternatively, you
|
``server_environment_files_sample`` module for this purpose.
|
||||||
can provide them in environment variables ``SERVER_ENV_CONFIG`` and
|
Alternatively, you can provide them in environment variables
|
||||||
``SERVER_ENV_CONFIG_SECRET``.
|
``SERVER_ENV_CONFIG`` and ``SERVER_ENV_CONFIG_SECRET``.
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
||||||
To configure this module, you need to edit the main configuration file
|
To configure this module, you need to edit the main configuration file
|
||||||
of your instance, and add a directive called ``running_env``. Commonly
|
of your instance, and add a directive called ``running_env``. Commonly
|
||||||
used values are 'dev', 'test', 'production'::
|
used values are 'dev', 'test', 'production':
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
running_env=dev
|
running_env=dev
|
||||||
|
|
||||||
Values associated to keys containing 'passw' are only displayed in the 'dev'
|
Values associated to keys containing 'passw' are only displayed in the
|
||||||
environment.
|
'dev' environment.
|
||||||
|
|
||||||
If you don't provide any value, `test` is used as a safe default.
|
If you don't provide any value, test is used as a safe default.
|
||||||
|
|
||||||
You have several possibilities to set configuration values:
|
You have several possibilities to set configuration values:
|
||||||
|
|
||||||
server_environment_files
|
server_environment_files
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
------------------------
|
||||||
|
|
||||||
You can edit the settings you need in the ``server_environment_files`` addon. The
|
You can edit the settings you need in the ``server_environment_files``
|
||||||
``server_environment_files_sample`` can be used as an example:
|
addon. The ``server_environment_files_sample`` can be used as an
|
||||||
|
example:
|
||||||
|
|
||||||
* values common to all / most environments can be stored in the
|
- values common to all / most environments can be stored in the
|
||||||
``default/`` directory using the .ini file syntax;
|
``default/`` directory using the .ini file syntax;
|
||||||
* each environment you need to define is stored in its own directory
|
- each environment you need to define is stored in its own directory
|
||||||
and can override or extend default values;
|
and can override or extend default values;
|
||||||
* you can override or extend values in the main configuration
|
- you can override or extend values in the main configuration file of
|
||||||
file of your instance;
|
your instance;
|
||||||
|
|
||||||
Environment variable
|
Environment variable
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
--------------------
|
||||||
|
|
||||||
You can define configuration in the environment variable ``SERVER_ENV_CONFIG``
|
You can define configuration in the environment variable
|
||||||
and/or ``SERVER_ENV_CONFIG_SECRET``. The 2 variables are handled the exact same
|
``SERVER_ENV_CONFIG`` and/or ``SERVER_ENV_CONFIG_SECRET``. The 2
|
||||||
way, this is only a convenience for the deployment where you can isolate the
|
variables are handled the exact same way, this is only a convenience for
|
||||||
secrets in a different, encrypted, file. They are multi-line environment variables
|
the deployment where you can isolate the secrets in a different,
|
||||||
in the same configparser format than the files.
|
encrypted, file. They are multi-line environment variables in the same
|
||||||
If you used options in ``server_environment_files``, the options set in the
|
configparser format than the files. If you used options in
|
||||||
environment variable override them.
|
``server_environment_files``, the options set in the environment
|
||||||
|
variable override them.
|
||||||
|
|
||||||
The options in the environment variable are not dependent of ``running_env``,
|
The options in the environment variable are not dependent of
|
||||||
the content of the variable must be set accordingly to the running environment.
|
``running_env``, the content of the variable must be set accordingly to
|
||||||
|
the running environment.
|
||||||
|
|
||||||
Example of setup:
|
Example of setup:
|
||||||
|
|
||||||
A public file, containing that will contain public variables::
|
A public file, containing that will contain public variables:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
# These variables are not odoo standard variables,
|
# These variables are not odoo standard variables,
|
||||||
# they are there to represent what your file could look like
|
# they are there to represent what your file could look like
|
||||||
|
|
@ -126,7 +134,9 @@ A public file, containing that will contain public variables::
|
||||||
directory_path=Odoo
|
directory_path=Odoo
|
||||||
"
|
"
|
||||||
|
|
||||||
A second file which is encrypted and contains secrets::
|
A second file which is encrypted and contains secrets:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
# This variable is not an odoo standard variable,
|
# This variable is not an odoo standard variable,
|
||||||
# it is there to represent what your file could look like
|
# it is there to represent what your file could look like
|
||||||
|
|
@ -139,17 +149,15 @@ A second file which is encrypted and contains secrets::
|
||||||
|
|
||||||
**WARNING**
|
**WARNING**
|
||||||
|
|
||||||
`my_sftp` must match the name of the record.
|
my_sftp must match the name of the record. If you want something more
|
||||||
If you want something more reliable use `server.env.techname.mixin`
|
reliable use server.env.techname.mixin and use tech_name field to
|
||||||
and use `tech_name` field to reference records.
|
reference records. See "USAGE".
|
||||||
See "USAGE".
|
|
||||||
|
|
||||||
|
|
||||||
Default values
|
Default values
|
||||||
~~~~~~~~~~~~~~
|
--------------
|
||||||
|
|
||||||
When using the ``server.env.mixin`` mixin, for each env-computed field, a
|
When using the ``server.env.mixin`` mixin, for each env-computed field,
|
||||||
companion field ``<field>_env_default`` is created. This field is not
|
a companion field ``<field>_env_default`` is created. This field is not
|
||||||
environment-dependent. It's a fallback value used when no key is set in
|
environment-dependent. It's a fallback value used when no key is set in
|
||||||
configuration files / environment variable.
|
configuration files / environment variable.
|
||||||
|
|
||||||
|
|
@ -157,18 +165,17 @@ When the default field is used, the field is made editable on Odoo.
|
||||||
|
|
||||||
Note: empty environment keys always take precedence over default fields
|
Note: empty environment keys always take precedence over default fields
|
||||||
|
|
||||||
|
|
||||||
Server environment integration
|
Server environment integration
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
------------------------------
|
||||||
|
|
||||||
Read the documentation of the class `models/server_env_mixin.py
|
Read the documentation of the class
|
||||||
<models/server_env_mixin.py>`_.
|
`models/server_env_mixin.py <models/server_env_mixin.py>`__.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
You can include a mixin in your model and configure the env-computed fields
|
You can include a mixin in your model and configure the env-computed
|
||||||
by an override of ``_server_env_fields``.
|
fields by an override of ``_server_env_fields``.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
|
@ -180,11 +187,12 @@ by an override of ``_server_env_fields``.
|
||||||
def _server_env_fields(self):
|
def _server_env_fields(self):
|
||||||
return {"directory_path": {}}
|
return {"directory_path": {}}
|
||||||
|
|
||||||
Read the documentation of the class and methods in `models/server_env_mixin.py
|
Read the documentation of the class and methods in
|
||||||
<models/server_env_mixin.py>`__.
|
`models/server_env_mixin.py <models/server_env_mixin.py>`__.
|
||||||
|
|
||||||
|
If you want to have a technical name to reference:
|
||||||
|
|
||||||
If you want to have a technical name to reference::
|
::
|
||||||
|
|
||||||
class StorageBackend(models.Model):
|
class StorageBackend(models.Model):
|
||||||
_name = "storage.backend"
|
_name = "storage.backend"
|
||||||
|
|
@ -195,11 +203,13 @@ If you want to have a technical name to reference::
|
||||||
Known issues / Roadmap
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
||||||
* it is not possible to set the environment from the command line. A
|
- it is not possible to set the environment from the command line. A
|
||||||
configuration file must be used.
|
configuration file must be used.
|
||||||
* the module does not allow to set low level attributes such as database server, etc.
|
- the module does not allow to set low level attributes such as
|
||||||
* `server.env.techname.mixin`'s `tech_name` field could leverage the new option
|
database server, etc.
|
||||||
for computable / writable fields and get rid of some onchange / read / write code.
|
- server.env.techname.mixin's tech_name field could leverage the new
|
||||||
|
option for computable / writable fields and get rid of some onchange
|
||||||
|
/ read / write code.
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
@ -207,7 +217,7 @@ Bug Tracker
|
||||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_.
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_.
|
||||||
In case of trouble, please check there if your issue has already been reported.
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
||||||
`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
Do not contact contributors directly about support or help with technical issues.
|
Do not contact contributors directly about support or help with technical issues.
|
||||||
|
|
||||||
|
|
@ -215,28 +225,28 @@ Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Authors
|
Authors
|
||||||
~~~~~~~
|
-------
|
||||||
|
|
||||||
* Camptocamp
|
* Camptocamp
|
||||||
|
|
||||||
Contributors
|
Contributors
|
||||||
~~~~~~~~~~~~
|
------------
|
||||||
|
|
||||||
* Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
|
- Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
|
||||||
* Nicolas Bessi <nicolas.bessi@camptocamp.com>
|
- Nicolas Bessi <nicolas.bessi@camptocamp.com>
|
||||||
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
|
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
|
||||||
* Daniel Reis <dgreis@sapo.pt>
|
- Daniel Reis <dgreis@sapo.pt>
|
||||||
* Holger Brunn <hbrunn@therp.nl>
|
- Holger Brunn <hbrunn@therp.nl>
|
||||||
* Leonardo Pistone <leonardo.pistone@camptocamp.com>
|
- Leonardo Pistone <leonardo.pistone@camptocamp.com>
|
||||||
* Adrien Peiffer <adrien.peiffer@acsone.com>
|
- Adrien Peiffer <adrien.peiffer@acsone.com>
|
||||||
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
|
- Thierry Ducrest <thierry.ducrest@camptocamp.com>
|
||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
* Thomas Binfeld <thomas.binsfeld@acsone.eu>
|
- Thomas Binfeld <thomas.binsfeld@acsone.eu>
|
||||||
* Stéphane Bidoul <stefane.bidoul@acsone.com>
|
- Stéphane Bidoul <stefane.bidoul@acsone.com>
|
||||||
* Simone Orsi <simahawk@gmail.com>
|
- Simone Orsi <simahawk@gmail.com>
|
||||||
|
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
-----------
|
||||||
|
|
||||||
This module is maintained by the OCA.
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
|
@ -248,6 +258,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.
|
promote its widespread use.
|
||||||
|
|
||||||
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/16.0/server_environment>`_ project on GitHub.
|
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/17.0/server_environment>`_ project on GitHub.
|
||||||
|
|
||||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ class ServerEnvMixin(models.AbstractModel):
|
||||||
options = self._server_env_fields[base_field_name]
|
options = self._server_env_fields[base_field_name]
|
||||||
if options and options.get("no_default_field"):
|
if options and options.get("no_default_field"):
|
||||||
return ""
|
return ""
|
||||||
return "{}_env_default".format(base_field_name)
|
return f"{base_field_name}_env_default"
|
||||||
|
|
||||||
def _server_env_is_editable_fieldname(self, base_field_name):
|
def _server_env_is_editable_fieldname(self, base_field_name):
|
||||||
"""Return the name of the field for "is editable"
|
"""Return the name of the field for "is editable"
|
||||||
|
|
@ -346,7 +346,7 @@ class ServerEnvMixin(models.AbstractModel):
|
||||||
This is the field used to tell if the env-computed field can
|
This is the field used to tell if the env-computed field can
|
||||||
be edited.
|
be edited.
|
||||||
"""
|
"""
|
||||||
return "{}_env_is_editable".format(base_field_name)
|
return f"{base_field_name}_env_is_editable"
|
||||||
|
|
||||||
def _server_env_transform_field_to_read_from_env(self, field):
|
def _server_env_transform_field_to_read_from_env(self, field):
|
||||||
"""Transform the original field in a computed field"""
|
"""Transform the original field in a computed field"""
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["whool"]
|
||||||
|
build-backend = "whool.buildapi"
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
To configure this module, you need to edit the main configuration file
|
||||||
|
of your instance, and add a directive called `running_env`. Commonly
|
||||||
|
used values are 'dev', 'test', 'production':
|
||||||
|
|
||||||
|
[options]
|
||||||
|
running_env=dev
|
||||||
|
|
||||||
|
Values associated to keys containing 'passw' are only displayed in the
|
||||||
|
'dev' environment.
|
||||||
|
|
||||||
|
If you don't provide any value, test is used as a safe default.
|
||||||
|
|
||||||
|
You have several possibilities to set configuration values:
|
||||||
|
|
||||||
|
## server_environment_files
|
||||||
|
|
||||||
|
You can edit the settings you need in the `server_environment_files`
|
||||||
|
addon. The `server_environment_files_sample` can be used as an example:
|
||||||
|
|
||||||
|
- values common to all / most environments can be stored in the
|
||||||
|
`default/` directory using the .ini file syntax;
|
||||||
|
- each environment you need to define is stored in its own directory and
|
||||||
|
can override or extend default values;
|
||||||
|
- you can override or extend values in the main configuration file of
|
||||||
|
your instance;
|
||||||
|
|
||||||
|
## Environment variable
|
||||||
|
|
||||||
|
You can define configuration in the environment variable
|
||||||
|
`SERVER_ENV_CONFIG` and/or `SERVER_ENV_CONFIG_SECRET`. The 2 variables
|
||||||
|
are handled the exact same way, this is only a convenience for the
|
||||||
|
deployment where you can isolate the secrets in a different, encrypted,
|
||||||
|
file. They are multi-line environment variables in the same configparser
|
||||||
|
format than the files. If you used options in
|
||||||
|
`server_environment_files`, the options set in the environment variable
|
||||||
|
override them.
|
||||||
|
|
||||||
|
The options in the environment variable are not dependent of
|
||||||
|
`running_env`, the content of the variable must be set accordingly to
|
||||||
|
the running environment.
|
||||||
|
|
||||||
|
Example of setup:
|
||||||
|
|
||||||
|
A public file, containing that will contain public variables:
|
||||||
|
|
||||||
|
# These variables are not odoo standard variables,
|
||||||
|
# they are there to represent what your file could look like
|
||||||
|
export WORKERS='8'
|
||||||
|
export MAX_CRON_THREADS='1'
|
||||||
|
export LOG_LEVEL=info
|
||||||
|
export LOG_HANDLER=":INFO"
|
||||||
|
export DB_MAXCONN=5
|
||||||
|
|
||||||
|
# server environment options
|
||||||
|
export SERVER_ENV_CONFIG="
|
||||||
|
[storage_backend.my_sftp]
|
||||||
|
sftp_server=10.10.10.10
|
||||||
|
sftp_login=foo
|
||||||
|
sftp_port=22200
|
||||||
|
directory_path=Odoo
|
||||||
|
"
|
||||||
|
|
||||||
|
A second file which is encrypted and contains secrets:
|
||||||
|
|
||||||
|
# This variable is not an odoo standard variable,
|
||||||
|
# it is there to represent what your file could look like
|
||||||
|
export DB_PASSWORD='xxxxxxxxx'
|
||||||
|
# server environment options
|
||||||
|
export SERVER_ENV_CONFIG_SECRET="
|
||||||
|
[storage_backend.my_sftp]
|
||||||
|
sftp_password=xxxxxxxxx
|
||||||
|
"
|
||||||
|
|
||||||
|
**WARNING**
|
||||||
|
|
||||||
|
> my_sftp must match the name of the record. If you want something more
|
||||||
|
> reliable use server.env.techname.mixin and use tech_name field to
|
||||||
|
> reference records. See "USAGE".
|
||||||
|
|
||||||
|
## Default values
|
||||||
|
|
||||||
|
When using the `server.env.mixin` mixin, for each env-computed field, a
|
||||||
|
companion field `<field>_env_default` is created. This field is not
|
||||||
|
environment-dependent. It's a fallback value used when no key is set in
|
||||||
|
configuration files / environment variable.
|
||||||
|
|
||||||
|
When the default field is used, the field is made editable on Odoo.
|
||||||
|
|
||||||
|
Note: empty environment keys always take precedence over default fields
|
||||||
|
|
||||||
|
## Server environment integration
|
||||||
|
|
||||||
|
Read the documentation of the class
|
||||||
|
[models/server_env_mixin.py](models/server_env_mixin.py).
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
To configure this module, you need to edit the main configuration file
|
|
||||||
of your instance, and add a directive called ``running_env``. Commonly
|
|
||||||
used values are 'dev', 'test', 'production'::
|
|
||||||
|
|
||||||
[options]
|
|
||||||
running_env=dev
|
|
||||||
|
|
||||||
Values associated to keys containing 'passw' are only displayed in the 'dev'
|
|
||||||
environment.
|
|
||||||
|
|
||||||
If you don't provide any value, `test` is used as a safe default.
|
|
||||||
|
|
||||||
You have several possibilities to set configuration values:
|
|
||||||
|
|
||||||
server_environment_files
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
You can edit the settings you need in the ``server_environment_files`` addon. The
|
|
||||||
``server_environment_files_sample`` can be used as an example:
|
|
||||||
|
|
||||||
* values common to all / most environments can be stored in the
|
|
||||||
``default/`` directory using the .ini file syntax;
|
|
||||||
* each environment you need to define is stored in its own directory
|
|
||||||
and can override or extend default values;
|
|
||||||
* you can override or extend values in the main configuration
|
|
||||||
file of your instance;
|
|
||||||
|
|
||||||
Environment variable
|
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
You can define configuration in the environment variable ``SERVER_ENV_CONFIG``
|
|
||||||
and/or ``SERVER_ENV_CONFIG_SECRET``. The 2 variables are handled the exact same
|
|
||||||
way, this is only a convenience for the deployment where you can isolate the
|
|
||||||
secrets in a different, encrypted, file. They are multi-line environment variables
|
|
||||||
in the same configparser format than the files.
|
|
||||||
If you used options in ``server_environment_files``, the options set in the
|
|
||||||
environment variable override them.
|
|
||||||
|
|
||||||
The options in the environment variable are not dependent of ``running_env``,
|
|
||||||
the content of the variable must be set accordingly to the running environment.
|
|
||||||
|
|
||||||
Example of setup:
|
|
||||||
|
|
||||||
A public file, containing that will contain public variables::
|
|
||||||
|
|
||||||
# These variables are not odoo standard variables,
|
|
||||||
# they are there to represent what your file could look like
|
|
||||||
export WORKERS='8'
|
|
||||||
export MAX_CRON_THREADS='1'
|
|
||||||
export LOG_LEVEL=info
|
|
||||||
export LOG_HANDLER=":INFO"
|
|
||||||
export DB_MAXCONN=5
|
|
||||||
|
|
||||||
# server environment options
|
|
||||||
export SERVER_ENV_CONFIG="
|
|
||||||
[storage_backend.my_sftp]
|
|
||||||
sftp_server=10.10.10.10
|
|
||||||
sftp_login=foo
|
|
||||||
sftp_port=22200
|
|
||||||
directory_path=Odoo
|
|
||||||
"
|
|
||||||
|
|
||||||
A second file which is encrypted and contains secrets::
|
|
||||||
|
|
||||||
# This variable is not an odoo standard variable,
|
|
||||||
# it is there to represent what your file could look like
|
|
||||||
export DB_PASSWORD='xxxxxxxxx'
|
|
||||||
# server environment options
|
|
||||||
export SERVER_ENV_CONFIG_SECRET="
|
|
||||||
[storage_backend.my_sftp]
|
|
||||||
sftp_password=xxxxxxxxx
|
|
||||||
"
|
|
||||||
|
|
||||||
**WARNING**
|
|
||||||
|
|
||||||
`my_sftp` must match the name of the record.
|
|
||||||
If you want something more reliable use `server.env.techname.mixin`
|
|
||||||
and use `tech_name` field to reference records.
|
|
||||||
See "USAGE".
|
|
||||||
|
|
||||||
|
|
||||||
Default values
|
|
||||||
~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
When using the ``server.env.mixin`` mixin, for each env-computed field, a
|
|
||||||
companion field ``<field>_env_default`` is created. This field is not
|
|
||||||
environment-dependent. It's a fallback value used when no key is set in
|
|
||||||
configuration files / environment variable.
|
|
||||||
|
|
||||||
When the default field is used, the field is made editable on Odoo.
|
|
||||||
|
|
||||||
Note: empty environment keys always take precedence over default fields
|
|
||||||
|
|
||||||
|
|
||||||
Server environment integration
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Read the documentation of the class `models/server_env_mixin.py
|
|
||||||
<models/server_env_mixin.py>`_.
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
- Florent Xicluna (Wingo) \<<florent.xicluna@gmail.com>\>
|
||||||
|
- Nicolas Bessi \<<nicolas.bessi@camptocamp.com>\>
|
||||||
|
- Alexandre Fayolle \<<alexandre.fayolle@camptocamp.com>\>
|
||||||
|
- Daniel Reis \<<dgreis@sapo.pt>\>
|
||||||
|
- Holger Brunn \<<hbrunn@therp.nl>\>
|
||||||
|
- Leonardo Pistone \<<leonardo.pistone@camptocamp.com>\>
|
||||||
|
- Adrien Peiffer \<<adrien.peiffer@acsone.com>\>
|
||||||
|
- Thierry Ducrest \<<thierry.ducrest@camptocamp.com>\>
|
||||||
|
- Guewen Baconnier \<<guewen.baconnier@camptocamp.com>\>
|
||||||
|
- Thomas Binfeld \<<thomas.binsfeld@acsone.eu>\>
|
||||||
|
- Stéphane Bidoul \<<stefane.bidoul@acsone.com>\>
|
||||||
|
- Simone Orsi \<<simahawk@gmail.com>\>
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
* Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
|
|
||||||
* Nicolas Bessi <nicolas.bessi@camptocamp.com>
|
|
||||||
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
|
|
||||||
* Daniel Reis <dgreis@sapo.pt>
|
|
||||||
* Holger Brunn <hbrunn@therp.nl>
|
|
||||||
* Leonardo Pistone <leonardo.pistone@camptocamp.com>
|
|
||||||
* Adrien Peiffer <adrien.peiffer@acsone.com>
|
|
||||||
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
|
|
||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
|
||||||
* Thomas Binfeld <thomas.binsfeld@acsone.eu>
|
|
||||||
* Stéphane Bidoul <stefane.bidoul@acsone.com>
|
|
||||||
* Simone Orsi <simahawk@gmail.com>
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
This module provides a way to define an environment in the main Odoo
|
||||||
|
configuration file and to read some configurations from files depending
|
||||||
|
on the configured environment: you define the environment in the main
|
||||||
|
configuration file, and the values for the various possible environments
|
||||||
|
are stored in the `server_environment_files` companion module.
|
||||||
|
|
||||||
|
The `server_environment_files` module is optional, the values can be set
|
||||||
|
using an environment variable with a fallback on default values in the
|
||||||
|
database.
|
||||||
|
|
||||||
|
The configuration read from the files are visible under the
|
||||||
|
Configuration menu. If you are not in the 'dev' environment you will not
|
||||||
|
be able to see the values contained in the defined secret keys (by
|
||||||
|
default : '*passw*', '*key*', '*secret*' and '*token*').
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
This module provides a way to define an environment in the main Odoo
|
|
||||||
configuration file and to read some configurations from files
|
|
||||||
depending on the configured environment: you define the environment in
|
|
||||||
the main configuration file, and the values for the various possible
|
|
||||||
environments are stored in the ``server_environment_files`` companion
|
|
||||||
module.
|
|
||||||
|
|
||||||
The ``server_environment_files`` module is optional, the values can be set using
|
|
||||||
an environment variable with a fallback on default values in the database.
|
|
||||||
|
|
||||||
The configuration read from the files are visible under the Configuration
|
|
||||||
menu. If you are not in the 'dev' environment you will not be able to
|
|
||||||
see the values contained in the defined secret keys
|
|
||||||
(by default : '*passw*', '*key*', '*secret*' and '*token*').
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
By itself, this module does little. See for instance the
|
||||||
|
`mail_environment` addon which depends on this one to allow configuring
|
||||||
|
the incoming and outgoing mail servers depending on the environment.
|
||||||
|
|
||||||
|
You can store your configuration values in a companion module called
|
||||||
|
`server_environment_files`. You can copy and customize the provided
|
||||||
|
`server_environment_files_sample` module for this purpose.
|
||||||
|
Alternatively, you can provide them in environment variables
|
||||||
|
`SERVER_ENV_CONFIG` and `SERVER_ENV_CONFIG_SECRET`.
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
By itself, this module does little. See for instance the
|
|
||||||
``mail_environment`` addon which depends on this one to allow configuring
|
|
||||||
the incoming and outgoing mail servers depending on the environment.
|
|
||||||
|
|
||||||
You can store your configuration values in a companion module called
|
|
||||||
``server_environment_files``. You can copy and customize the provided
|
|
||||||
``server_environment_files_sample`` module for this purpose. Alternatively, you
|
|
||||||
can provide them in environment variables ``SERVER_ENV_CONFIG`` and
|
|
||||||
``SERVER_ENV_CONFIG_SECRET``.
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
- it is not possible to set the environment from the command line. A
|
||||||
|
configuration file must be used.
|
||||||
|
- the module does not allow to set low level attributes such as database
|
||||||
|
server, etc.
|
||||||
|
- server.env.techname.mixin's tech_name field could leverage the new
|
||||||
|
option for computable / writable fields and get rid of some onchange /
|
||||||
|
read / write code.
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
* it is not possible to set the environment from the command line. A
|
|
||||||
configuration file must be used.
|
|
||||||
* the module does not allow to set low level attributes such as database server, etc.
|
|
||||||
* `server.env.techname.mixin`'s `tech_name` field could leverage the new option
|
|
||||||
for computable / writable fields and get rid of some onchange / read / write code.
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
You can include a mixin in your model and configure the env-computed fields
|
You can include a mixin in your model and configure the env-computed
|
||||||
by an override of ``_server_env_fields``.
|
fields by an override of `_server_env_fields`.
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
class StorageBackend(models.Model):
|
class StorageBackend(models.Model):
|
||||||
_name = "storage.backend"
|
_name = "storage.backend"
|
||||||
|
|
@ -11,11 +9,10 @@ by an override of ``_server_env_fields``.
|
||||||
def _server_env_fields(self):
|
def _server_env_fields(self):
|
||||||
return {"directory_path": {}}
|
return {"directory_path": {}}
|
||||||
|
|
||||||
Read the documentation of the class and methods in `models/server_env_mixin.py
|
Read the documentation of the class and methods in
|
||||||
<models/server_env_mixin.py>`__.
|
[models/server_env_mixin.py](models/server_env_mixin.py).
|
||||||
|
|
||||||
|
If you want to have a technical name to reference:
|
||||||
If you want to have a technical name to reference::
|
|
||||||
|
|
||||||
class StorageBackend(models.Model):
|
class StorageBackend(models.Model):
|
||||||
_name = "storage.backend"
|
_name = "storage.backend"
|
||||||
|
|
@ -111,9 +111,7 @@ def _load_config_from_server_env_files(config_p):
|
||||||
try:
|
try:
|
||||||
config_p.read(conf_files)
|
config_p.read(conf_files)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(f'Cannot read config files "{conf_files}": {e}') from e
|
||||||
'Cannot read config files "{}": {}'.format(conf_files, e)
|
|
||||||
) from e
|
|
||||||
|
|
||||||
|
|
||||||
def _load_config_from_rcfile(config_p):
|
def _load_config_from_rcfile(config_p):
|
||||||
|
|
@ -129,7 +127,7 @@ def _load_config_from_env(config_p):
|
||||||
config_p.read_string(env_config)
|
config_p.read_string(env_config)
|
||||||
except configparser.Error as err:
|
except configparser.Error as err:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"{} content could not be parsed: {}".format(varname, err)
|
f"{varname} content could not be parsed: {err}"
|
||||||
) from err
|
) from err
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -182,7 +180,7 @@ class ServerConfiguration(models.TransientModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _format_key(cls, section, key):
|
def _format_key(cls, section, key):
|
||||||
return "{}_I_{}".format(section, key)
|
return f"{section}_I_{key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def show_passwords(self):
|
def show_passwords(self):
|
||||||
|
|
|
||||||
|
|
@ -369,19 +369,19 @@ ul.auto-toc {
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
!! source digest: sha256:681af9ccb320ef4e5866b4dfcb9ed2d8d19abae84f71d251cdc8376303f40c01
|
!! source digest: sha256:681af9ccb320ef4e5866b4dfcb9ed2d8d19abae84f71d251cdc8376303f40c01
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||||
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/16.0/server_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-16-0/server-env-16-0-server_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/17.0/server_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-17-0/server-env-17-0-server_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||||
<p>This module provides a way to define an environment in the main Odoo
|
<p>This module provides a way to define an environment in the main Odoo
|
||||||
configuration file and to read some configurations from files
|
configuration file and to read some configurations from files depending
|
||||||
depending on the configured environment: you define the environment in
|
on the configured environment: you define the environment in the main
|
||||||
the main configuration file, and the values for the various possible
|
configuration file, and the values for the various possible environments
|
||||||
environments are stored in the <tt class="docutils literal">server_environment_files</tt> companion
|
are stored in the <tt class="docutils literal">server_environment_files</tt> companion module.</p>
|
||||||
module.</p>
|
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be
|
||||||
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be set using
|
set using an environment variable with a fallback on default values in
|
||||||
an environment variable with a fallback on default values in the database.</p>
|
the database.</p>
|
||||||
<p>The configuration read from the files are visible under the Configuration
|
<p>The configuration read from the files are visible under the
|
||||||
menu. If you are not in the ‘dev’ environment you will not be able to
|
Configuration menu. If you are not in the ‘dev’ environment you will not
|
||||||
see the values contained in the defined secret keys
|
be able to see the values contained in the defined secret keys (by
|
||||||
(by default : ‘<em>passw</em>’, ‘<em>key</em>’, ‘<em>secret</em>’ and ‘<em>token</em>’).</p>
|
default : ‘<em>passw</em>’, ‘<em>key</em>’, ‘<em>secret</em>’ and ‘<em>token</em>’).</p>
|
||||||
<p><strong>Table of contents</strong></p>
|
<p><strong>Table of contents</strong></p>
|
||||||
<div class="contents local topic" id="contents">
|
<div class="contents local topic" id="contents">
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
|
|
@ -407,13 +407,14 @@ see the values contained in the defined secret keys
|
||||||
<div class="section" id="installation">
|
<div class="section" id="installation">
|
||||||
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
|
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
|
||||||
<p>By itself, this module does little. See for instance the
|
<p>By itself, this module does little. See for instance the
|
||||||
<tt class="docutils literal">mail_environment</tt> addon which depends on this one to allow configuring
|
<tt class="docutils literal">mail_environment</tt> addon which depends on this one to allow
|
||||||
the incoming and outgoing mail servers depending on the environment.</p>
|
configuring the incoming and outgoing mail servers depending on the
|
||||||
|
environment.</p>
|
||||||
<p>You can store your configuration values in a companion module called
|
<p>You can store your configuration values in a companion module called
|
||||||
<tt class="docutils literal">server_environment_files</tt>. You can copy and customize the provided
|
<tt class="docutils literal">server_environment_files</tt>. You can copy and customize the provided
|
||||||
<tt class="docutils literal">server_environment_files_sample</tt> module for this purpose. Alternatively, you
|
<tt class="docutils literal">server_environment_files_sample</tt> module for this purpose.
|
||||||
can provide them in environment variables <tt class="docutils literal">SERVER_ENV_CONFIG</tt> and
|
Alternatively, you can provide them in environment variables
|
||||||
<tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>.</p>
|
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="configuration">
|
<div class="section" id="configuration">
|
||||||
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
|
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
|
||||||
|
|
@ -424,34 +425,37 @@ used values are ‘dev’, ‘test’, ‘production’:</p>
|
||||||
[options]
|
[options]
|
||||||
running_env=dev
|
running_env=dev
|
||||||
</pre>
|
</pre>
|
||||||
<p>Values associated to keys containing ‘passw’ are only displayed in the ‘dev’
|
<p>Values associated to keys containing ‘passw’ are only displayed in the
|
||||||
environment.</p>
|
‘dev’ environment.</p>
|
||||||
<p>If you don’t provide any value, <cite>test</cite> is used as a safe default.</p>
|
<p>If you don’t provide any value, test is used as a safe default.</p>
|
||||||
<p>You have several possibilities to set configuration values:</p>
|
<p>You have several possibilities to set configuration values:</p>
|
||||||
<div class="section" id="server-environment-files">
|
<div class="section" id="server-environment-files">
|
||||||
<h2><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h2>
|
<h2><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h2>
|
||||||
<p>You can edit the settings you need in the <tt class="docutils literal">server_environment_files</tt> addon. The
|
<p>You can edit the settings you need in the <tt class="docutils literal">server_environment_files</tt>
|
||||||
<tt class="docutils literal">server_environment_files_sample</tt> can be used as an example:</p>
|
addon. The <tt class="docutils literal">server_environment_files_sample</tt> can be used as an
|
||||||
|
example:</p>
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
<li>values common to all / most environments can be stored in the
|
<li>values common to all / most environments can be stored in the
|
||||||
<tt class="docutils literal">default/</tt> directory using the .ini file syntax;</li>
|
<tt class="docutils literal">default/</tt> directory using the .ini file syntax;</li>
|
||||||
<li>each environment you need to define is stored in its own directory
|
<li>each environment you need to define is stored in its own directory
|
||||||
and can override or extend default values;</li>
|
and can override or extend default values;</li>
|
||||||
<li>you can override or extend values in the main configuration
|
<li>you can override or extend values in the main configuration file of
|
||||||
file of your instance;</li>
|
your instance;</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="environment-variable">
|
<div class="section" id="environment-variable">
|
||||||
<h2><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h2>
|
<h2><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h2>
|
||||||
<p>You can define configuration in the environment variable <tt class="docutils literal">SERVER_ENV_CONFIG</tt>
|
<p>You can define configuration in the environment variable
|
||||||
and/or <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>. The 2 variables are handled the exact same
|
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and/or <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>. The 2
|
||||||
way, this is only a convenience for the deployment where you can isolate the
|
variables are handled the exact same way, this is only a convenience for
|
||||||
secrets in a different, encrypted, file. They are multi-line environment variables
|
the deployment where you can isolate the secrets in a different,
|
||||||
in the same configparser format than the files.
|
encrypted, file. They are multi-line environment variables in the same
|
||||||
If you used options in <tt class="docutils literal">server_environment_files</tt>, the options set in the
|
configparser format than the files. If you used options in
|
||||||
environment variable override them.</p>
|
<tt class="docutils literal">server_environment_files</tt>, the options set in the environment
|
||||||
<p>The options in the environment variable are not dependent of <tt class="docutils literal">running_env</tt>,
|
variable override them.</p>
|
||||||
the content of the variable must be set accordingly to the running environment.</p>
|
<p>The options in the environment variable are not dependent of
|
||||||
|
<tt class="docutils literal">running_env</tt>, the content of the variable must be set accordingly to
|
||||||
|
the running environment.</p>
|
||||||
<p>Example of setup:</p>
|
<p>Example of setup:</p>
|
||||||
<p>A public file, containing that will contain public variables:</p>
|
<p>A public file, containing that will contain public variables:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
|
|
@ -485,15 +489,14 @@ sftp_password=xxxxxxxxx
|
||||||
</pre>
|
</pre>
|
||||||
<p><strong>WARNING</strong></p>
|
<p><strong>WARNING</strong></p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<cite>my_sftp</cite> must match the name of the record.
|
my_sftp must match the name of the record. If you want something more
|
||||||
If you want something more reliable use <cite>server.env.techname.mixin</cite>
|
reliable use server.env.techname.mixin and use tech_name field to
|
||||||
and use <cite>tech_name</cite> field to reference records.
|
reference records. See “USAGE”.</blockquote>
|
||||||
See “USAGE”.</blockquote>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="default-values">
|
<div class="section" id="default-values">
|
||||||
<h2><a class="toc-backref" href="#toc-entry-5">Default values</a></h2>
|
<h2><a class="toc-backref" href="#toc-entry-5">Default values</a></h2>
|
||||||
<p>When using the <tt class="docutils literal">server.env.mixin</tt> mixin, for each env-computed field, a
|
<p>When using the <tt class="docutils literal">server.env.mixin</tt> mixin, for each env-computed field,
|
||||||
companion field <tt class="docutils literal"><field>_env_default</tt> is created. This field is not
|
a companion field <tt class="docutils literal"><field>_env_default</tt> is created. This field is not
|
||||||
environment-dependent. It’s a fallback value used when no key is set in
|
environment-dependent. It’s a fallback value used when no key is set in
|
||||||
configuration files / environment variable.</p>
|
configuration files / environment variable.</p>
|
||||||
<p>When the default field is used, the field is made editable on Odoo.</p>
|
<p>When the default field is used, the field is made editable on Odoo.</p>
|
||||||
|
|
@ -501,13 +504,14 @@ configuration files / environment variable.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="server-environment-integration">
|
<div class="section" id="server-environment-integration">
|
||||||
<h2><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h2>
|
<h2><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h2>
|
||||||
<p>Read the documentation of the class <a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a>.</p>
|
<p>Read the documentation of the class
|
||||||
|
<a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="usage">
|
<div class="section" id="usage">
|
||||||
<h1><a class="toc-backref" href="#toc-entry-7">Usage</a></h1>
|
<h1><a class="toc-backref" href="#toc-entry-7">Usage</a></h1>
|
||||||
<p>You can include a mixin in your model and configure the env-computed fields
|
<p>You can include a mixin in your model and configure the env-computed
|
||||||
by an override of <tt class="docutils literal">_server_env_fields</tt>.</p>
|
fields by an override of <tt class="docutils literal">_server_env_fields</tt>.</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
class StorageBackend(models.Model):
|
class StorageBackend(models.Model):
|
||||||
_name = "storage.backend"
|
_name = "storage.backend"
|
||||||
|
|
@ -517,7 +521,8 @@ class StorageBackend(models.Model):
|
||||||
def _server_env_fields(self):
|
def _server_env_fields(self):
|
||||||
return {"directory_path": {}}
|
return {"directory_path": {}}
|
||||||
</pre>
|
</pre>
|
||||||
<p>Read the documentation of the class and methods in <a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a>.</p>
|
<p>Read the documentation of the class and methods in
|
||||||
|
<a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a>.</p>
|
||||||
<p>If you want to have a technical name to reference:</p>
|
<p>If you want to have a technical name to reference:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
class StorageBackend(models.Model):
|
class StorageBackend(models.Model):
|
||||||
|
|
@ -532,9 +537,11 @@ class StorageBackend(models.Model):
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
<li>it is not possible to set the environment from the command line. A
|
<li>it is not possible to set the environment from the command line. A
|
||||||
configuration file must be used.</li>
|
configuration file must be used.</li>
|
||||||
<li>the module does not allow to set low level attributes such as database server, etc.</li>
|
<li>the module does not allow to set low level attributes such as
|
||||||
<li><cite>server.env.techname.mixin</cite>’s <cite>tech_name</cite> field could leverage the new option
|
database server, etc.</li>
|
||||||
for computable / writable fields and get rid of some onchange / read / write code.</li>
|
<li>server.env.techname.mixin’s tech_name field could leverage the new
|
||||||
|
option for computable / writable fields and get rid of some onchange
|
||||||
|
/ read / write code.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="bug-tracker">
|
<div class="section" id="bug-tracker">
|
||||||
|
|
@ -542,7 +549,7 @@ for computable / writable fields and get rid of some onchange / read / write cod
|
||||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
|
||||||
In case of trouble, please check there if your issue has already been reported.
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
||||||
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="credits">
|
<div class="section" id="credits">
|
||||||
|
|
@ -577,7 +584,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.</p>
|
promote its widespread use.</p>
|
||||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/16.0/server_environment">OCA/server-env</a> project on GitHub.</p>
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/17.0/server_environment">OCA/server-env</a> project on GitHub.</p>
|
||||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue