Skip to content

Commit 0e3be21

Browse files
committed
[19.0][ADD] fs_storage_environment: make server_environment an optional dependency
1 parent 0eb8c38 commit 0e3be21

16 files changed

Lines changed: 783 additions & 26 deletions

File tree

fs_storage/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"security/ir.model.access.csv",
1818
"wizards/fs_test_connection.xml",
1919
],
20-
"external_dependencies": {"python": ["fsspec>=2024.5.0"]},
20+
"external_dependencies": {"python": ["fsspec>=2024.5.0", "openupgradelib>=3.6.0"]},
2121
"installable": True,
2222
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
@openupgrade.migrate()
8+
def migrate(env, version):
9+
"""Install the glue module once fs_storage upgrade succeeded."""
10+
module = env["ir.module.module"].search(
11+
[
12+
("name", "=", "fs_storage_environment"),
13+
("state", "=", "uninstalled"),
14+
],
15+
limit=1,
16+
)
17+
if not module:
18+
return
19+
module.button_install()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from openupgradelib import openupgrade
5+
6+
from odoo.tools import SQL
7+
8+
from odoo.addons.base.models.ir_model import field_xmlid
9+
10+
11+
def _get_server_env_mixin_fnames(cr, model: str) -> set[str]:
12+
"""Return the core mixin field names present on the model."""
13+
possible_fnames = ("server_env_defaults", "tech_name")
14+
cr.execute(
15+
SQL(
16+
"""
17+
SELECT name
18+
FROM ir_model_fields
19+
WHERE model = %(model)s
20+
AND name IN %(possible_fnames)s
21+
""",
22+
model=model,
23+
possible_fnames=possible_fnames,
24+
)
25+
)
26+
return {row[0] for row in cr.fetchall()}
27+
28+
29+
def _get_server_env_mixin_magic_fnames(cr, model):
30+
"""Return the dynamic server_environment helper fields for the model.
31+
32+
These are the fields created on the fly by server.env.mixin:
33+
- x_<field_name>_env_default
34+
- x_<field_name>_env_is_editable
35+
"""
36+
cr.execute(
37+
SQL(
38+
"""
39+
SELECT name
40+
FROM ir_model_fields
41+
WHERE model = %(model)s
42+
AND (
43+
name LIKE 'x_%%_env_default'
44+
OR name LIKE 'x_%%_env_is_editable'
45+
)
46+
""",
47+
model=model,
48+
)
49+
)
50+
return {row[0] for row in cr.fetchall()}
51+
52+
53+
@openupgrade.migrate()
54+
def migrate(env, version):
55+
"""Move XMLIDs to the glue module.
56+
57+
This keeps the server_environment ir.model.fields metadata attached to the
58+
new module and preserves field values.
59+
"""
60+
cr = env.cr
61+
if not version:
62+
return
63+
64+
model = "fs.storage"
65+
old_module = "fs_storage"
66+
new_module = "fs_storage_environment"
67+
68+
mixin_fnames = _get_server_env_mixin_fnames(cr, model)
69+
magic_fnames = _get_server_env_mixin_magic_fnames(cr, model)
70+
to_move_fnames = mixin_fnames | magic_fnames
71+
72+
rename_specs = [
73+
(field_xmlid(old_module, model, fname), field_xmlid(new_module, model, fname))
74+
for fname in to_move_fnames
75+
]
76+
openupgrade.rename_xmlids(cr, rename_specs, allow_merge=True)
77+
78+
# Add noupdate to the magic_fnames, to prevent Odoo from deleting them in upgrade
79+
if magic_fnames:
80+
openupgrade.logged_query(
81+
cr,
82+
"""
83+
UPDATE ir_model_data SET noupdate = TRUE
84+
WHERE module = %(module)s
85+
AND name IN %(names)s
86+
""",
87+
dict(
88+
module=new_module,
89+
names=tuple(
90+
field_xmlid(new_module, model, fname).split(".")[1]
91+
for fname in magic_fnames
92+
),
93+
),
94+
)

fs_storage/upgrades/19.0.1.1.2/pre-update.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

