Skip to content
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

[17.0][OU-ADD] openupgrade_framework: framework patches #4327

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7145adf
[INIT] Full refactor of the OpenUpgrade project
legalsylvain Nov 1, 2020
8683fd9
[DEL] openupgrade_records -> server-tools/14.0
StefanRijnhart Nov 29, 2020
ae78c24
[RFR] OpenUpgrade framework patches
StefanRijnhart Dec 6, 2020
c9472e0
[UPD] README.rst
OCA-git-bot Jan 20, 2021
44d8f2f
[ADD] icon.png
OCA-git-bot Jan 20, 2021
735492b
[FIX] _logger.warn -> _logger.warning
MiquelRForgeFlow Mar 25, 2021
c2d6588
[FIX] doc: base must be included in --load parameter
MiquelRForgeFlow Mar 25, 2021
1d6b423
[UPD] README.rst
OCA-git-bot Mar 25, 2021
27fa1f6
[FIX] base: Don't fail uninstalling when missing models
MiquelRForgeFlow Apr 8, 2021
8ae6847
[FIX] openupgrade_framework: _drop_column was in wrong class
MiquelRForgeFlow Apr 12, 2021
49501e8
[DOC] add banner file, to make this module more visible on the app st…
legalsylvain Jun 10, 2021
5a8ef1c
[UPD] README.rst
OCA-git-bot Jun 10, 2021
2d6018d
[FIX] Don't break on missing model in selection _process_ondelete
StefanRijnhart Jul 7, 2021
826366a
[REF] Add maintainers
legalsylvain Aug 4, 2021
a2686cf
[UPD] README.rst
OCA-git-bot Aug 5, 2021
21d49aa
[IMP] openupgrade_framework: avoid AttributeError in view validation
MiquelRForgeFlow Oct 4, 2021
789b40f
[MIG][15.0] openupgrade_framework
legalsylvain Nov 15, 2021
add83ab
[REF] adapt framework, due to renaming handle_view_error into _raise_…
legalsylvain Nov 15, 2021
357568b
fixup! [WIP][15.0] base module
legalsylvain Nov 15, 2021
01920f7
fixup! fixup! [WIP][15.0] base module
legalsylvain Nov 15, 2021
8f8a282
Update method _postprocess_view of ir_ui_view by removing the input a…
jcdrubay May 10, 2022
725e2e1
[MIG] remove the odoo_patch on function _postprocess_view which becam…
jcdrubay May 11, 2022
9dfda1b
Adjustements for code style
jcdrubay May 12, 2022
9f18f92
[UPD] README.rst
OCA-git-bot May 18, 2022
5876638
[OU-FIX] Migration scripts were not run during install
StefanRijnhart Feb 27, 2022
681da28
[IMP] openupgrade_framework: tracking number of rows per table before
royle-vietnam Jun 8, 2022
b21b507
Revert "[IMP][15.0] openupgrade_framework: tracking number of rows pe…
StefanRijnhart Jun 22, 2022
87b01e7
[IMP] openupgrade_framework: to not crash, simply not deactivating the
royle-vietnam Jul 11, 2022
ecafe3f
[IMP] openupgrade_framework: add environ parameter to force demo
MiquelRForgeFlow Jun 20, 2022
db9fab4
[UPD] README.rst
OCA-git-bot Jul 18, 2022
f2683d4
[IMP] base: override to not raise an exception
royle-vietnam May 14, 2022
5e033a0
[FIX] openupgrade_framework: Proper module dependency resolution
pedrobaeza Jul 24, 2022
0450742
[FIX] framework: monkeypatch needs to patch original method
MiquelRForgeFlow Sep 13, 2022
68814af
[FIX] framework: monkeypatch needs to patch original method (fixup)
MiquelRForgeFlow Sep 14, 2022
5f5b485
[MIG] openupgrade_framework v16
hbrunn Jan 10, 2023
415b85f
[ADD] implement tests of migrations
hbrunn Jan 17, 2023
e5b22e2
[UPD] README.rst
OCA-git-bot Mar 24, 2023
7fed531
[FIX] Add openupgradelib dependencies in manifest files
legalsylvain Mar 27, 2023
49566f5
[UPD] README.rst
OCA-git-bot Sep 3, 2023
d09a9a6
[OU-FIX] don't fail when there's an unknown field in a view
hbrunn Dec 22, 2023
08ae911
[IMP] openupgrade_framework: pre-commit auto fixes
acpMicrocom Feb 28, 2024
e104cf7
[MIG] openupgrade_framework: Migration to 17.0
acpMicrocom Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions openupgrade_framework/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
=====================
Openupgrade Framework
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:06d77ecf97625ec075fa31dde7f8f41bcf849fa13af0598f8c1de397348f2dfd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fopenupgrade-lightgray.png?logo=github
:target: https://github.com/OCA/openupgrade/tree/17.0/openupgrade_framework
:alt: OCA/openupgrade
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/openupgrade-17-0/openupgrade-17-0-openupgrade_framework
: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/openupgrade&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is a technical module that contains a number of
monkeypatches to improve the behaviour of Odoo when migrating your
database using the OpenUpgrade migration scripts:

