Skip to content

Commit

Permalink
[13.0][OU-ADD] stock_picking_responsible: merged into stock
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkeunen committed Nov 23, 2023
1 parent 1c5c8fd commit 6b00e4a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
50 changes: 50 additions & 0 deletions addons/stock/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
import re
import logging as _logging_module
_logger = _logging_module.getLogger(__name__)


def _get_main_company(cr):
Expand Down Expand Up @@ -185,6 +187,53 @@ def map_stock_location_usage(env):
)


def map_stock_picking_responsible_responsible_id_to_user_id(env):
"""
responsible_id (partner_id) field in stock_picking_responsible is replaced by user_id (res.users)
We map the partner to their user and log the partners missing a user
"""
legacy_column_name = openupgrade.get_legacy_name("responsible_id")
if not openupgrade.column_exists(env.cr, "stock_picking", legacy_column_name):
return

env.cr.execute(
f"""
SELECT sp.id AS picking_id,
sp.name as picking_name,
rp.id AS partner_id,
rp.name as partner_name
FROM stock_picking sp
JOIN res_partner rp ON rp.id = sp.{legacy_column_name}
LEFT JOIN res_users ru ON rp.id = ru.partner_id
WHERE ru.id IS NULL
"""
)
partner_wo_user = env.cr.fetchall()
for picking_id, picking_name, partner_id, partner_name in partner_wo_user:
_logger.warning(
f"Picking (%{picking_id}) {picking_name}:"
f" cannot match user to ({partner_id}) {partner_name}"
)

# map responsible_id to user_id
openupgrade.logged_query(
env.cr,
f"""
WITH partner_user AS (
SELECT sp.id AS picking_id,
rp.id AS partner_id,
ru.id AS user_id
FROM stock_picking sp
JOIN res_partner rp ON rp.id = sp.{legacy_column_name}
LEFT join res_users ru ON rp.id = ru.partner_id)
UPDATE stock_picking
SET user_id = partner_user.user_id
FROM partner_user
WHERE stock_picking.id = partner_user.picking_id;
"""
)


def fill_stock_picking_type_sequence_code(env):
"""Deduce sequence code from current sequence pattern """
picking_types = env["stock.picking.type"].with_context(active_text=False).search([])
Expand Down Expand Up @@ -411,6 +460,7 @@ def migrate(env, version):
fill_propagate_date_minimum_delta(env)
fill_stock_inventory_start_empty(env)
map_stock_location_usage(env)
map_stock_picking_responsible_responsible_id_to_user_id(env)
fill_stock_picking_type_sequence_code(env)
handle_stock_scrap_sequence(env, main_company)
map_stock_locations(env, main_company)
Expand Down
13 changes: 13 additions & 0 deletions addons/stock/migrations/13.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ def prefill_stock_picking_type_sequence_code(env):
)


def merge_stock_picking_responsible_module(env):
"""
The stock_picking_responsible module is now merged in stock.
We copy the legacy column to convert data in post-migration script.
"""
if openupgrade.column_exists(env.cr, "stock_picking", "responsible_id"):
openupgrade.copy_columns(
env.cr,
{'stock_picking': [('responsible_id', None, None)]}
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.copy_columns(env.cr, _column_copies)
Expand All @@ -107,3 +119,4 @@ def migrate(env, version):
assure_stock_rule_company_is_correct(env)
fill_inventory_line_categ(env)
prefill_stock_picking_type_sequence_code(env)
merge_stock_picking_responsible_module(env)
2 changes: 2 additions & 0 deletions odoo/addons/openupgrade_records/lib/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
'sale_product_classification': 'product_abc_classification_sale',
# OCA/stock-logistics-warehouse
'stock_putaway_product_form': 'stock_putaway_product_template',
# OCA/stock-logistics-workflow
'stock_picking_responsible': 'stock',
# OCA/l10n-netherlands -> OCA/account-financial-reporting
'l10n_nl_mis_reports': 'mis_template_financial_report',
}
Expand Down

0 comments on commit 6b00e4a

Please sign in to comment.