Skip to content

Commit

Permalink
Merge PR #2364 into 11.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jul 16, 2020
2 parents f7845f4 + a44e207 commit b42c7ae
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions addons/stock/migrations/11.0.1.1/end-migration.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging

from odoo.exceptions import ValidationError
from openupgradelib import openupgrade, openupgrade_merge_records

QUANT_MERGE_OPS = {
Expand All @@ -12,6 +13,7 @@


def merge_quants(env):
logger = logging.getLogger('openupgrade.stock.end_migration')
group_list = [
'product_id', 'package_id', 'lot_id', 'location_id', 'owner_id',
]
Expand All @@ -21,9 +23,23 @@ def merge_quants(env):
quants = StockQuant.search(group['__domain'])
if len(quants) == 1:
continue
openupgrade_merge_records.merge_records(
env, 'stock.quant', quants[1:].ids, quants[0].id, QUANT_MERGE_OPS,
)
try:
with env.cr.savepoint():
openupgrade_merge_records.merge_records(
env, 'stock.quant', quants[1:].ids, quants[0].id, QUANT_MERGE_OPS,
)
except ValidationError as error:
logger.error(
'Cannot merge quants %s for '
'product %s, package %s, lot %s, location %s, owner %s: %s',
quants.ids,
quants[0].product_id.default_code or quants[0].product_id.name,
quants[0].package_id.name or '-',
quants[0].lot_id.name or '-',
quants[0].location_id.complete_name,
quants[0].owner_id.name or '-',
error,
)


@openupgrade.migrate(use_env=True)
Expand Down

0 comments on commit b42c7ae

Please sign in to comment.