### Install using easy_install Source: https://github.com/oca/openupgradelib/blob/master/docs/installation.html Use this command to install the library directly from the command line. ```bash $ easy_install openupgradelib ``` -------------------------------- ### Set Up Virtual Environment and Install Locally Source: https://github.com/oca/openupgradelib/blob/master/docs/contributing.html Create a virtual environment and install your local copy of openupgradelib in development mode. ```bash mkvirtualenv openupgradelib cd openupgradelib/ python setup.py develop ``` -------------------------------- ### Install documentation dependencies Source: https://github.com/oca/openupgradelib/blob/master/DEVELOP.rst Sets up a virtual environment and installs the necessary Odoo and documentation requirements. ```shell git clone https://github.com/odoo/odoo -b 16.0 --depth=1 ./src/odoo virtualenv env --python=python3.10 ./env/bin/pip install -r ./src/odoo/requirements.txt ./env/bin/pip install -e ./src/odoo/ ./env/bin/pip install -e . ./env/bin/pip install -r ./doc_requirements.txt ``` -------------------------------- ### Install OpenUpgrade Library Source: https://github.com/oca/openupgradelib/blob/master/docsource/API.md Install the OpenUpgrade library using pip. This command is used in your terminal or command prompt. ```bash pip install openupgradelib ``` -------------------------------- ### Set up local development environment Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Commands to create a virtual environment and install the package in development mode. ```bash $ mkvirtualenv openupgradelib $ cd openupgradelib/ $ python setup.py develop ``` -------------------------------- ### Install using pip within virtualenvwrapper Source: https://github.com/oca/openupgradelib/blob/master/docs/installation.html This snippet shows how to create a virtual environment and then install the library using pip. ```bash $ mkvirtualenv openupgradelib $ pip install openupgradelib ``` -------------------------------- ### Install latest fixes from GitHub Source: https://github.com/oca/openupgradelib/blob/master/docs/installation.html Install the most recent version of the library directly from its GitHub repository to ensure you have the latest fixes. ```bash $ pip install git+git://github.com/OCA/openupgradelib.git ``` -------------------------------- ### Migrate Decorator for OpenUpgrade Scripts Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Decorator for the main migrate() function in migration scripts. It handles versioning and environment setup. ```python @openupgrade.migrate() def migrate(cr, version): # some custom code migrate_stock_warehouses(cr) for partner in partners: migrate_partner(cr, partner) ``` -------------------------------- ### Clone and branch repository Source: https://github.com/oca/openupgradelib/blob/master/DEVELOP.rst Initializes the local development environment by cloning the repository and creating a new feature branch. ```shell git clone https://github.com/OCA/openupgradelib -b documentation git checkout -b documentation-NEW-FEATURE ``` -------------------------------- ### Compile documentation locally Source: https://github.com/oca/openupgradelib/blob/master/DEVELOP.rst Uses Sphinx to build the documentation from the docsource directory into the docs directory. ```shell ./env/bin/python -m sphinx -W -d ./docs/.doctrees ./docsource ./docs ``` -------------------------------- ### warn_possible_dataloss Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Warns the user about potential data loss when a field of a model has moved from one module to another, and the new module is not installed. It counts the number of differing values. ```APIDOC ## warn_possible_dataloss ### Description Warns the user about potential data loss when a field of a model has moved from one module to another, and the new module is not installed. It counts the number of differing values. Use ORM, so call from the post script. ### Method openupgradelib.openupgrade.warn_possible_dataloss ### Parameters #### Path Parameters - **cr** (object) - Database cursor. - **pool** (object) - The ORM pool object. - **old_module** (string) - The name of the old module. - **fields** (list) - A list of dictionaries, where each dictionary has the following keys: 'table' (string): name of the table where the field is. 'field' (string): name of the field that is moving. 'new_module' (string): name of the new module. ``` -------------------------------- ### Create a development branch Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Command to create and switch to a new branch for your changes. ```bash $ git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Import OpenUpgrade Library Source: https://github.com/oca/openupgradelib/blob/master/docs/usage.html This is the standard way to import the OpenUpgrade Library to begin using its functionalities in your Python project. ```python import openupgradelib ``` -------------------------------- ### Run Tests and Linting Source: https://github.com/oca/openupgradelib/blob/master/docs/contributing.html Ensure your changes pass linting and all tests, including cross-version compatibility with tox. ```bash flake8 openupgradelib tests python setup.py test tox ``` -------------------------------- ### Run quality checks and tests Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Commands to run linting and test suites to ensure code quality. ```bash $ flake8 openupgradelib tests $ python setup.py test $ tox ``` -------------------------------- ### OpenUpgrade General Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html A collection of utility functions for managing database schema, data, and configurations within the OpenUpgrade framework. ```APIDOC ## OpenUpgrade API Reference This section details the general methods available in the `openupgradelib.openupgrade` module. ### Methods - `add_columns(cr, table, columns)`: Adds new columns to a database table. - `add_fields(cr, model, fields)`: Adds new fields to an OpenERP/Odoo model. - `add_ir_model_fields(cr, model, fields)`: Adds fields to the `ir.model` definition. - `add_xmlid(cr, xmlid, name, value)`: Adds a new XMLID. - `check_values_selection_field(cr, model, field_name, values)`: Checks if the values of a selection field are valid. - `chunked(iterable, n)`: Splits an iterable into chunks of size n. - `clean_transient_models(cr, models)`: Cleans up transient models. - `column_exists(cr, table, column)`: Checks if a column exists in a table. - `convert_field_to_html(cr, model, field_name)`: Converts a field to HTML format. - `convert_to_company_dependent(cr, model, field_name)`: Converts a field to be company-dependent. - `copy_columns(cr, table, columns)`: Copies columns from one table to another. - `copy_fields_multilang(cr, model, field_names)`: Copies fields for multilingual support. - `cow_templates_mark_if_equal_to_upstream(cr, model, field_name)`: Marks templates if they are equal to upstream. - `cow_templates_replicate_upstream(cr, model, field_name)`: Replicates templates from upstream. - `date_to_datetime_tz(date)`: Converts a date to a timezone-aware datetime. - `deactivate_workflow_transitions(cr, model, transitions)`: Deactivates workflow transitions. - `delete_model_workflow(cr, model)`: Deletes the workflow for a model. - `delete_record_translations(cr, model, ids)`: Deletes translations for records. - `delete_records_safely_by_xml_id(cr, model, xmlids)`: Safely deletes records by their XMLID. - `delete_sql_constraint_safely(cr, table, name)`: Safely deletes an SQL constraint. - `disable_invalid_filters(cr, model)`: Disables invalid filters for a model. - `drop_columns(cr, table, columns)`: Drops columns from a database table. - `float_to_integer(value)`: Converts a float to an integer. - `get_field2column_type(field)`: Gets the database column type for a field. - `get_legacy_name(name)`: Gets the legacy name for a given name. - `lift_constraints(cr, table, constraints)`: Lifts constraints from a table. - `load_data(cr, module, filename)`: Loads data from a file for a module. - `logged_query(cr, query, params)`: Executes a query with logging. - `logging(message)`: Logs a message. - `m2o_to_x2m(cr, model, field_name)`: Converts a many2one field to a one2many field. - `map_values(value, mapping)`: Maps values based on a provided mapping. - `merge_models(cr, model1, model2)`: Merges two models. - `message(message)`: Displays a message. - `migrate(cr, model, field, values)`: Migrates a field's values. - `move_field_m2o(cr, model, field_name, new_model)`: Moves a many2one field to a new model. - `reactivate_workflow_transitions(cr, model, transitions)`: Reactivates workflow transitions. - `remove_tables_fks(cr, tables)`: Removes foreign key constraints from tables. - `rename_columns(cr, table, columns)`: Renames columns in a database table. - `rename_field_references(cr, model, old_name, new_name)`: Renames references to a field. - `rename_fields(cr, model, fields)`: Renames fields in a model. - `rename_models(cr, models)`: Renames models. - `rename_property(cr, model, old_name, new_name)`: Renames a property in a model. - `rename_tables(cr, tables)`: Renames database tables. - `rename_xmlids(cr, xmlids)`: Renames XMLIDs. - `safe_unlink(cr, model, ids)`: Safely unlinks records. - `set_defaults(cr, model, fields)`: Sets default values for fields. - `set_xml_ids_noupdate_value(cr, xmlids, value)`: Sets the 'noupdate' value for XMLIDs. - `table_exists(cr, table)`: Checks if a table exists. - `update_field_multilang(cr, model, field_name)`: Updates a field for multilingual support. - `update_module_moved_fields(cr, module, fields)`: Updates module information for moved fields. - `update_module_moved_models(cr, module, models)`: Updates module information for moved models. - `update_module_moved_translations(cr, module, translations)`: Updates module information for moved translations. - `update_module_names(cr, module, names)`: Updates module names. - `update_workflow_workitems(cr, model)`: Updates workflow workitems. ``` -------------------------------- ### Clone the repository Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Use this command to clone your fork of the openupgradelib repository locally. ```bash $ git clone git@github.com:your_name_here/openupgradelib.git ``` -------------------------------- ### Commit and push changes Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Standard git commands to stage, commit, and push your local changes to GitHub. ```bash $ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/oca/openupgradelib/blob/master/docs/contributing.html Stage, commit, and push your changes to your fork on GitHub. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### OpenUpgrade 9.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 9.0, including binary field conversion and account type replacement. ```APIDOC ## OpenUpgrade 9.0 Methods This section lists methods specific to OpenUpgrade version 9.0. ### Methods - `convert_binary_field_to_attachment()` - `replace_account_types()` ``` -------------------------------- ### OpenUpgrade 16.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 16.0 for Bootstrap conversion, analytic distribution, and translation migration. ```APIDOC ## OpenUpgrade 16.0 Methods This section lists methods specific to OpenUpgrade version 16.0. ### Methods - `convert_field_bootstrap_4to5()` - `convert_string_bootstrap_4to5()` - `fill_analytic_distribution()` - `migrate_translations_to_jsonb()` ``` -------------------------------- ### migrate Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Initiates the migration process for the database or specific modules. This function is part of the core openupgrade module. ```APIDOC ## migrate() ### Description Initiates the migration process for the database or specific modules. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes parameters specifying the migration scope and options, but they are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### openupgradelib.openupgrade_160.fill_analytic_distribution Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Converts v15 analytic account and tags with distributions to v16 analytic distributions. Allows configuration for related tables and columns. ```APIDOC ## openupgradelib.openupgrade_160.fill_analytic_distribution ### Description Convert v15 analytic account + analytic tags with distributions (optional) to v16 analytic distributions. ### Parameters * **env** - Required - Odoo environment. * **table** - Required - Name of the main table (eg. sale_order_line…). * **m2m_rel** - Optional - Name of the table for the m2m field that stores v15 analytic tags (eg. account_analytic_tag_sale_order_line_rel). If falsy, no tags are evaluated. * **m2m_column1** - Optional - Name of the column in the m2m table storing the ID of the record of the main table (eg. sale_order_line_id). * **m2m_column2** - Optional - Name of the column in the m2m table storing the ID of the record of the analytic tag. By default, it’s “account_analytic_tag_id”. * **column** - Optional - Name of the column in the main table for storing the new analytic distribution. By default, it’s “analytic_distribution”. * **analytic_account_column** - Optional - Name of the column in the main table for storing the old analytic account. By default, it’s analytic_account_id. ``` -------------------------------- ### Run specific tests Source: https://github.com/oca/openupgradelib/blob/master/CONTRIBUTING.rst Command to execute a specific subset of tests using the unittest module. ```bash $ python -m unittest tests.test_openupgradelib ``` -------------------------------- ### Sign Git Tag for Release Source: https://github.com/oca/openupgradelib/wiki/How-to-bump-version-of-openupgradelib Create a signed Git tag for the new version. The '-s' parameter is essential for signing the tag, which is required for automated PyPI package uploads via Travis CI. ```bash git tag -s -m NEW.VERSION.NUMBER ``` -------------------------------- ### OpenUpgrade 7.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 7.0, primarily for user and partner data migration. ```APIDOC ## OpenUpgrade 7.0 Methods This section lists methods specific to OpenUpgrade version 7.0. ### Methods - `get_partner_id_from_user_id()` - `set_partner_id_from_partner_address_id()` ``` -------------------------------- ### Import OpenUpgrade in Python Scripts Source: https://github.com/oca/openupgradelib/blob/master/docsource/API.md Import the openupgrade module into your Python scripts. This is necessary to use the library's functions. ```python from openupgradelib import openupgrade ``` -------------------------------- ### OpenUpgrade 12.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 12.0 for field and string conversion. ```APIDOC ## OpenUpgrade 12.0 Methods This section lists methods specific to OpenUpgrade version 12.0. ### Methods - `convert_field_bootstrap_3to4()` - `convert_string_bootstrap_3to4()` ``` -------------------------------- ### Push Tags to Remote Repository Source: https://github.com/oca/openupgradelib/wiki/How-to-bump-version-of-openupgradelib Upload all local tags, including the newly signed tag, to the remote repository. The '--tags' parameter ensures that all tags are pushed, which is necessary for the Travis CI build to detect and upload the PyPI package. ```bash git push OCA_REMOTE --tags ``` -------------------------------- ### OpenUpgrade 14.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 14.0 for converting HTML string fields. ```APIDOC ## OpenUpgrade 14.0 Methods This section lists methods specific to OpenUpgrade version 14.0. ### Methods - `convert_field_html_string_13to14()` - `convert_html_string_13to14()` ``` -------------------------------- ### openupgradelib.openupgrade.logging Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html A decorator for OpenUpgrade script functions to log execution details. It logs each time a decorated function is called, with options to include argument details or log only at specified intervals. ```APIDOC ## openupgradelib.openupgrade.logging ### Description This decorator is used for any sub-functions called within an OpenUpgrade script (pre or post migration script). It logs each time the function is called, which is useful for functions that take time or for debugging purposes. ### Parameters * **args_details** (bool) - Optional - If True, arguments details are given in the log. * **step** (int) - Optional - The log will be done only every 'step' times. ``` -------------------------------- ### OpenUpgrade 8.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 8.0, focusing on message and alias updates. ```APIDOC ## OpenUpgrade 8.0 Methods This section lists methods specific to OpenUpgrade version 8.0. ### Methods - `get_last_post_for_model()` - `set_message_last_post()` - `update_aliases()` ``` -------------------------------- ### Run a Subset of Unit Tests Source: https://github.com/oca/openupgradelib/blob/master/docs/contributing.html Execute a specific subset of unit tests using the unittest module. ```python python -m unittest tests.test_openupgradelib ``` -------------------------------- ### openupgradelib.openupgrade.cow_templates_replicate_upstream Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Resets COW'd templates to their upstream equivalents. Meant to be executed in an end-migration script. ```APIDOC ## openupgradelib.openupgrade.cow_templates_replicate_upstream ### Description Reset COW’d templates to their upstream equivalents. This is meant to be executed in an end-migration script. This only makes sense if: 1. Origin is >= v12. 2. Website was installed. Hint: run this in website’s end-migration. ### Parameters - **_cr** - Database cursor. - **_mark_colname** (str) - Optional. Name of the column used for marking. Defaults to None. ``` -------------------------------- ### openupgradelib.openupgrade.migrate Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html A decorator for the `migrate()` function in migration scripts. It manages how the migration function is executed, with options to ignore version checks or use an environment instead of a plain cursor. ```APIDOC ## openupgradelib.openupgrade.migrate ### Description This is the decorator for the `migrate()` function in migration scripts. It controls the execution behavior of the migration function. ### Parameters * **no_version** (bool) - Optional - Set to `True` if the method should be considered even if the module is not installed during a migration. * **use_env** (bool) - Optional - Set to `True` if you want an v8+ environment instead of a plain cursor. This is the default starting from version 10. * **uid** - Optional - The user ID to set when an environment is requested. * **context** - Optional - The context to set when an environment is requested. ``` -------------------------------- ### openupgradelib.openupgrade.cow_templates_mark_if_equal_to_upstream Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Marks COW'd templates that are equal to their upstream equivalents. Meant to be executed in a pre-migration script. ```APIDOC ## openupgradelib.openupgrade.cow_templates_mark_if_equal_to_upstream ### Description Record which COW’d templates are equal to their upstream equivalents. This is meant to be executed in a pre-migration script. This only makes sense if: 1. Origin is >= v12. 2. Website was installed. Hint: run this in website’s pre-migration. 3. You are going to run [`cow_templates_replicate_upstream()`](#openupgradelib.openupgrade.cow_templates_replicate_upstream "openupgradelib.openupgrade.cow_templates_replicate_upstream") in the end-migration. ### Parameters - **_cr** - Database cursor. - **_mark_colname** (str) - Optional. Name of the column to mark equality. Defaults to None. ``` -------------------------------- ### OpenUpgrade 18.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 18.0 for company-dependent data conversion. ```APIDOC ## OpenUpgrade 18.0 Methods This section lists methods specific to OpenUpgrade version 18.0. ### Methods - `convert_company_dependent()` ``` -------------------------------- ### OpenUpgrade Core Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Core utility methods provided by the OpenUpgrade library for managing database schema and data. ```APIDOC ## Core OpenUpgrade Methods This section lists general utility functions available in the OpenUpgrade library. ### Methods - `remove_tables_fks()` - `rename_columns()` - `rename_field_references()` - `rename_fields()` - `rename_models()` - `rename_property()` - `rename_tables()` - `rename_xmlids()` - `safe_unlink()` - `set_defaults()` - `set_xml_ids_noupdate_value()` - `table_exists()` - `update_field_multilang()` - `update_module_moved_fields()` - `update_module_moved_models()` - `update_module_moved_translations()` - `update_module_names()` - `update_workflow_workitems()` - `warn_possible_dataloss()` ``` -------------------------------- ### logging Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Handles logging operations within the OpenUpgradeLib. This function is part of the core openupgrade module. ```APIDOC ## logging() ### Description Handles logging operations within the OpenUpgradeLib. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes logging messages and levels as parameters, but details are not provided in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### Migrate Decorator Configuration Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Decorator for the migrate() function, allowing configuration for version handling and environment usage. Supports specifying 'no_version' and 'use_env' for custom migration logic. ```python openupgrade.migrate(_no_version=False, _use_env=None, _uid=None, _context=None_) ``` -------------------------------- ### openupgradelib.openupgrade.load_data Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Loads data from an XML, CSV, or YAML file during an upgrade script. It's useful for initializing essential data marked with 'noupdate=1' that the standard upgrade mechanism might miss. ```APIDOC ## openupgradelib.openupgrade.load_data ### Description Load an xml, csv or yml data file from your post script. The usual case for this is the occurrence of newly added essential or useful data in the module that is marked with “noupdate=’1’” and without “forcecreate=’1’” so that it will not be loaded by the usual upgrade mechanism. Leaving the ‘mode’ argument to its default ‘init’ will load the data from your migration script. ### Method `load_data(env_or_cr, module_name, filename, idref=None, mode='init', xml_transformation_filename=None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **env_or_cr**: An environment object (Odoo v17+) or a cursor object (until v16). * **module_name**: The name of the module containing the data file. * **filename**: The path to the data file, relative to the module directory or the upgrade path. * **idref** (optional): A hash for mapping cache, used for ID references. * **mode** (optional): Specifies how to load the data. Options include 'init', 'update', 'demo', 'init_no_create'. Defaults to 'init'. * **xml_transformation_filename** (optional): The name of a transformation file (e.g., for XML files) to apply in-place transformations to the loaded data. ``` -------------------------------- ### Logging Decorator for OpenUpgrade Scripts Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Use this decorator to log function calls within OpenUpgrade scripts, useful for debugging or tracking progress. Logs can include argument details or be triggered at specified intervals. ```python import openupgrade @openupgrade.logging() def migrate_stock_warehouses(cr): # some custom code @openupgrade.logging(step=1000) def migrate_partner(cr, partner): # some custom code ``` -------------------------------- ### openupgradelib.openupgrade.copy_columns Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Copies table columns, typically used in pre-migration scripts. It allows for renaming columns and specifying new types. ```APIDOC ## openupgradelib.openupgrade.copy_columns ### Description Copy table columns. Typically called in the pre script. ### Parameters - **_cr** - Database cursor. - **_column_spec** - A hash with table keys, with lists of tuples as values. Tuples consist of (old_name, new_name, type). Use None for new_name to trigger a conversion of old_name using get_legacy_name(). Use None for type to use type of old field. Make sure to quote properly, if your column name coincides with a SQL directive. eg. ‘“column”’ ### Added in version 8.0 ``` -------------------------------- ### Update Version Number in __init__.py Source: https://github.com/oca/openupgradelib/wiki/How-to-bump-version-of-openupgradelib Modify the __version__ variable in the __init__.py file to reflect the new version number. This is a crucial first step in the release process. ```python __version__ = 'NEW.VERSION.NUMBER' ``` -------------------------------- ### openupgradelib.openupgrade.message Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html A log handler for non-critical upgrade notifications. It is designed to be extended for reporting purposes, potentially logging to a table. ```APIDOC ## openupgradelib.openupgrade.message ### Description Log handler for non-critical notifications about the upgrade process. This function can be extended to include logging to a table for reporting purposes. ### Parameters * **cr** - The database cursor. * **module** - The module name that the message concerns. * **table** - The model that this message concerns. Can be `False`, but preferably not if ‘column’ is defined. * **column** - The column that this message concerns. Can be `False`. * **message** - The message string to log. * **args** - Additional arguments. * **kwargs** - Additional keyword arguments. ### Added in version 7.0 ``` -------------------------------- ### openupgradelib.openupgrade_160.convert_string_bootstrap_4to5 Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Converts an HTML string from Bootstrap 4 to Bootstrap 5. It can optionally format the output HTML. ```APIDOC ## openupgradelib.openupgrade_160.convert_string_bootstrap_4to5 ### Description Convert an HTML string from Bootstrap 4 to 5. It can optionally format the output HTML. ### Parameters * **html_string** (str) - Required - Raw HTML fragment to convert. * **pretty_print** (bool) - Optional - Indicate if you wish to return the HTML pretty formatted. Defaults to True. ### Return str: Raw HTML fragment converted. ``` -------------------------------- ### OpenUpgrade 13.0 Methods Source: https://github.com/oca/openupgradelib/blob/master/docs/index.html Methods specific to OpenUpgrade version 13.0 for unlinking invalid tax tags. ```APIDOC ## OpenUpgrade 13.0 Methods This section lists methods specific to OpenUpgrade version 13.0. ### Methods - `unlink_invalid_tax_tags_from_repartition_lines()` ``` -------------------------------- ### openupgradelib.openupgrade.chunked Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Iterates over a potentially large number of records in a memory and performance-friendly manner, yielding chunks or single records. ```APIDOC ## openupgradelib.openupgrade.chunked ### Description Memory and performance friendly method to iterate over a potentially large number of records. Yields either a whole chunk or a single record at the time. Don’t nest calls to this method. ### Parameters * **records**: An iterable of records. * **single**: Boolean, if True yields single records, otherwise yields chunks. Defaults to True. ``` -------------------------------- ### openupgradelib.openupgrade_120.convert_string_bootstrap_3to4 Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Converts an HTML string from Bootstrap 3 to Bootstrap 4 format. Optionally returns the HTML pretty-formatted. ```APIDOC ## openupgradelib.openupgrade_120.convert_string_bootstrap_3to4 ### Description Convert an HTML string from Bootstrap 3 to 4. ### Parameters * **html_string** (str): Raw HTML fragment to convert. * **pretty_print** (bool): Indicate if you wish to return the HTML pretty formatted. ### Returns str: Raw HTML fragment converted. ``` -------------------------------- ### openupgradelib.openupgrade.logged_query Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Executes a SQL query and logs the query and the number of affected rows at the DEBUG level. It can optionally skip logging if no records are affected. ```APIDOC ## openupgradelib.openupgrade.logged_query ### Description Logs query and affected rows at level DEBUG. Useful for debugging database operations during upgrades. ### Method `logged_query(cr, query, args=None, skip_no_result=False)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **cr**: The database cursor. * **query**: The SQL query string to execute. * **args** (optional): A list, tuple, or dictionary of substitution values for the query. * **skip_no_result** (optional): If True, logging details are only shown if there are affected records. Defaults to False. ``` -------------------------------- ### openupgradelib.openupgrade.add_xmlid Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Adds an entry in ir_model_data, typically called in the pre script to handle cases where an entry might have been manually created by the user. ```APIDOC ## openupgradelib.openupgrade.add_xmlid ### Description Adds an entry in ir_model_data. Typically called in the pre script. One usage example is when an entry has been add in the XML and there is a high probability that the user has already created the entry manually. For example, a currency was added in the XML data of the base module in OpenERP 6 but the user had already created this missing currency by hand in it’s 5.0 database. In order to avoid having 2 identical currencies (which is in fact blocked by a sql_constraint), you have to add the entry in ir_model_data before the upgrade. ### Parameters * **cr**: Database cursor. * **module**: Module name. * **xmlid**: XML ID of the entry. * **model**: Model name. * **res_id**: Resource ID. * **noupdate**: Optional boolean, defaults to False. ``` -------------------------------- ### openupgradelib.openupgrade.add_ir_model_fields Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Adds new columns to ir_model_fields, typically in raw SQL at an early stage of the upgrade process. Not suitable for fields with additional SQL constraints. ```APIDOC ## openupgradelib.openupgrade.add_ir_model_fields ### Description Typically, new columns on ir_model_fields need to be added in a very early stage in the upgrade process of the base module, in raw sql as they need to be in place before any model gets initialized. Do not use for fields with additional SQL constraints, such as a reference to another table or the cascade constraint, but craft your own statement taking them into account. ### Parameters * **columnspec**: tuple of (column name, column type) ``` -------------------------------- ### load_data Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Loads data into the system, likely from a file or defined structure. This function is part of the core openupgrade module. ```APIDOC ## load_data() ### Description Loads data into the system, likely from a file or defined structure. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes parameters specifying the data source and target, but they are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### message Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Displays a message to the user or logs it. This function is part of the core openupgrade module. ```APIDOC ## message() ### Description Displays a message to the user or logs it. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes a message string as input, but details are not provided in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### logged_query Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Executes a database query and logs it. This function is part of the core openupgrade module. ```APIDOC ## logged_query() ### Description Executes a database query and logs it. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes a SQL query string as input, but details are not provided in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### openupgradelib.openupgrade.add_fields Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Adds new fields to a model, including SQL column, ir.model.fields entry, and ir.model.data entry. Intended for pre-migration scripts to pre-populate fields. ```APIDOC ## openupgradelib.openupgrade.add_fields ### Description This method adds all the needed stuff for having a new field populated in the DB (SQL column, ir.model.fields entry, ir.model.data entry…). It’s intended for being run in pre-migration scripts for pre-populating fields that are going to be declared later in the module. ### Parameters * **field_spec**: List of tuples with the following expected elements for each tuple: * field name * model name * SQL table name: Put False if the model is already loaded in the registry and thus the SQL table name can be obtained that way. * field type: binary, boolean, char, date, datetime, float, html, integer, many2many, many2one, many2one_reference, monetary, one2many, reference, selection, text, serialized, json, properties, properties_definition. The list can vary depending on Odoo version or custom added field types. * SQL field type: If the field type is custom or if it’s one of the special cases (see get_field2column_type), you need to indicate here the SQL type to use (from the valid PostgreSQL types): [https://www.postgresql.org/docs/9.6/static/datatype.html](https://www.postgresql.org/docs/9.6/static/datatype.html) Note: From >=v16, if field is translatable, SQL field type has to be explicitly stated as ‘jsonb’. * module name: for adding the XML-ID entry. * (optional) initialization value: if included in the tuple, it is set in the column for existing records. ``` -------------------------------- ### openupgradelib.openupgrade_90.convert_binary_field_to_attachment Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Converts binary fields from version 8.0 to attachments in version 9.0. This function should be called in post-migration scripts and handles MIME type guessing, file saving, and removes the source column. ```APIDOC ## convert_binary_field_to_attachment ### Description This method converts the 8.0 binary fields to attachments like Odoo 9.0 makes with the new attachment=True attribute. It has to be called on post-migration script, as there’s a call to get the res_name of the target model, which is not yet loaded on pre-migration. You need to rename the involved column in pre-migration script if you don’t want to lose your data in the process. This method also removes after the conversion the source column for avoiding data duplication. This is done through Odoo ORM, because there’s a lot of logic associated with guessing MIME type, format and length, file saving in store… that is doesn’t worth to recreate it via SQL as there’s not too much performance problem. ### Parameters #### Path Parameters - **_env** (object) - Required - Odoo environment. - **_field_spec** (dict) - Required - A dictionary with the ORM model name as key, and as dictionary values a tuple with: - field name to be converted as attachment as first element. ### Returns - **nothing** ``` -------------------------------- ### openupgradelib.openupgrade.get_legacy_name Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Generates a versioned name for legacy database objects (tables, columns) to prevent naming conflicts during upgrades. ```APIDOC ## openupgradelib.openupgrade.get_legacy_name ### Description Returns a versioned name for legacy tables/columns/etc. Use this function instead of some custom name to avoid collisions with future or past legacy tables/columns/etc. ### Method `get_legacy_name(original_name, version)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **original_name**: The original name of the column or table. * **version**: The current version of the migration, as passed to the `migrate()` function. ``` -------------------------------- ### set_defaults Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Sets default values for specified fields. ```APIDOC ## set_defaults() ### Description Sets default values for specified fields. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### Map Values in Database Columns Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Maps old values from a source column to new values in a target column within the same model or table. Typically used in post-migration scripts. Supports mapping via SQL or ORM. ```python openupgrade.map_values(_cr_, _source_column_, _target_column_, _mapping_, _model_=None, _table_=None, _write_='sql') ``` -------------------------------- ### openupgradelib.openupgrade.reactivate_workflow_transitions Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Reactivates workflow transitions that were previously deactivated using the deactivate_workflow_transitions function. This function is useful for restoring workflow states. ```APIDOC ## openupgradelib.openupgrade.reactivate_workflow_transitions ### Description Reactivates workflow transitions that were previously deactivated using the deactivate_workflow_transitions function. This function is useful for restoring workflow states. ### Parameters * **transition_conditions** (dict) - a dictionary returned by deactivate_workflow_transitions ### Added in version 7.0 ### Deprecated since version 11.0: Workflows were removed from Odoo as of version 11.0 ``` -------------------------------- ### openupgradelib.openupgrade.set_defaults Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Sets default values for fields, useful for newly required fields. This function uses the ORM and should be called from a post-migration script. ```APIDOC ## openupgradelib.openupgrade.set_defaults ### Description Sets default values for fields, useful for newly required fields. This function uses the ORM and should be called from a post-migration script. ### Method openupgradelib.openupgrade.set_defaults(_cr_, _pool_, _default_spec_, _force=False_, _use_orm=False_) ### Parameters #### Path Parameters - **_cr** (object) - Environment/pool variable. The database cursor. - **_pool** (object) - The pool object, 'env' can also be passed. - **_default_spec** (hash) - A dictionary with model names as keys. Values are lists of tuples (field, value). None as a value assigns the default value. - **_force** (boolean) - Overwrites existing values. Defaults to False. - **_use_orm** (boolean) - If True, uses ORM for the write operation; otherwise, uses an SQL clause. Defaults to False. ``` -------------------------------- ### openupgradelib.openupgrade.m2o_to_x2m Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Transforms many2one relations into one2many or many2many. This function is useful for migrating data structures, but caution should be exercised when converting to one2many due to potential data loss. ```APIDOC ## openupgradelib.openupgrade.m2o_to_x2m ### Description Transforms many2one relations into one2many or many2many. For openupgrade versions prior to 14.0, it's recommended to use `rename_columns` in your pre-migrate script before calling `m2o_to_x2m` in your post-migrate script. Be aware of potential data loss when converting to one2many. ### Parameters * **cr** - The database cursor. * **model** - The target model registry object. * **table** - The source table. * **field** - The new field name on the target model. * **source_field** - The (renamed) many2one column on the source table. ### Added in version 8.0 ``` -------------------------------- ### replace_account_types Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Replaces account types, likely for version compatibility. ```APIDOC ## replace_account_types() ### Description Replaces account types, likely for version compatibility. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### openupgradelib.openupgrade.clean_transient_models Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Cleans transient models to prevent data issues. Should be run at the base pre-migration script for a general scope. Only works on Odoo versions greater than v8. ```APIDOC ## openupgradelib.openupgrade.clean_transient_models ### Description Clean transient models to prevent possible issues due to chained data. To be run at the base pre-migration script for having a general scope. Only works on > v8. ### Parameters * **cr**: Database cursor. ``` -------------------------------- ### table_exists Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Checks if a table exists in the database. ```APIDOC ## table_exists() ### Description Checks if a table exists in the database. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### Log Upgrade Messages Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Logs non-critical notifications about the upgrade process. Can be extended for reporting purposes. Specify the module, table, and column concerned by the message. ```python openupgrade.message(_cr_, _module_, _table_, _column_, _message_, *_args_, **_kwargs_) ``` -------------------------------- ### update_workflow_workitems Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Finds all workflow items from a target state and sets them to a desired state. This is useful when a workflow action is removed, and objects in those states need to be transitioned to continue the workflow. Run in pre-migration. ```APIDOC ## update_workflow_workitems ### Description Finds all workflow items from a target state and sets them to a desired state. This is useful when a workflow action is removed, and objects in those states need to be transitioned to continue the workflow. Run in pre-migration. ### Method openupgradelib.openupgrade.update_workflow_workitems ### Parameters #### Path Parameters - **cr** (object) - Database cursor. - **pool** (object) - The ORM pool object. - **ref_spec_actions** (list) - A list of tuples, where each tuple contains a couple of workflow action external IDs. The first ID is replaced with the second. ``` -------------------------------- ### Commit Changes with Git Source: https://github.com/oca/openupgradelib/wiki/How-to-bump-version-of-openupgradelib After updating the version number, commit the changes to your Git repository. This records the version update in the project's history. ```bash git commit ... ``` -------------------------------- ### set_partner_id_from_partner_address_id Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Sets the partner ID based on the partner's address ID. ```APIDOC ## set_partner_id_from_partner_address_id() ### Description Sets the partner ID based on the partner's address ID. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### fill_analytic_distribution Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Fills analytic distribution data. This function is specific to version 16.0 of openupgrade. ```APIDOC ## fill_analytic_distribution() ### Description Fills analytic distribution data. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes parameters related to analytic distribution, but they are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### migrate_translations_to_jsonb Source: https://github.com/oca/openupgradelib/blob/master/docs/genindex.html Migrates translation data to the JSONB format. This function is specific to version 16.0 of openupgrade. ```APIDOC ## migrate_translations_to_jsonb() ### Description Migrates translation data to the JSONB format. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function likely takes parameters related to translation data and target format, but they are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Not applicable (Python function) ``` -------------------------------- ### openupgradelib.openupgrade_160.migrate_translations_to_jsonb Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Migrates translated fields from ir.translation to jsonb columns in Odoo 16. Executes provided queries on the translation table. ```APIDOC ## openupgradelib.openupgrade_160.migrate_translations_to_jsonb ### Description In Odoo 16, translated fields no longer use the model ir.translation. Instead they store all their values into jsonb columns in the model’s table. This method executes provided queries on table _ir_translation if exists or on table ir_translation. ### Parameters * **env** - Required - Odoo environment. * **fields_spec** - Required - list of tuples of (model name, field name). ``` -------------------------------- ### openupgradelib.openupgrade_90.replace_account_types Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Replaces old account types with their specified replacements. It allows for the old account type to not exist, except during unit tests. ```APIDOC ## openupgradelib.openupgrade_90.replace_account_types ### Description Replaces old account types with their specified replacements. The old account type is allowed not to exist anymore, except when running unit tests. ### Parameters * **env**: Odoo environment. * **type_spec**: list of tuples (xmlid of old account.account.type, xmlid of new account.account.type) * **unlink**: attempt to unlink the old account type ``` -------------------------------- ### openupgradelib.openupgrade_160.convert_field_bootstrap_4to5 Source: https://github.com/oca/openupgradelib/blob/master/docs/API.html Converts field values from Bootstrap 4 to Bootstrap 5 for a given model and field. It supports filtering records by a domain and can use ORM or SQL methods. ```APIDOC ## openupgradelib.openupgrade_160.convert_field_bootstrap_4to5 ### Description Converts all the values for the given model and field, being able to restrict to a domain of affected records. ### Parameters * **env** - Required - Odoo environment. * **model_name** - Required - Name of the model that contains the field. * **field_name** - Required - Name of the field that contains the BS3 HTML content. * **domain** - Optional - Optional domain for filtering records in the model. * **method** - Optional - 'orm' (default) for using ORM; 'sql' for avoiding problems with extra triggers in ORM. Defaults to 'orm'. ```