[18.0][FIX] hr_shift: current_shift_id must be the shift active right now - #44
Open
cvinh wants to merge 1 commit into
Open
[18.0][FIX] hr_shift: current_shift_id must be the shift active right now#44cvinh wants to merge 1 commit into
cvinh wants to merge 1 commit into
Conversation
hr.employee.current_shift_id is a Many2one that used to be computed via a helper _shift_of_date(min_time, max_time), always called with the UTC 00:00 and UTC 23:59 of "today", searching lines whose start_time and end_time fell entirely inside that window. Two issues combine to break the field: - The name says "current" but the query returns any shift scheduled today, so the field is misleading: it is filled hours before the shift actually starts, and stays filled well after it ends. - The window is built from fields.Date.today(), which is UTC-based. For a user living far from UTC (e.g. GMT-10 in French Polynesia), a single local day is split across two UTC days and a shift on Monday afternoon local time is stored on the next UTC day. An employee with two shifts the same local day (morning + afternoon) can end up with both matching the same UTC-day window on the boundary, and the Many2one assignment then raises ValueError: Wrong value for hr.employee.current_shift_id: .... Rewrite _compute_current_shift_id to match the semantic implied by the field name: the shift whose [start_time, end_time] contains the current instant. The domain becomes an overlap check on fields.Datetime.now(), which is timezone-agnostic because both sides are stored in UTC. Only the shift active right now matches, so the Many2one assignment is naturally singular for any well-formed data set (no overlapping shifts), regardless of the user's timezone or the number of shifts scheduled the same day. _shift_of_date is dropped since it has no external callers in shift-planning or Odoo core and its name no longer fits the new semantic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hr.employee.current_shift_id is a Many2one that used to be computed via a helper _shift_of_date(min_time, max_time), always called with the UTC 00:00 and UTC 23:59 of "today", searching lines whose start_time and end_time fell entirely inside that window. Two issues combine to break the field:
Rewrite _compute_current_shift_id to match the semantic implied by the field name: the shift whose [start_time, end_time] contains the current instant. The domain becomes an overlap check on fields.Datetime.now(), which is timezone-agnostic because both sides are stored in UTC. Only the shift active right now matches, so the Many2one assignment is naturally singular for any well-formed data set (no overlapping shifts), regardless of the user's timezone or the number of shifts scheduled the same day.
_shift_of_date is dropped since it has no external callers in shift-planning or Odoo core and its name no longer fits the new semantic.