Skip to content

Commit

Permalink
[MIG] server_environment: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvh332 committed Sep 24, 2024
1 parent b9ec8c3 commit 1105d02
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 81 deletions.
41 changes: 21 additions & 20 deletions server_environment/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ server configuration environment files
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
:target: https://github.com/OCA/server-env/tree/17.0/server_environment
:target: https://github.com/OCA/server-env/tree/18.0/server_environment
:alt: OCA/server-env
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-env-17-0/server-env-17-0-server_environment
:target: https://translation.odoo-community.org/projects/server-env-18-0/server-env-18-0-server_environment
:alt: Translate me on Weblate
.. |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=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -34,9 +34,9 @@ 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. you
will be able to overwrite some odoo options.
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
Expand Down Expand Up @@ -96,18 +96,12 @@ 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;
* In some platforms (like odoo.sh where production config file is copied to staging)
it can be usefull to overwrite options write in the `[options]` section. You must
allow the overwrite by adding `server_environment_allow_overwrite_options_section = True``
to the former `odoo.cfg` config file or through the environment variable:
`export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True` (if both are set
config file take precedent).
- 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
--------------------
Expand Down Expand Up @@ -231,7 +225,7 @@ Bug Tracker
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.
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:%2017.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:%2018.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.

Expand All @@ -258,6 +252,13 @@ Contributors
- Thomas Binfeld <[email protected]>
- Stéphane Bidoul <[email protected]>
- Simone Orsi <[email protected]>
- Thien Vo <[email protected]>

Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
-----------
Expand All @@ -272,6 +273,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/17.0/server_environment>`_ project on GitHub.
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/18.0/server_environment>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion server_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "server configuration environment files",
"version": "17.0.1.1.0",
"version": "18.0.1.0.0",
"depends": ["base", "base_sparse_field"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"summary": "move some configurations out of the database",
Expand Down
53 changes: 18 additions & 35 deletions server_environment/models/server_env_tech_name_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

import logging

from odoo import api, fields, models

from odoo.addons.http_routing.models.ir_http import slugify
_logger = logging.getLogger(__name__)


class ServerEnvTechNameMixin(models.AbstractModel):
Expand Down Expand Up @@ -35,43 +37,24 @@ class ServerEnvTechNameMixin(models.AbstractModel):
"`tech_name` must be unique!",
)
]
# TODO: could leverage the new option for computable / writable fields
# and get rid of some onchange / read / write code.
tech_name = fields.Char(
help="Unique name for technical purposes. Eg: server env keys.",
compute="_compute_tech_name",
copy=False,
readonly=False,
store=True,
help="Unique name for technical purposes. Eg: server env keys.",
)

_server_env_section_name_field = "tech_name"

@api.onchange("name")
def _onchange_name_for_tech(self):
# Keep this specific name for the method to avoid possible overrides
# of existing `_onchange_name` methods
if self.name and not self.tech_name:
self.tech_name = self.name

@api.onchange("tech_name")
def _onchange_tech_name(self):
if self.tech_name:
# make sure is normalized
self.tech_name = self._normalize_tech_name(self.tech_name)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
self._handle_tech_name(vals)
return super().create(vals_list)

def write(self, vals):
self._handle_tech_name(vals)
return super().write(vals)

def _handle_tech_name(self, vals):
# make sure technical names are always there
if not vals.get("tech_name") and vals.get("name"):
vals["tech_name"] = self._normalize_tech_name(vals["name"])

@staticmethod
def _normalize_tech_name(name):
return slugify(name).replace("-", "_")
@api.depends("name")
def _compute_tech_name(self):
for record in self:
if record.name and not record.tech_name:
record.tech_name = self._normalize_tech_name(record.name)
_logger.warning(
f"Tech name automatically generated from name: {record.tech_name}"
)

def _normalize_tech_name(self, name):
return self.env["ir.http"]._slugify(name).replace("-", "_")
1 change: 1 addition & 0 deletions server_environment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
- Thomas Binfeld \<<[email protected]>\>
- Stéphane Bidoul \<<[email protected]>\>
- Simone Orsi \<<[email protected]>\>
- Thien Vo \<<[email protected]>\>
1 change: 1 addition & 0 deletions server_environment/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
50 changes: 25 additions & 25 deletions server_environment/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,19 @@ <h1 class="title">server configuration environment files</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:261183b349b7fa17e4c205c3cda8bf4b06e629c65d04ad4b7bfd105901c60da9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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&amp;target_branch=17.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/18.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-18-0/server-env-18-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&amp;target_branch=18.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
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 <tt class="docutils literal">server_environment_files</tt> companion
module.</p>
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be set using
an environment variable with a fallback on default values in the database. you
will be able to overwrite some odoo options.</p>
<p>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 : ‘<em>passw</em>’, ‘<em>key</em>’, ‘<em>secret</em>’ and ‘<em>token</em>’).</p>
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 <tt class="docutils literal">server_environment_files</tt> companion module.</p>
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be
set using an environment variable with a fallback on default values in
the database.</p>
<p>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 : ‘<em>passw</em>’, ‘<em>key</em>’, ‘<em>secret</em>’ and ‘<em>token</em>’).</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -400,7 +399,8 @@ <h1 class="title">server configuration environment files</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-10">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-11">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-12">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-13">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-13">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-14">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -446,14 +446,8 @@ <h2><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h2>
<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
and can override or extend default values;</li>
<li>you can override or extend values in the main configuration
file of your instance;</li>
<li>In some platforms (like odoo.sh where production config file is copied to staging)
it can be usefull to overwrite options write in the <cite>[options]</cite> section. You must
allow the overwrite by adding <cite>server_environment_allow_overwrite_options_section = True`</cite>
to the former <cite>odoo.cfg</cite> config file or through the environment variable:
<cite>export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True</cite> (if both are set
config file take precedent).</li>
<li>you can override or extend values in the main configuration file of
your instance;</li>
</ul>
</div>
<div class="section" id="environment-variable">
Expand Down Expand Up @@ -562,7 +556,7 @@ <h1><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h1>
<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.
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:%2017.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:%2018.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>
</div>
<div class="section" id="credits">
Expand All @@ -588,18 +582,24 @@ <h2><a class="toc-backref" href="#toc-entry-12">Contributors</a></h2>
<li>Thomas Binfeld &lt;<a class="reference external" href="mailto:thomas.binsfeld&#64;acsone.eu">thomas.binsfeld&#64;acsone.eu</a>&gt;</li>
<li>Stéphane Bidoul &lt;<a class="reference external" href="mailto:stefane.bidoul&#64;acsone.com">stefane.bidoul&#64;acsone.com</a>&gt;</li>
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simahawk&#64;gmail.com">simahawk&#64;gmail.com</a>&gt;</li>
<li>Thien Vo &lt;<a class="reference external" href="mailto:thienvh&#64;trobz.com">thienvh&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-13">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</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>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/18.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>
</div>
</div>
Expand Down

0 comments on commit 1105d02

Please sign in to comment.