Skip to content

Commit a961ea1

Browse files
committed
Fix inheritance of server env techname mixin
In case a model was inheriting both server.env.mixin and server.env.techname.mixin the value of _server_env_section_name_field was depending on the order in which the mixins were inherited on that model. If server.env.mixin was inherit first as in: _name = "my.model" _inherit = ["my.model", "server.env.mixin", "server.env.techname.mixin"] Then the value of _server_env_section_name would be `name` If server.env.techname.mixin was inherit first as in: _name = "my.model" _inherit = ["my.model", "server.env.techname.mixin", "server.env.mixin"] Then the value of _server_env_section_name would be `tech_name` To avoid this, since the server.env.techname.mixin changes an attribute of server.env.mixin, server.env.techname.mixin must inherit the server.env.mixin. With this, only one of the mixins needs to be inherited and there cannot be any 'silent' issue, where the _server_env_section_name depends on the order on which mixins are inherited.
1 parent 5290aa4 commit a961ea1

5 files changed

Lines changed: 63 additions & 67 deletions

File tree

server_environment/README.rst

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
======================================
62
server configuration environment files
73
======================================
@@ -17,7 +13,7 @@ server configuration environment files
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Production/Stable
20-
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2218
:alt: License: LGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
@@ -100,12 +96,12 @@ You can edit the settings you need in the ``server_environment_files``
10096
addon. The ``server_environment_files_sample`` can be used as an
10197
example:
10298

103-
- values common to all / most environments can be stored in the
104-
``default/`` directory using the .ini file syntax;
105-
- each environment you need to define is stored in its own directory and
106-
can override or extend default values;
107-
- you can override or extend values in the main configuration file of
108-
your instance;
99+
- values common to all / most environments can be stored in the
100+
``default/`` directory using the .ini file syntax;
101+
- each environment you need to define is stored in its own directory
102+
and can override or extend default values;
103+
- you can override or extend values in the main configuration file of
104+
your instance;
109105

110106
Environment variable
111107
--------------------
@@ -181,7 +177,9 @@ Server environment integration
181177
------------------------------
182178

183179
Read the documentation of the class
184-
`models/server_env_mixin.py <models/server_env_mixin.py>`__.
180+
`models/server_env_mixin.py <models/server_env_mixin.py>`__ and
181+
[models/server_env_tech_name_mixin.py]
182+
(models/server_env_tech_name_mixin.py)
185183

186184
Usage
187185
=====
@@ -208,20 +206,20 @@ If you want to have a technical name to reference:
208206

209207
class StorageBackend(models.Model):
210208
_name = "storage.backend"
211-
_inherit = ["storage.backend", "server.env.techname.mixin", "server.env.mixin"]
209+
_inherit = ["storage.backend", "server.env.techname.mixin"]
212210

213211
[...]
214212

215213
Known issues / Roadmap
216214
======================
217215

218-
- it is not possible to set the environment from the command line. A
219-
configuration file must be used.
220-
- the module does not allow to set low level attributes such as database
221-
server, etc.
222-
- server.env.techname.mixin's tech_name field could leverage the new
223-
option for computable / writable fields and get rid of some onchange /
224-
read / write code.
216+
- it is not possible to set the environment from the command line. A
217+
configuration file must be used.
218+
- the module does not allow to set low level attributes such as
219+
database server, etc.
220+
- server.env.techname.mixin's tech_name field could leverage the new
221+
option for computable / writable fields and get rid of some onchange
222+
/ read / write code.
225223

226224
Bug Tracker
227225
===========
@@ -244,18 +242,18 @@ Authors
244242
Contributors
245243
------------
246244

247-
- Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
248-
- Nicolas Bessi <nicolas.bessi@camptocamp.com>
249-
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
250-
- Daniel Reis <dgreis@sapo.pt>
251-
- Holger Brunn <hbrunn@therp.nl>
252-
- Leonardo Pistone <leonardo.pistone@camptocamp.com>
253-
- Adrien Peiffer <adrien.peiffer@acsone.com>
254-
- Thierry Ducrest <thierry.ducrest@camptocamp.com>
255-
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
256-
- Thomas Binfeld <thomas.binsfeld@acsone.eu>
257-
- Stéphane Bidoul <stefane.bidoul@acsone.com>
258-
- Simone Orsi <simahawk@gmail.com>
245+
- Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
246+
- Nicolas Bessi <nicolas.bessi@camptocamp.com>
247+
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
248+
- Daniel Reis <dgreis@sapo.pt>
249+
- Holger Brunn <hbrunn@therp.nl>
250+
- Leonardo Pistone <leonardo.pistone@camptocamp.com>
251+
- Adrien Peiffer <adrien.peiffer@acsone.com>
252+
- Thierry Ducrest <thierry.ducrest@camptocamp.com>
253+
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
254+
- Thomas Binfeld <thomas.binsfeld@acsone.eu>
255+
- Stéphane Bidoul <stefane.bidoul@acsone.com>
256+
- Simone Orsi <simahawk@gmail.com>
259257

260258
Maintainers
261259
-----------

server_environment/models/server_env_tech_name_mixin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ class ServerEnvTechNameMixin(models.AbstractModel):
1414
This mixin helps solve the problem by providing a tech name field
1515
and a cleanup machinery as well as a unique constrain.
1616
17-
To use this mixin add it to the _inherit attr of your module like:
17+
To use this mixin add it to the _inherit attr of your model like:
18+
(instead of `server.env.mixin`)
1819
1920
_inherit = [
2021
"my.model",
2122
"server.env.techname.mixin",
22-
"server.env.mixin",
2323
]
2424
2525
"""
2626

2727
_name = "server.env.techname.mixin"
28+
_inherit = "server.env.mixin"
2829
_description = "Server environment technical name"
2930
_sql_constraints = [
3031
(

server_environment/readme/CONFIGURE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ Note: empty environment keys always take precedence over default fields
9797
## Server environment integration
9898

9999
Read the documentation of the class
100-
[models/server_env_mixin.py](models/server_env_mixin.py).
100+
[models/server_env_mixin.py](models/server_env_mixin.py) and [models/server_env_tech_name_mixin.py]
101+
(models/server_env_tech_name_mixin.py)

server_environment/readme/USAGE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ If you want to have a technical name to reference:
1616

1717
class StorageBackend(models.Model):
1818
_name = "storage.backend"
19-
_inherit = ["storage.backend", "server.env.techname.mixin", "server.env.mixin"]
19+
_inherit = ["storage.backend", "server.env.techname.mixin"]
2020

2121
[...]

server_environment/static/description/index.html

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>server configuration environment files</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="server-configuration-environment-files">
364+
<h1 class="title">server configuration environment files</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="server-configuration-environment-files">
370-
<h1>server configuration environment files</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:63b219d993d67edff4ef7cdfdb79606dce9435d848bf3c0e56252b4f5fd2d415
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/license-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>
372+
<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/license-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>
378373
<p>This module provides a way to define an environment in the main Odoo
379374
configuration file and to read some configurations from files depending
380375
on the configured environment: you define the environment in the main
@@ -410,7 +405,7 @@ <h1>server configuration environment files</h1>
410405
</ul>
411406
</div>
412407
<div class="section" id="installation">
413-
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
408+
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
414409
<p>By itself, this module does little. See for instance the
415410
<tt class="docutils literal">mail_environment</tt> addon which depends on this one to allow
416411
configuring the incoming and outgoing mail servers depending on the
@@ -422,7 +417,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
422417
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>.</p>
423418
</div>
424419
<div class="section" id="configuration">
425-
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
420+
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
426421
<p>To configure this module, you need to edit the main configuration file
427422
of your instance, and add a directive called <tt class="docutils literal">running_env</tt>. Commonly
428423
used values are ‘dev’, ‘test’, ‘production’:</p>
@@ -441,21 +436,21 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
441436
<p>If you don’t provide any value, test is used as a safe default.</p>
442437
<p>You have several possibilities to set configuration values:</p>
443438
<div class="section" id="server-environment-files">
444-
<h3><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h3>
439+
<h2><a class="toc-backref" href="#toc-entry-3">server_environment_files</a></h2>
445440
<p>You can edit the settings you need in the <tt class="docutils literal">server_environment_files</tt>
446441
addon. The <tt class="docutils literal">server_environment_files_sample</tt> can be used as an
447442
example:</p>
448443
<ul class="simple">
449444
<li>values common to all / most environments can be stored in the
450445
<tt class="docutils literal">default/</tt> directory using the .ini file syntax;</li>
451-
<li>each environment you need to define is stored in its own directory and
452-
can override or extend default values;</li>
446+
<li>each environment you need to define is stored in its own directory
447+
and can override or extend default values;</li>
453448
<li>you can override or extend values in the main configuration file of
454449
your instance;</li>
455450
</ul>
456451
</div>
457452
<div class="section" id="environment-variable">
458-
<h3><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h3>
453+
<h2><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h2>
459454
<p>You can define configuration in the environment variable
460455
<tt class="docutils literal">SERVER_ENV_CONFIG</tt> and/or <tt class="docutils literal">SERVER_ENV_CONFIG_SECRET</tt>. The 2
461456
variables are handled the exact same way, this is only a convenience for
@@ -505,7 +500,7 @@ <h3><a class="toc-backref" href="#toc-entry-4">Environment variable</a></h3>
505500
reference records. See “USAGE”.</blockquote>
506501
</div>
507502
<div class="section" id="default-values">
508-
<h3><a class="toc-backref" href="#toc-entry-5">Default values</a></h3>
503+
<h2><a class="toc-backref" href="#toc-entry-5">Default values</a></h2>
509504
<p>When using the <tt class="docutils literal">server.env.mixin</tt> mixin, for each env-computed field,
510505
a companion field <tt class="docutils literal">&lt;field&gt;_env_default</tt> is created. This field is not
511506
environment-dependent. It’s a fallback value used when no key is set in
@@ -514,13 +509,15 @@ <h3><a class="toc-backref" href="#toc-entry-5">Default values</a></h3>
514509
<p>Note: empty environment keys always take precedence over default fields</p>
515510
</div>
516511
<div class="section" id="server-environment-integration">
517-
<h3><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h3>
512+
<h2><a class="toc-backref" href="#toc-entry-6">Server environment integration</a></h2>
518513
<p>Read the documentation of the class
519-
<a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a>.</p>
514+
<a class="reference external" href="models/server_env_mixin.py">models/server_env_mixin.py</a> and
515+
[models/server_env_tech_name_mixin.py]
516+
(models/server_env_tech_name_mixin.py)</p>
520517
</div>
521518
</div>
522519
<div class="section" id="usage">
523-
<h2><a class="toc-backref" href="#toc-entry-7">Usage</a></h2>
520+
<h1><a class="toc-backref" href="#toc-entry-7">Usage</a></h1>
524521
<p>You can include a mixin in your model and configure the env-computed
525522
fields by an override of <tt class="docutils literal">_server_env_fields</tt>.</p>
526523
<pre class="literal-block">
@@ -538,41 +535,41 @@ <h2><a class="toc-backref" href="#toc-entry-7">Usage</a></h2>
538535
<pre class="literal-block">
539536
class StorageBackend(models.Model):
540537
_name = &quot;storage.backend&quot;
541-
_inherit = [&quot;storage.backend&quot;, &quot;server.env.techname.mixin&quot;, &quot;server.env.mixin&quot;]
538+
_inherit = [&quot;storage.backend&quot;, &quot;server.env.techname.mixin&quot;]
542539

543540
[...]
544541
</pre>
545542
</div>
546543
<div class="section" id="known-issues-roadmap">
547-
<h2><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h2>
544+
<h1><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h1>
548545
<ul class="simple">
549546
<li>it is not possible to set the environment from the command line. A
550547
configuration file must be used.</li>
551-
<li>the module does not allow to set low level attributes such as database
552-
server, etc.</li>
548+
<li>the module does not allow to set low level attributes such as
549+
database server, etc.</li>
553550
<li>server.env.techname.mixin’s tech_name field could leverage the new
554-
option for computable / writable fields and get rid of some onchange /
555-
read / write code.</li>
551+
option for computable / writable fields and get rid of some onchange
552+
/ read / write code.</li>
556553
</ul>
557554
</div>
558555
<div class="section" id="bug-tracker">
559-
<h2><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h2>
556+
<h1><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h1>
560557
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
561558
In case of trouble, please check there if your issue has already been reported.
562559
If you spotted it first, help us to smash it by providing a detailed and welcomed
563560
<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>
564561
<p>Do not contact contributors directly about support or help with technical issues.</p>
565562
</div>
566563
<div class="section" id="credits">
567-
<h2><a class="toc-backref" href="#toc-entry-10">Credits</a></h2>
564+
<h1><a class="toc-backref" href="#toc-entry-10">Credits</a></h1>
568565
<div class="section" id="authors">
569-
<h3><a class="toc-backref" href="#toc-entry-11">Authors</a></h3>
566+
<h2><a class="toc-backref" href="#toc-entry-11">Authors</a></h2>
570567
<ul class="simple">
571568
<li>Camptocamp</li>
572569
</ul>
573570
</div>
574571
<div class="section" id="contributors">
575-
<h3><a class="toc-backref" href="#toc-entry-12">Contributors</a></h3>
572+
<h2><a class="toc-backref" href="#toc-entry-12">Contributors</a></h2>
576573
<ul class="simple">
577574
<li>Florent Xicluna (Wingo) &lt;<a class="reference external" href="mailto:florent.xicluna&#64;gmail.com">florent.xicluna&#64;gmail.com</a>&gt;</li>
578575
<li>Nicolas Bessi &lt;<a class="reference external" href="mailto:nicolas.bessi&#64;camptocamp.com">nicolas.bessi&#64;camptocamp.com</a>&gt;</li>
@@ -589,7 +586,7 @@ <h3><a class="toc-backref" href="#toc-entry-12">Contributors</a></h3>
589586
</ul>
590587
</div>
591588
<div class="section" id="maintainers">
592-
<h3><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h3>
589+
<h2><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h2>
593590
<p>This module is maintained by the OCA.</p>
594591
<a class="reference external image-reference" href="https://odoo-community.org">
595592
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -602,6 +599,5 @@ <h3><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h3>
602599
</div>
603600
</div>
604601
</div>
605-
</div>
606602
</body>
607603
</html>

0 commit comments

Comments
 (0)