- Prevent dropping columns or tables in the database when fields or
models are obsoleted in the Odoo data model of the target release.
After the migration, you can review and delete unused database tables
and columns using database_cleanup. See
https://odoo-community.org/shop/product/database-cleanup-918
- When data records are deleted during the migration (such as views or
other system records), this is done in a secure mode. If the deletion
fails because of some unforeseen dependency, the deletion will be
cancelled and a message is logged, after which the migration
continues.
- Prevent a number of log messages that do not apply when using
OpenUpgrade.
- Suppress log messages about failed view validation, which are to be
expected during a migration.
- Run migration scripts for modules that are installed as new
dependencies of upgraded modules (when there are such scripts for
those particular modules)
- Production databases generated with demo data, will be transformed to
non-demo ones. If you want to avoid that, you have to pass through
the environment variable OPENUPGRADE_USE_DEMO, the value "yes".

For detailed documentation see:

- https://github.com/OCA/OpenUpgrade/
- https://oca.github.io/OpenUpgrade

**Table of contents**

.. contents::
:local:

Installation
============

This module does not need to be installed on a database. It simply needs
to be available via your ``addons-path``.

Configuration
=============

- call your odoo instance with the option
``--load=base,web,openupgrade_framework``

or

- add the key to your configuration file:

.. code:: shell

[options]
server_wide_modules = web,openupgrade_framework

When you load the module in either way of these ways, and you have the
openupgrade_scripts module in your addons path available, the
--upgrade-path option of Odoo will be set automatically to the location
of the OpenUpgrade migration scripts.

Development
===========

The odoo_patch folder contains python files in a tree that mimicks the
folder tree of the Odoo project. It contains a number of monkey patches
to improve the migration of an Odoo database between two major versions.

So far, we are able to make everything work without overwriting large
blocks of code, but if larger patches need to be added, please use the
method described below:

To see the patches added, you can use ``meld`` tools:

``meld PATH_TO_ODOO_FOLDER/odoo/ PATH_TO_OPENUPGRADE_FRAMEWORK_MODULE/odoo_patch``

To make more easy the diff analysis :

- Make sure the python files has the same path as the original one.
- Keep the same indentation as the original file. (using ``if True:``
if required)
- Add the following two lines at the beginning of your file, to avoid
flake8 / pylint errors

.. code:: python

# flake8: noqa
# pylint: skip-file

- When you want to change the code. add the following tags:

For an addition:

.. code:: python

# <OpenUpgrade:ADD>
some code...
# </OpenUpgrade>

For a change:

.. code:: python

# <OpenUpgrade:CHANGE>
some code...
# </OpenUpgrade>

For a removal:

.. code:: python

# <OpenUpgrade:REMOVE>
# Comment the code, instead of removing it.
# </OpenUpgrade>

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/openupgrade/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/openupgrade/issues/new?body=module:%20openupgrade_framework%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.

Credits
=======

Authors
-------

* Therp BV
* Opener B.V.
* GRAP
* Hunki Enterprises BV

Contributors
------------

- Stefan Rijnhart <stefan@opener.amsterdam>
- Sylvain LE GAL <https://twitter.com/legalsylvain>

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

