upgrade-util icon indicating copy to clipboard operation
upgrade-util copied to clipboard

[FIX] Preserve all translated fields on v16 migration

Open yajo opened this issue 1 year ago • 15 comments

Currently, the upgrade process preserves translations only for Odoo CE+EE fields. However, databases usually have more modules (or even custom fields) and those translations get lost when upgrading to Odoo 16.

With this script, all translated fields will inherit their translations in all languages. Since it is executed in the pre phase of base, it should be able to still find the ir_translation table.

@moduon MT-7120

yajo avatar Aug 28 '24 08:08 yajo

Pull request status dashboard

robodoo avatar Aug 28 '24 08:08 robodoo

However, databases usually have more modules (or even custom fields) and those translations get lost when upgrading to Odoo 16.

The table is renamed to _ir_translation and kept always. What translations are you trying to keep? Only entries with type='code' are cleaned before renaming the table.

aj-fuentes avatar Aug 28 '24 11:08 aj-fuentes

Merge to upgrade

those Errors are killing me

NomadsComputerllc avatar Aug 29 '24 05:08 NomadsComputerllc

After a migration, you can see an upgrade report like this:

image

It specifies that migrations may be wrong. However, in reality, all those are wrong because only the base language (usually en_US) is migrated.

With this script, all langs are always migrated in all fields (declared by Odoo or not). Still, something may be wrong; but at least, most problems get auto-fixed now.

yajo avatar Aug 30 '24 08:08 yajo

Yes, you need to use _get_translation_upgrade_queries on your side (via an upgrade script) when updating the custom modules (with custom code available) on your upgraded DB.

That's the same mechanism we use in the standard upgrade script. We cannot do this for custom fields because we don't know if a field has a special translate= method. This option comes via code and we do not have the custom code. There are two standard options xml_translate and html_translate, but there could be even a custom translate.

What you could do is something like (beware: not tested!)

    for model in your_custom_models:      
        if model._auto and not model._abstract:
            for field in model._fields.values():
                if field.store and field.translate:
                    migrate, cleanup = _get_translation_upgrade_queries(cr, field)
                    # run the queries in migrate, and cleanup

Side node: when _get_translation_upgrade_queries was introduced this repo didn't exist thus the way to share the queries with the community was via the main odoo repo.

aj-fuentes avatar Aug 30 '24 09:08 aj-fuentes

IIUC there shouldn't be an incompatibility between this PR and your suggestion, right? 🤔

This PR only improves the default value for those fields. If there's more magic involved, then you can still do that and get to the appropriate fix.

yajo avatar Aug 30 '24 10:08 yajo

@yajo

IIUC there shouldn't be an incompatibility between this PR and your suggestion, right? 🤔

This change is risky because it will interfere with all the battle tested machinery of the translations in 15->16 upgrade. Including PO loading, noupdate flags, etc. Also for specific scripts of some clients.

This PR only improves the default value for those fields. If there's more magic involved, then you can still do that and get to the appropriate fix.

If you want to contribute an improvement I think it would be better to add something that could be used directly in end- scripts for custom code (in specific.py). That way the community could have a simpler alternative than figuring out how to use _get_translation_upgrade_queries. We could even add a reference to it in the upgrade report (like in the example picture you sent before).

@KangOl could you give some insight here please?

aj-fuentes avatar Aug 30 '24 11:08 aj-fuentes

I changed it according to your suggestion. Could you please review again?

yajo avatar Sep 18 '24 07:09 yajo

upgradeci retry with always only base

KangOl avatar Sep 18 '24 15:09 KangOl

All attended.

yajo avatar Oct 30 '24 10:10 yajo

Could you please rebase your fork's branch in the latest master of this repo? The CIs are all red due to this.

aj-fuentes avatar Oct 30 '24 12:10 aj-fuentes

upgradeci retry

aj-fuentes avatar Oct 31 '24 13:10 aj-fuentes

Rebased

yajo avatar Nov 06 '24 11:11 yajo

Hello! Any news here?

yajo avatar Nov 29 '24 13:11 yajo

I didn't notice this was broken. CI is fixed now. Could you review again please?

yajo avatar May 09 '25 08:05 yajo

How's this going?

yajo avatar May 23 '25 09:05 yajo

Hello there! Is there intention to merge this? Thanks!

yajo avatar Sep 04 '25 12:09 yajo