fs_storage_environment/README.rst

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
5+
===============================================
6+
Filesystem Storage Backend - Server Environment
7+
===============================================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:156bf422ce912fb80137f8203230a58ff1f4159a2f6befa17aa9eec9fb6dbcd5
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
22+
:alt: License: LGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github
24+
:target: https://github.com/OCA/storage/tree/19.0/fs_storage_environment
25+
:alt: OCA/storage
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/storage-19-0/storage-19-0-fs_storage_environment
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=19.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
Glue module to make Server Environment features available for the
36+
Filesystem Storage Backend addon.
37+
38+
**Table of contents**
39+
40+
.. contents::
41+
:local:
42+
43+
Usage
44+
=====
45+
46+
Configuration
47+
-------------
48+
49+
When you create a new backend, you must specify the following:
50+
51+
- Resolve env vars. This options resolves the protocol options values
52+
starting with $ from environment variables
53+
54+
Server Environment
55+
------------------
56+
57+
To ease the management of the filesystem storages configuration accross
58+
the different environments, the configuration of the filesystem storages
59+
can be defined in environment files or directly in the main
60+
configuration file. For example, the configuration of a filesystem
61+
storage with the code fsprod can be provided in the main configuration
62+
file as follows:
63+
64+
.. code:: ini
65+
66+
[fs_storage.fsprod]
67+
protocol=s3
68+
options={"endpoint_url": "https://my_s3_server/", "key": "KEY", "secret": "SECRET"}
69+
directory_path=my_bucket
70+
71+
To work, a storage.backend record must exist with the code fsprod into
72+
the database. In your configuration section, you can specify the value
73+
for the following fields:
74+
75+
- protocol
76+
- options
77+
- directory_path
78+
79+
Bug Tracker
80+
===========
81+
82+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/storage/issues>`_.
83+
In case of trouble, please check there if your issue has already been reported.
84+
If you spotted it first, help us to smash it by providing a detailed and welcomed
85+
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_storage_environment%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
86+
87+
Do not contact contributors directly about support or help with technical issues.
88+
89+
Credits
90+
=======
91+
92+
Authors
93+
-------
94+
95+
* ACSONE SA/NV
96+
97+
Contributors
98+
------------
99+
100+
- Laurent Mignon <laurent.mignon@acsone.eu>
101+
- Sébastien BEAU <sebastien.beau@akretion.com>
102+
- Maksym Yankin <maksym.yankin@camptocamp.com>
103+
104+
Maintainers
105+
-----------
106+
107+
This module is maintained by the OCA.
108+
109+
.. image:: https://odoo-community.org/logo.png
110+
:alt: Odoo Community Association
111+
:target: https://odoo-community.org
112+
113+
OCA, or the Odoo Community Association, is a nonprofit organization whose
114+
mission is to support the collaborative development of Odoo features and
115+
promote its widespread use.
116+
117+
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/19.0/fs_storage_environment>`_ project on GitHub.
118+
119+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

fs_storage_environment/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2017 Akretion (http://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
{
6+
"name": "Filesystem Storage Backend - Server Environment",
7+
"summary": "Use Server Environment feature to manage the concept of Storage",
8+
"version": "19.0.1.0.0",
9+
"category": "FS Storage",
10+
"website": "https://github.com/OCA/storage",
11+
"author": " ACSONE SA/NV, Odoo Community Association (OCA)",
12+
"license": "LGPL-3",
13+
"development_status": "Beta",
14+
"depends": ["fs_storage", "server_environment"],
15+
"auto_install": True,
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import fs_storage
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2023 ACSONE SA/NV (https://www.acsone.eu).
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
from odoo import models
5+
6+
7+
class FSStorage(models.Model):
8+
_name = "fs.storage"
9+
_inherit = ["fs.storage", "server.env.mixin"]
10+
_server_env_section_name_field = "code"
11+
12+
@property
13+
def _server_env_fields(self):
14+
return {
15+
"protocol": {},
16+
"options": {},
17+
"directory_path": {},
18+
"eval_options_from_env": {},
19+
"model_xmlids": {},
20+
"field_xmlids": {},
21+
"check_connection_method": {},
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)