Skip to content
Merged
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/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
)
"""
)
Original file line number Diff line number Diff line change
@@ -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),
)
Original file line number Diff line number Diff line change
@@ -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
Loading