Skip to content

[18.0] [FIX] l10n_it_riba_oca: fix scripts for OpenUpgrade migration#5131

Open
odooNextev wants to merge 1 commit intoOCA:18.0from
odooNextev:18.0-fix-l10n_it_riba_oca-oomig
Open

[18.0] [FIX] l10n_it_riba_oca: fix scripts for OpenUpgrade migration#5131
odooNextev wants to merge 1 commit intoOCA:18.0from
odooNextev:18.0-fix-l10n_it_riba_oca-oomig

Conversation

@odooNextev
Copy link
Copy Markdown
Contributor

Gli script di pre-migrazione di OpenUpgrade ricevono solo il cursore del database (cr) e una stringa di versione come argomenti, mentre il normale flusso di aggiornamento di Odoo (tramite frontend o odoo -u) fornisce un oggetto env completo.

Questo commit introduce una funzione wrapper migrate_old_module(cr) in hooks.py che costruisce un api.Environment a partire dal solo cursore, permettendo di riutilizzare correttamente la logica esistente di pre_absorb_old_module(env) anche durante una migrazione con OpenUpgrade.

Inoltre, migrate(cr, installed_version) nello script di pre-migrazione è stata corretto in migrate(cr, version), che è esattamente quella attesa da OpenUpgrade.

Senza queste modifiche, la migrazione funzionava solo aggiornando il modulo dal frontend di Odoo (dove env è già disponibile), ma falliva silenziosamente con OpenUpgrade, che chiama la funzione passando solo il cursore senza costruire un env automaticamente.

Copy link
Copy Markdown
Contributor

@monen17 monen17 left a comment

Choose a reason for hiding this comment

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

Grazie della PR!
Non ho provato la migrazione ma ho fatto solo revisione del codice, vedi i commenti qui sotto.



def migrate(cr, installed_version):
def migrate(cr, version):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Se questo non serve meglio toglierlo, così in questo commit ci sono solo le modifiche necessarie

Called from pre-migration script with cursor-only access.
Creates an env from cr and delegates to pre_absorb_old_module.
"""
env = api.Environment(cr, 1, {}) # uid=1 (admin), empty context
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

L'utente con ID 1 non è admin ma Odoobot

Comment on lines 11 to 16
from odoo.addons.l10n_it_riba_oca import hooks


def migrate(cr, installed_version):
def migrate(cr, version):
# Used by OpenUpgrade when module is in `apriori`
hooks.migrate_old_module(cr)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Possiamo invece usare openupgradelib e chiamare direttamente pre_absorb_old_module?
Così è analogo a come viene fatto negli altri moduli del repository, vedi ad esempio:

from openupgradelib import openupgrade
from odoo.addons.l10n_it_account_vat_period_end_settlement import hooks
@openupgrade.migrate()
def migrate(env, version):
# Used by OpenUpgrade when module is in `apriori`
hooks.pre_absorb_old_module(env)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Se l'unica cosa da fare nella migrazione è rinominare il modulo, probabilmente non serve nemmeno questo file perché la rinomina viene già eseguita in https://github.com/OCA/OpenUpgrade/blob/82572397744b96c1a1ad706d8a911abc90ee4dea/openupgrade_scripts/scripts/base/18.0.1.3/pre-migration.py#L74, puoi verificare?
Se non serve meglio rimuoverlo e lasciamo solo l'hook pre_absorb_old_module.

@@ -15,3 +17,13 @@ def pre_absorb_old_module(env):
],
merge_modules=True,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non riguarda le modifiche di questa PR, ma ho notato che qui si usa merge_modules=True, mentre in https://github.com/OCA/OpenUpgrade/blob/82572397744b96c1a1ad706d8a911abc90ee4dea/openupgrade_scripts/apriori.py#L25 il modulo è elencato tra i moduli da rinominare, puoi verificare se serve davvero usare merge_modules oppure no?
Se serve, allora il modulo va spostato nella lista dei moduli da mergiare; altrimenti va tolto da qui.

Così la migrazione tramite OpenUpgrade e l'hook di init fanno le stesse operazioni.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants