Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][OU-ADD] sale_stock: migration #4057

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules150-160.rst
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| sale_sms | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| sale_stock | | |
| sale_stock | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| sale_stock_margin | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
54 changes: 54 additions & 0 deletions openupgrade_scripts/scripts/sale_stock/16.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from openupgradelib import openupgrade


def _update_delivery_status(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE sale_order
ADD COLUMN IF NOT EXISTS delivery_status character varying
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order as so
SET delivery_status =
CASE
WHEN
(SELECT COUNT(*) FROM stock_picking WHERE sale_id = so.id) = 0
OR
(
SELECT COUNT(*)
FROM stock_picking
WHERE sale_id = so.id AND state = 'cancel'
) = (
SELECT COUNT(*)
FROM stock_picking
WHERE sale_id = so.id
) THEN NULL
WHEN
(
SELECT COUNT(*)
FROM stock_picking
WHERE sale_id = so.id AND state IN ('done', 'cancel')
) = (
SELECT COUNT(*)
FROM stock_picking
WHERE sale_id = so.id
) THEN 'full'
WHEN
(
SELECT COUNT(*)
FROM stock_picking
WHERE sale_id = so.id AND state = 'done'
) > 0 THEN 'partial'
ELSE 'pending'
END
""",
)


@openupgrade.migrate()
def migrate(env, version):
_update_delivery_status(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---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
# DONE: pre-migration: create column and fill values

sale_stock / sale.order / incoterm_location (char) : NEW
# NOTHING TO DO

sale_stock / sale.order.line / product_type (selection) : module is now 'sale' ('sale_stock')
# NOTHING TO DO: hanlde in 'sale' module

sale_stock / sale.order.line / route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do]
sale_stock / stock.location.route / sale_selectable (boolean) : DEL
sale_stock / stock.route / sale_selectable (boolean) : NEW
# NOTHING TO DO

---XML records in module 'sale_stock'---
DEL ir.ui.menu: sale_stock.menu_aftersale
DEL ir.ui.menu: sale_stock.menu_invoiced
DEL ir.ui.view: sale_stock.product_template_view_form_inherit_sale
DEL ir.ui.view: sale_stock.product_template_view_form_inherit_stock
# NOTHING TO DO: noupdate="0" records