odooupgradeodoo-14odoo-16odoo.sh

Is it possible to upgrade Odoo.sh from a staging database?


Does anyone know if it is possible to upgrade an odoo.sh staging database through the upload form from here? https://upgrade.odoo.com/#odoosh

The Odoo.sh upgrade service says that the DB used to upgrade comes from the latest production daily automatic backup, and in every commit in the process it is restored from the same backup

Odoo.sh upgrade service details

The problem is that my team production branch has custom modules that present compatibility issues with the new version (from Odoo 14 to Odoo 16), but we can't delete them from production, cause they are working and are needed for now, so we want to delete the modules from the staging, upgrade it and solve the compatibility problems each module at a time... is that possible? Or is there a better way to solve this problem?

The compatibility problems are related to deprecated models and such.

I have tried uninstalling and deleting the modules from the staging branch, but the production database still have them as "installed" in every upgrade try so the upgrade fails everytime


Solution

  • There are 2 strategies : Using the Upgrade tool provided by Odoo.sh, that reloads the master database in your staging branch after each commit, requiring python scripts. The other strategy is working on the basis of an upgraded Database of your staging branch using upgrade.odoo.com, so that you can easily uninstall custom modules and correct them "manually" one by one.

    During this process (in any upgrade strategy), you can get the remaining issues from the Odoo.sh's (Upgrade)-Log and correct your custom modules accordingly step by step using git-commit/push:

    log-issue-1 -> fix-1 -> git push-> log-issue-2 -> fix-2 -> git push ...etc...

    2 DIFFERENT UPGRADE STRATEGIES:

    1. Using upgrade.odoo.com to upgrade your database (from your staging-branch's DB-backup)...and restore it after. Then, correcting your custom module to fit this new database manually and reporting each of the correction step in a document, so that you can apply them on your master database when the process is technically achieved and tested (user's dayly routines) in staging.

    2. Or using Odoo.sh's Upgrade by writing scripts to fix the issues reported in the log, you can use your own scripts (to delete views or replace code in views...) in migrations/pre-migrate.py, post-migrate.py, end-migrate.py scripts (for difficult cases: documentation: https://readthedocs.org/projects/oopgrade/downloads/pdf/latest/) to adapt your models and views of your custom models, using the OpenUpgrade library: https://pypi.org/project/openupgradelib/

    For difficult upgrade cases, it's worth it to have a look to openupgrade-functions to write your own functions (in xxx-migrate.py files) or even to use them by installing openupgrade in your project: append openupgradelib in your requirements.txt file and then run a bash command:

    pip3 install -r requirements.txt
    

    Available functions of this library:

    add_ir_model_fields()
    bump_major()
    bump_minor()
    bump_patch()
    change_column_type()
    column_exists()
    delete_model_workflow()
    drop_columns()
    get_foreign_keys()
    install_modules()
    load_data()
    oopgrade.oopgrade
    oopgrade.version
    rename_columns()
    rename_tables()
    set_defaults()
    set_stored_function()
    table_exists()
    update_module_names()
    

    Documentation on this library: https://oca.github.io/openupgradelib/installation.html

    To learn how to use openupgradelib's functions, you can find good use-case examples here (open-upgrade): https://github.com/OCA/OpenUpgrade/blob/15.0/openupgrade_scripts/scripts/website_sale/15.0.1.1/post-migration.py

    
    from openupgradelib import openupgrade
    
    
    def update_xpath_for_product_custom_text(env):
        """Look for custom views website_sale.product_custom_text and update the content hook"""
        for view in env["ir.ui.view"].search(
            [
                ("key", "=", "website_sale.product_custom_text"),
                ("website_id", "!=", False),
            ]
        ):
            view.arch_db = view.arch_db.replace(
                "expr=\"//div[@id='product_details']\"",
                "expr=\"//div[@id='o_product_terms_and_share']\"",
            )
    
    
    def set_visibility_product_attribute(env):
        # Check that website_sale_product_attribute_filter_visibility was installed
        if not openupgrade.column_exists(env.cr, "product_attribute", "is_published"):
            return
        openupgrade.logged_query(
            env.cr,
            """
            UPDATE product_attribute
            SET visibility = CASE WHEN is_published is not true THEN 'hidden'
                                  ELSE 'visible'
                                  END
            """,
        )
    
    
    def enable_price_filter_view(env):
        """If you had website_sale_attribute_filter_price module installed in previous
        version, replace it by the new core price filter.
        """
        for website in env["website"].search([]):
            view = env["ir.ui.view"].search(
                [
                    ("key", "=", "website_sale_attribute_filter_price.pricefilter"),
                    ("website_id", "=", website.id),
                ]
            )
            if view:
                # It's important to set the context to create the new view related to the
                # current website. See write method of ir.ui.view in website module
                website.with_context(website_id=website.id).viewref(
                    "website_sale.filter_products_price"
                ).active = True
                view.unlink()
    
    
    @openupgrade.migrate()
    def migrate(env, version):
        # Load noupdate changes
        openupgrade.load_data(
            env.cr,
            "website_sale",
            "15.0.1.1/noupdate_changes.xml",
        )
        openupgrade.delete_record_translations(
            env.cr,
            "website_sale",
            [
                "mail_template_sale_cart_recovery",
            ],
        )
        set_visibility_product_attribute(env)
        enable_price_filter_view(env)
        update_xpath_for_product_custom_text(env)