Many developers have contributed to the OpenUpgrade framework in its
previous incarnation. Their original contributions may no longer needed,
or they are no longer recognizable in their current form but OpenUpgrade
would not have existed at this point without them.

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px
:target: https://github.com/legalsylvain
:alt: legalsylvain
.. |maintainer-StefanRijnhart| image:: https://github.com/StefanRijnhart.png?size=40px
:target: https://github.com/StefanRijnhart
:alt: StefanRijnhart
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-legalsylvain| |maintainer-StefanRijnhart| |maintainer-hbrunn|

This module is part of the `OCA/openupgrade <https://github.com/OCA/openupgrade/tree/17.0/openupgrade_framework>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
16 changes: 16 additions & 0 deletions openupgrade_framework/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging
import os

from odoo.modules import get_module_path
from odoo.tools import config

from . import odoo_patch

if not config.get("upgrade_path"):
path = get_module_path("openupgrade_scripts", display_warning=False)
if path:
logging.getLogger(__name__).info(
"Setting upgrade_path to the scripts directory inside the module "
"location of openupgrade_scripts"
)
config["upgrade_path"] = os.path.join(path, "scripts")
18 changes: 18 additions & 0 deletions openupgrade_framework/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Openupgrade Framework",
"summary": """Module to integrate in the server_wide_modules
option to make upgrades between two major revisions.""",
"author": "Odoo Community Association (OCA), Therp BV, Opener B.V., GRAP, "
"Hunki Enterprises BV",
"maintainers": ["legalsylvain", "StefanRijnhart", "hbrunn"],
"website": "https://github.com/OCA/OpenUpgrade",
"category": "Migration",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": ["base"],
"images": ["static/description/banner.jpg"],
"external_dependencies": {"python": ["openupgradelib"]},
"installable": True,
}
1 change: 1 addition & 0 deletions openupgrade_framework/odoo_patch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import odoo
1 change: 1 addition & 0 deletions openupgrade_framework/odoo_patch/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import addons, api, models, modules, tests
1 change: 1 addition & 0 deletions openupgrade_framework/odoo_patch/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_model
from . import ir_ui_view
103 changes: 103 additions & 0 deletions openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade

from odoo import api, models
from odoo.tools import mute_logger

from odoo.addons.base.models.ir_model import (
IrModel,
IrModelData,
IrModelFields,
IrModelRelation,
IrModelSelection,
)


def _drop_table(self):
"""Never drop tables"""
for model in self:
if self.env.get(model.model) is not None:
openupgrade.message(
self.env.cr,
"Unknown",
False,
False,
"Not dropping the table or view of model %s",
model.model,
)


IrModel._drop_table = _drop_table


def _drop_column(self):
"""Never drop columns"""
for field in self:
if field.name in models.MAGIC_COLUMNS:
continue
openupgrade.message(
self.env.cr,
"Unknown",
False,
False,
"Not dropping the column of field %s of model %s",
field.name,
field.model,
)
continue


IrModelFields._drop_column = _drop_column


@api.model
def _module_data_uninstall(self, modules_to_remove):
"""To pass context, that the patch in __getitem__ of api.Environment uses"""
patched_self = self.with_context(**{"missing_model": True})
return IrModelData._module_data_uninstall._original_method(
patched_self, modules_to_remove
)


_module_data_uninstall._original_method = IrModelData._module_data_uninstall
IrModelData._module_data_uninstall = _module_data_uninstall


@api.model
def _process_end(self, modules):
"""Don't warn about upgrade conventions from Odoo
('fields should be explicitly removed by an upgrade script')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning was removed from Odoo in odoo/odoo#56657
This patch can be removed here.

"""
with mute_logger("odoo.addons.base.models.ir_model"):
return IrModelData._process_end._original_method(self, modules)


_process_end._original_method = IrModelData._process_end
IrModelData._process_end = _process_end


def _module_data_uninstall(self):
"""Don't delete many2many relation tables. Only unlink the
ir.model.relation record itself.
"""
self.unlink()


IrModelRelation._module_data_uninstall = _module_data_uninstall


def _process_ondelete(self):
"""Don't break on missing models when deleting their selection fields"""
to_process = self.browse([])
for selection in self:
try:
self.env[selection.field_id.model] # pylint: disable=pointless-statement
to_process += selection
except KeyError:
continue
return IrModelSelection._process_ondelete._original_method(to_process)


_process_ondelete._original_method = IrModelSelection._process_ondelete
IrModelSelection._process_ondelete = _process_ondelete
Loading
Loading