Skip to content

Commit

Permalink
Merge pull request #3906 from qrtl/14.0-imp-openupgrade
Browse files Browse the repository at this point in the history
[14.0][IMP] base: binary_conversion_for_db_attachments
  • Loading branch information
pedrobaeza authored Sep 13, 2023
2 parents e84308e + 9226642 commit 11000ec
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions openupgrade_scripts/scripts/base/14.0.1.3/post-migrate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Copyright 2020 Odoo Community Association (OCA)
# Copyright 2020 Opener B.V. <stefan@opener.am>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import base64
import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


def fix_module_category_parent_id(env):
# due to renames, we need to correct the parent_id
Expand Down Expand Up @@ -111,10 +116,30 @@ def users_should_export(env):
)


def binary_conversion_for_db_attachments(env):
attachments = env["ir.attachment"].search(
[
("db_datas", "!=", False),
]
)
for attachment in attachments:
try:
# Decoding base64 encoded data to binary
binary_data = base64.b64decode(attachment.db_datas)
attachment.write({"db_datas": binary_data})
except Exception as e:
_logger.error(
"Error while migrating attachment id %s: %s",
attachment.id,
repr(e),
)


@openupgrade.migrate()
def migrate(env, version):
fix_module_category_parent_id(env)
assign_module_category_parent(env)
users_should_export(env)
binary_conversion_for_db_attachments(env)
# Load noupdate changes
openupgrade.load_data(env.cr, "base", "14.0.1.3/noupdate_changes.xml")

0 comments on commit 11000ec

Please sign in to comment.