From acc80a128fa2663368493e90dbb1c6120b7d419b Mon Sep 17 00:00:00 2001 From: odooNextev Date: Wed, 30 Oct 2024 15:15:25 +0100 Subject: [PATCH] [FIX] migrazione --- l10n_it_accompanying_invoice/README.rst | 11 ++++++--- l10n_it_accompanying_invoice/__manifest__.py | 2 +- l10n_it_accompanying_invoice/hooks.py | 22 +++++++++++------- .../migrations/16.0.1.0.1/post-migration.py | 23 +++++++++++++++++++ .../{16.0.1.0.0 => 16.0.1.0.1}/pre-migrate.py | 8 +++---- .../readme/ROADMAP.md | 11 ++++++--- .../static/description/index.html | 10 +++++--- 7 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 l10n_it_accompanying_invoice/migrations/16.0.1.0.1/post-migration.py rename l10n_it_accompanying_invoice/migrations/{16.0.1.0.0 => 16.0.1.0.1}/pre-migrate.py (62%) diff --git a/l10n_it_accompanying_invoice/README.rst b/l10n_it_accompanying_invoice/README.rst index f682b4a5fe6..ddf3a8038cf 100644 --- a/l10n_it_accompanying_invoice/README.rst +++ b/l10n_it_accompanying_invoice/README.rst @@ -56,9 +56,14 @@ Known issues / Roadmap **Italiano** -Il modulo è stato migrato, ma gli script di migrazione non sono stati -provati e quindi sono stati commentati. Si possono provare in un -ambiente di test decommentando +Odoo Italia non supporta più i moduli alla versione 12.0 perciò non ci +siamo occupati ufficialmente della migrazione dei dati da questa +versione. + +Tuttavia se non si volessero perdere i dati già presenti nella versione +12.0 si potrebbe togliere la dipendenza dal modulo ``l10n_it_ddt`` nel +``__manifest__.py`` e lanciare gli script di migrazione commentati. Si +possono provare in un ambiente di test decommentando - il riferimento a ``hooks.py`` in ``__init__.py`` - ``external_dependencies`` e ``pre_init_hook`` in ``__manifest__.py`` diff --git a/l10n_it_accompanying_invoice/__manifest__.py b/l10n_it_accompanying_invoice/__manifest__.py index c77d56367cc..971aa845101 100644 --- a/l10n_it_accompanying_invoice/__manifest__.py +++ b/l10n_it_accompanying_invoice/__manifest__.py @@ -6,7 +6,7 @@ { "name": "ITA - Fattura accompagnatoria", "summary": "Stampa della fattura accompagnatoria", - "version": "16.0.1.0.0", + "version": "16.0.1.0.1", "category": "Accounting", "website": "https://github.com/OCA/l10n-italy" "/tree/16.0/l10n_it_accompanying_invoice", diff --git a/l10n_it_accompanying_invoice/hooks.py b/l10n_it_accompanying_invoice/hooks.py index 3b8399ec1dc..d297afeb70e 100644 --- a/l10n_it_accompanying_invoice/hooks.py +++ b/l10n_it_accompanying_invoice/hooks.py @@ -2,7 +2,6 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from openupgradelib import openupgrade -from openupgradelib.openupgrade import logged_query from odoo.tools import DotDict @@ -169,13 +168,13 @@ ] -def remove_models(cr, model_spec): - for name in model_spec: - logged_query( - cr, - "DELETE FROM ir_model WHERE model = %s", - (name,), - ) +# def remove_models(cr, model_spec): +# for name in model_spec: +# logged_query( +# cr, +# "DELETE FROM ir_model WHERE model = %s", +# (name,), +# ) def migrate_old_module(cr): @@ -216,4 +215,11 @@ def migrate_old_module(cr): def pre_absorb_old_module(cr): if openupgrade.is_module_installed(cr, "l10n_it_accompanying_invoice"): + openupgrade.update_module_names( + cr, + [ + ("l10n_it_fattura_accompagnatoria", "l10n_it_accompanying_invoice"), + ], + merge_modules=True, + ) migrate_old_module(cr) diff --git a/l10n_it_accompanying_invoice/migrations/16.0.1.0.1/post-migration.py b/l10n_it_accompanying_invoice/migrations/16.0.1.0.1/post-migration.py new file mode 100644 index 00000000000..a96582f9d89 --- /dev/null +++ b/l10n_it_accompanying_invoice/migrations/16.0.1.0.1/post-migration.py @@ -0,0 +1,23 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + +from .hooks import RENAMED_FIELDS + + +def _get_set_clause(fields_list): + set_fields_list = [f"{field[1]} = ai.{field[0]}" for field in fields_list] + set_fields_clause = ", ".join(set_fields_list) + return set_fields_clause + + +def migrate(cr, installed_version): + fields_list = [(field[0][1], field[1][1]) for field in RENAMED_FIELDS] + set_fields_clause = _get_set_clause(fields_list) + query = f""" +UPDATE account_move am +SET {set_fields_clause} +FROM account_invoice ai +WHERE am.old_invoice_id = ai.id + """ + openupgrade.logged_query(cr, query) diff --git a/l10n_it_accompanying_invoice/migrations/16.0.1.0.0/pre-migrate.py b/l10n_it_accompanying_invoice/migrations/16.0.1.0.1/pre-migrate.py similarity index 62% rename from l10n_it_accompanying_invoice/migrations/16.0.1.0.0/pre-migrate.py rename to l10n_it_accompanying_invoice/migrations/16.0.1.0.1/pre-migrate.py index f9a68b7ae79..c06e0aab3a3 100644 --- a/l10n_it_accompanying_invoice/migrations/16.0.1.0.0/pre-migrate.py +++ b/l10n_it_accompanying_invoice/migrations/16.0.1.0.1/pre-migrate.py @@ -6,9 +6,9 @@ # but it raises # > ImportError: attempted relative import with no known parent package # pylint: disable=odoo-addons-relative-import -# from odoo.addons.l10n_it_accompanying_invoice import hooks +from . import hooks -# def migrate(cr, installed_version): -# # Used by OpenUpgrade when module is in `apriori` -# hooks.migrate_old_module(cr) +def migrate(cr, installed_version): + # Used by OpenUpgrade when module is in `apriori` + hooks.migrate_old_module(cr) diff --git a/l10n_it_accompanying_invoice/readme/ROADMAP.md b/l10n_it_accompanying_invoice/readme/ROADMAP.md index 28c5839a256..cc4aa702a26 100644 --- a/l10n_it_accompanying_invoice/readme/ROADMAP.md +++ b/l10n_it_accompanying_invoice/readme/ROADMAP.md @@ -1,9 +1,14 @@ **Italiano** -Il modulo è stato migrato, ma gli script di migrazione non -sono stati provati e quindi sono stati commentati. +Odoo Italia non supporta più i moduli alla versione 12.0 perciò +non ci siamo occupati ufficialmente della migrazione dei dati da +questa versione. + +Tuttavia se non si volessero perdere i dati già presenti nella +versione 12.0 si potrebbe togliere la dipendenza dal modulo +`l10n_it_ddt` nel `__manifest__.py` e lanciare gli script di +migrazione commentati. Si possono provare in un ambiente di test decommentando - il riferimento a `hooks.py` in `__init__.py` - `external_dependencies` e `pre_init_hook` in `__manifest__.py` - le righe di codice in `migrations/16.0.1.0.0/pre-migrate.py` - diff --git a/l10n_it_accompanying_invoice/static/description/index.html b/l10n_it_accompanying_invoice/static/description/index.html index 74526fb1668..6d70b2624e1 100644 --- a/l10n_it_accompanying_invoice/static/description/index.html +++ b/l10n_it_accompanying_invoice/static/description/index.html @@ -398,9 +398,13 @@

Usage

Known issues / Roadmap

Italiano

-

Il modulo è stato migrato, ma gli script di migrazione non sono stati -provati e quindi sono stati commentati. Si possono provare in un -ambiente di test decommentando

+

Odoo Italia non supporta più i moduli alla versione 12.0 perciò non ci +siamo occupati ufficialmente della migrazione dei dati da questa +versione.

+

Tuttavia se non si volessero perdere i dati già presenti nella versione +12.0 si potrebbe togliere la dipendenza dal modulo l10n_it_ddt nel +__manifest__.py e lanciare gli script di migrazione commentati. Si +possono provare in un ambiente di test decommentando