Skip to content

Commit

Permalink
[IMP-OU] sale_stock: add 'started' delivery_status case
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Dec 18, 2024
1 parent d1ef8a3 commit b4c6cce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 23 additions & 6 deletions openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit b4c6cce

Please sign in to comment.