-
-
Notifications
You must be signed in to change notification settings - Fork 211
[19.0][ADD] fs_storage_environment: make server_environment an optional dependency #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yankinmax
wants to merge
2
commits into
OCA:19.0
Choose a base branch
from
camptocamp:19-dr-fs_storage
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| """Install the glue module once fs_storage upgrade succeeded.""" | ||
| module = env["ir.module.module"].search( | ||
| [ | ||
| ("name", "=", "fs_storage_environment"), | ||
| ("state", "=", "uninstalled"), | ||
| ], | ||
| limit=1, | ||
| ) | ||
| if not module: | ||
| return | ||
| module.button_install() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| from odoo.tools import SQL | ||
|
|
||
| from odoo.addons.base.models.ir_model import field_xmlid | ||
|
|
||
|
|
||
| def _get_server_env_mixin_fnames(cr, model: str) -> set[str]: | ||
| """Return the core mixin field names present on the model.""" | ||
| possible_fnames = ("server_env_defaults", "tech_name") | ||
| cr.execute( | ||
| SQL( | ||
| """ | ||
| SELECT name | ||
| FROM ir_model_fields | ||
| WHERE model = %(model)s | ||
| AND name IN %(possible_fnames)s | ||
| """, | ||
| model=model, | ||
| possible_fnames=possible_fnames, | ||
| ) | ||
| ) | ||
| return {row[0] for row in cr.fetchall()} | ||
|
|
||
|
|
||
| def _get_server_env_mixin_magic_fnames(cr, model): | ||
| """Return the dynamic server_environment helper fields for the model. | ||
|
|
||
| These are the fields created on the fly by server.env.mixin: | ||
| - x_<field_name>_env_default | ||
| - x_<field_name>_env_is_editable | ||
| """ | ||
| cr.execute( | ||
| SQL( | ||
| """ | ||
| SELECT name | ||
| FROM ir_model_fields | ||
| WHERE model = %(model)s | ||
| AND ( | ||
| name LIKE 'x_%%_env_default' | ||
| OR name LIKE 'x_%%_env_is_editable' | ||
| ) | ||
| """, | ||
| model=model, | ||
| ) | ||
| ) | ||
| return {row[0] for row in cr.fetchall()} | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| """Move XMLIDs to the glue module. | ||
|
|
||
| This keeps the server_environment ir.model.fields metadata attached to the | ||
| new module and preserves field values. | ||
| """ | ||
| cr = env.cr | ||
| if not version: | ||
| return | ||
|
|
||
| model = "fs.storage" | ||
| old_module = "fs_storage" | ||
| new_module = "fs_storage_environment" | ||
|
|
||
| mixin_fnames = _get_server_env_mixin_fnames(cr, model) | ||
| magic_fnames = _get_server_env_mixin_magic_fnames(cr, model) | ||
| to_move_fnames = mixin_fnames | magic_fnames | ||
|
|
||
| rename_specs = [ | ||
| (field_xmlid(old_module, model, fname), field_xmlid(new_module, model, fname)) | ||
| for fname in to_move_fnames | ||
| ] | ||
| openupgrade.rename_xmlids(cr, rename_specs, allow_merge=True) | ||
|
|
||
| # Add noupdate to the magic_fnames, to prevent Odoo from deleting them in upgrade | ||
| if magic_fnames: | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE ir_model_data SET noupdate = TRUE | ||
| WHERE module = %(module)s | ||
| AND name IN %(names)s | ||
| """, | ||
| dict( | ||
| module=new_module, | ||
| names=tuple( | ||
| field_xmlid(new_module, model, fname).split(".")[1] | ||
| for fname in magic_fnames | ||
| ), | ||
| ), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had several times an issue with
openupgradelibno available. I don't get why.