Skip to content

Commit

Permalink
Merge pull request #4238 from coopiteasy/13.0-merge-stock_pickibg_res…
Browse files Browse the repository at this point in the history
…ponsible

[13.0][OU-ADD] stock_picking_responsible: merged into stock
  • Loading branch information
pedrobaeza authored Nov 29, 2023
2 parents 9fd471c + 8d44dea commit f269077
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
57 changes: 57 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 @@ -185,6 +185,62 @@ 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 create a deactivated user for partners without user and then
map the partner to their user in the stock picking.
"""
if not openupgrade.column_exists(env.cr, "stock_picking", "responsible_id"):
return

env.cr.execute(
f"""
SELECT distinct rp.id,
rp.name,
rp.company_id,
rp.email
FROM stock_picking sp
JOIN res_partner rp ON rp.id = sp.responsible_id
LEFT JOIN res_users ru ON rp.id = ru.partner_id
WHERE ru.id IS NULL
"""
)
partners_wo_user = env.cr.fetchall()

user_vals_list = []
for partner_id, name, company_id, email in partners_wo_user:
login = email if email else name
login = openupgrade.get_legacy_name(login).replace(" ", "_")
user_vals_list.append({
"login": login,
"partner_id": partner_id,
"company_id": company_id,
"active": False,
})

if user_vals_list:
env["res.users"].create(user_vals_list)

# 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.responsible_id
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 +467,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
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 f269077

Please sign in to comment.