From b4c6cceef8c63a7190d3fed4d6eba58239c16e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Wed, 18 Dec 2024 15:03:55 +0100 Subject: [PATCH] [IMP-OU] sale_stock: add 'started' delivery_status case --- .../sale_stock/16.0.1.0/pre-migration.py | 29 +++++++++++++++---- .../16.0.1.0/upgrade_analysis_work.txt | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py index 86c9234a9eba..a4b8fe4a318c 100644 --- a/openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py +++ b/openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py @@ -21,28 +21,45 @@ def compute_sale_order_delivery_status(env): openupgrade.logged_query( env.cr, """ - with so_delivery_status as ( + with so_delivery_status_sub as ( select sale_id as id, case when - count(state) filter ( + count(*) filter ( where state = 'cancel' - ) = count(state) - then null + ) = count(*) + then NULL when - count(state) filter ( + count(*) filter ( where state not in ('done', 'cancel') ) = 0 then 'full' when - count(state) filter (where state = 'done') > 0 + count(*) filter (where state = 'done') > 0 then 'partial' else 'pending' end as delivery_status from stock_picking group by 1 order by 1 + ), so_delivery_status as ( + select + sol.order_id as id, + case + when + sub.delivery_status = 'partial' and count(*) filter ( + where COALESCE(sol.qty_delivered,0) != 0 + ) > 0 + then 'started' + when sub.delivery_status IS NOT NULL + then sub.delivery_status + else NULL + end as delivery_status + from sale_order_line sol + join so_delivery_status_sub sub ON sub.id = sol.order_id + group by 1 + order by 1 ) update sale_order as so set delivery_status = so_delivery_status.delivery_status diff --git a/openupgrade_scripts/scripts/sale_stock/16.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/sale_stock/16.0.1.0/upgrade_analysis_work.txt index a9230552603d..d93426d9bdd8 100644 --- a/openupgrade_scripts/scripts/sale_stock/16.0.1.0/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/sale_stock/16.0.1.0/upgrade_analysis_work.txt @@ -1,6 +1,6 @@ ---Models in module 'sale_stock'--- ---Fields in module 'sale_stock'--- -sale_stock / sale.order / delivery_status (selection) : NEW selection_keys: ['full', 'partial', 'pending'], isfunction: function, stored +sale_stock / sale.order / delivery_status (selection) : NEW selection_keys: ['full', 'partial', 'pending', 'started'], isfunction: function, stored # DONE: pre-migration: fast computed delivery_status sale_stock / sale.order / incoterm_location (char) : NEW sale_stock / sale.order.line / product_type (selection) : module is now 'sale' ('sale_stock')