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] purchase_stock: migration #4067

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -670,7 +670,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| |del| purchase_requisition_stock_dropshipping | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| purchase_stock | | |
| purchase_stock | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| rating | Nothing to do | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from openupgradelib import openupgrade


def _compute_purchase_order_receipt_status(env):
openupgrade.add_fields(
env,
[
(
"receipt_status",
"purchase.order",
"purchase_order",
"selection",
"character varying",
"purchase_stock",
False,
),
],
)
openupgrade.logged_query(
env.cr,
"""
WITH po_receipt_status as (
SELECT rel.purchase_order_id as id,
CASE
WHEN
COUNT(sp.state) FILTER(WHERE sp.state = 'cancel') = COUNT(sp.state)
THEN null
WHEN
COUNT(sp.state) FILTER(WHERE sp.state not in ('done', 'cancel')) = 0
THEN 'full'
WHEN
COUNT(sp.state) FILTER(WHERE sp.state = 'done') > 0
THEN 'partial'
ELSE 'pending'
END as receipt_status
FROM stock_picking as sp
JOIN purchase_order_stock_picking_rel as rel
ON rel.stock_picking_id = sp.id
GROUP BY 1
ORDER BY 1
)
UPDATE purchase_order as po
SET receipt_status = po_receipt_status.receipt_status
FROM po_receipt_status
WHERE po_receipt_status.id = po.id;
""",
)


@openupgrade.migrate()
def migrate(env, version):
hoangtiendung070797 marked this conversation as resolved.
Show resolved Hide resolved
_compute_purchase_order_receipt_status(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'---Models in module 'purchase_stock'---
---Fields in module 'purchase_stock'---
purchase_stock / purchase.order / dest_address_id (False) : NEW mode: modify, hasdefault: compute
purchase_stock / purchase.order / incoterm_location (char) : NEW
# NOTHING TO DO

purchase_stock / purchase.order / receipt_status (selection) : NEW selection_keys: ['full', 'partial', 'pending'], isfunction: function, stored
# DONE: pre-migration: create column and fill values

purchase_stock / stock.warehouse.orderpoint / purchase_visibility_days (float): NEW hasdefault: default
# NOTHING TO DO

---XML records in module 'purchase_stock'---
NEW ir.ui.view: purchase_stock.purchase_order_view_tree_inherit
DEL ir.ui.view: purchase_stock.product_category_view_form
# NOTHING TO DO: noupdate="0" records

DEL stock.location.route: purchase_stock.route_warehouse0_buy (noupdate)
NEW stock.route: purchase_stock.route_warehouse0_buy (noupdate)
# NOTHING TO DO: handle in 'stock' module