From 7acdc315c121c341925a49676f71e2bf0d684484 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 19 Feb 2025 14:21:06 +0100 Subject: [PATCH] [OU-FIX] sale_stock: Missing migration script Honor https://github.com/OCA/OpenUpgrade/blob/44ca5988eb34de588b28c00342a6d54c5ce4e71d/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt#L138 TT49892 --- docsource/modules160-170.rst | 2 +- .../sale_stock/17.0.1.0/post-migration.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/sale_stock/17.0.1.0/post-migration.py diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index fe5427244e5..463442e162c 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -902,7 +902,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | sale_sms | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| sale_stock | Nothing to do | | +| sale_stock | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | sale_stock_margin | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/sale_stock/17.0.1.0/post-migration.py b/openupgrade_scripts/scripts/sale_stock/17.0.1.0/post-migration.py new file mode 100644 index 00000000000..c6a676138f3 --- /dev/null +++ b/openupgrade_scripts/scripts/sale_stock/17.0.1.0/post-migration.py @@ -0,0 +1,33 @@ +# Copyright 2025 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + # Fill delivery_date and incoterm_location according + # https://github.com/odoo/odoo/blob/00818b7bfaf22635b0c40b3b9c7e37e0c9789da1/ + # addons/sale_stock/models/account_move.py#L116-L134 + openupgrade.logged_query( + env.cr, + """ + WITH sub AS ( + SELECT + MAX(so.effective_date) as effective_date, + MAX(COALESCE(so.incoterm_location, '')) as incoterm_location, + am.id as move_id + FROM sale_order so + JOIN sale_order_line sol ON sol.order_id = so.id + JOIN sale_order_line_invoice_rel rel ON rel.order_line_id = sol.id + JOIN account_move_line aml ON rel.invoice_line_id = aml.id + JOIN account_move am ON aml.move_id = am.id + GROUP BY am.id + ) + UPDATE account_move am + SET delivery_date = sub.effective_date, + incoterm_location = sub.incoterm_location + FROM sub + WHERE sub.move_id = am.id + """, + )