Files
Odoo-Modules/fusion_clock/migrations/19.0.4.1.0/post-migrate.py
gsinghpal c527c7cade fix(fusion_clock): migration must recompute net_hours/overtime, not just break
Recomputing only x_fclk_break_minutes left historical x_fclk_net_hours / x_fclk_overtime_hours stale (add_to_compute+flush of one field does not cascade to dependents). Recompute the full chain in dependency order. Caught verifying the entech deploy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 00:28:12 -04:00

27 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
from odoo import api, SUPERUSER_ID
def migrate(cr, version):
"""Retire the single-threshold break param (superseded by per-rule
break1_after_hours), and force-recompute the now-computed break field so
existing closed attendances reflect the province rule + their penalties."""
cr.execute(
"DELETE FROM ir_config_parameter WHERE key = %s",
('fusion_clock.break_threshold_hours',),
)
env = api.Environment(cr, SUPERUSER_ID, {})
Attendance = env['hr.attendance']
closed = Attendance.search([('check_out', '!=', False)])
if closed:
# Recompute the break AND everything that derives from it, in dependency
# order (break -> net hours -> overtime). Recomputing break alone leaves
# stored x_fclk_net_hours / x_fclk_overtime_hours stale, because
# add_to_compute + flush of one field does not cascade to its dependents.
for fname in ('x_fclk_break_minutes', 'x_fclk_net_hours', 'x_fclk_overtime_hours'):
env.add_to_compute(Attendance._fields[fname], closed)
closed.flush_recordset([fname])