diff --git a/docsource/modules180-190.rst b/docsource/modules180-190.rst index f2846d67a336..ecd17c38a412 100644 --- a/docsource/modules180-190.rst +++ b/docsource/modules180-190.rst @@ -914,7 +914,7 @@ Module coverage 18.0 -> 19.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | product_email_template | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| product_expiry | | | +| product_expiry |Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | |del| product_images | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/product_expiry/19.0.1.0/post-migration.py b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/post-migration.py new file mode 100644 index 000000000000..e0a06dcb5591 --- /dev/null +++ b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/post-migration.py @@ -0,0 +1,46 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + backfill_stock_move_line_removal_date(env) + + +def backfill_stock_move_line_removal_date(env): + """Backfill removal_date on existing move lines - core only creates the + column empty to avoid a MemoryError on large tables. Mirrors + _compute_removal_date (lot priority, use_create_lots / use_expiration_date + gating, picking_id -> move_id fallback for picking type).""" + env.cr.execute( + """ + UPDATE stock_move_line sml + SET removal_date = CASE + WHEN lot.removal_date IS NOT NULL + THEN lot.removal_date + ELSE sml2.expiration_date + - (COALESCE(pt.removal_time, 0) || ' days')::interval + END + FROM stock_move_line sml2 + JOIN product_product pp ON sml2.product_id = pp.id + JOIN product_template pt ON pp.product_tmpl_id = pt.id + LEFT JOIN stock_lot lot ON sml2.lot_id = lot.id + LEFT JOIN stock_picking sp ON sml2.picking_id = sp.id + LEFT JOIN stock_move sm ON sml2.move_id = sm.id + LEFT JOIN stock_picking_type spt ON spt.id = COALESCE( + sp.picking_type_id, sm.picking_type_id + ) + WHERE sml.id = sml2.id + AND sml.removal_date IS NULL + AND ( + lot.removal_date IS NOT NULL + OR ( + COALESCE(spt.use_create_lots, FALSE) IS TRUE + AND COALESCE(pt.use_expiration_date, FALSE) IS TRUE + AND sml2.expiration_date IS NOT NULL + ) + ) + """ + ) diff --git a/openupgrade_scripts/scripts/product_expiry/19.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/pre-migration.py new file mode 100644 index 000000000000..c61869b2219b --- /dev/null +++ b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/pre-migration.py @@ -0,0 +1,26 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + reassign_alert_date_activities(env) + + +def reassign_alert_date_activities(env): + """Reassign alert-date activities to the standard To-do type + before the old activity type record is removed by the data sync.""" + old_type = env.ref("product_expiry.mail_activity_type_alert_date_reached", False) + new_type = env.ref("mail.mail_activity_data_todo", False) + if old_type and new_type: + env.cr.execute( + """ + UPDATE mail_activity + SET activity_type_id = %s, + summary = COALESCE(summary, 'Alert Date Reached') + WHERE activity_type_id = %s + """, + (new_type.id, old_type.id), + ) diff --git a/openupgrade_scripts/scripts/product_expiry/19.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..878327984d98 --- /dev/null +++ b/openupgrade_scripts/scripts/product_expiry/19.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,11 @@ +---Models in module 'product_expiry'--- + +---Fields in module 'product_expiry'--- +product_expiry / stock.move.line / removal_date (datetime) : NEW hasdefault: compute + +# DONE: backfilled in post-migration, mirrors _compute_removal_date + +---XML records in module 'product_expiry'--- +DEL mail.activity.type: product_expiry.mail_activity_type_alert_date_reached + +# DONE: reassigned existing activities to mail.mail_activity_data_todo in pre-migration