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..8e149628ffb5 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,33 +21,50 @@ 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, sub.delivery_status + order by 1 ) update sale_order as so set delivery_status = so_delivery_status.delivery_status from so_delivery_status - where so_delivery_status.id = so.id; + where so_delivery_status.id = so.id AND so_delivery_status.delivery_status IS NOT NULL; """, ) 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')