mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-10-02 01:33:11 +00:00
fix(slack-bot): show the last pay close on Sunday
The Monday 7am row for the week that just ended is not written yet, so /oncall pay now falls back to the prior close.
This commit is contained in:
parent
99cbf3ce39
commit
9c58304509
2 changed files with 52 additions and 34 deletions
|
|
@ -667,17 +667,21 @@ def _pay_week_bounds(pay_record: dict) -> tuple[datetime, datetime]:
|
|||
|
||||
def _show_pay(respond, schedule):
|
||||
now = datetime.now(EASTERN)
|
||||
# Last completed Sun–Sat week. Fall back to the legacy Monday key for
|
||||
# that same span until the first Sunday-keyed close exists.
|
||||
# The Monday 7am close writes the Sun–Sat week that ended Saturday. On
|
||||
# Sunday, and on Monday before that close, that row is not written yet, so
|
||||
# also try the prior week's Sunday key and the legacy Monday keys.
|
||||
prev_start = week_start(now) - timedelta(days=7)
|
||||
week_key = prev_start.strftime("%Y-%m-%d")
|
||||
|
||||
pay_record = schedule.get_pay_record(week_key)
|
||||
if not (pay_record and pay_record.get("breakdown")):
|
||||
legacy_monday = (prev_start + timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
legacy = schedule.get_pay_record(legacy_monday)
|
||||
if legacy and legacy.get("breakdown"):
|
||||
pay_record = legacy
|
||||
pay_record = None
|
||||
for start in (
|
||||
prev_start,
|
||||
prev_start + timedelta(days=1),
|
||||
prev_start - timedelta(days=7),
|
||||
prev_start - timedelta(days=6),
|
||||
):
|
||||
record = schedule.get_pay_record(start.strftime("%Y-%m-%d"))
|
||||
if record and record.get("breakdown"):
|
||||
pay_record = record
|
||||
break
|
||||
if pay_record and pay_record.get("breakdown"):
|
||||
label_start, label_end = _pay_week_bounds(pay_record)
|
||||
week_label = (
|
||||
|
|
|
|||
|
|
@ -37,38 +37,52 @@ class TestShiftTiming:
|
|||
assert slackbot_app._within_drop_lock("2026-06-02", "night") is True
|
||||
|
||||
|
||||
def _save_pay(schedule, week_key, week_start):
|
||||
schedule.save_pay_record(
|
||||
week_key,
|
||||
{
|
||||
"week_start": week_start,
|
||||
"breakdown": [
|
||||
{
|
||||
"date": week_start,
|
||||
"date_label": "day",
|
||||
"day": "Day",
|
||||
"name": "Alice",
|
||||
"extension": "114",
|
||||
"rate": 50,
|
||||
}
|
||||
],
|
||||
"totals": {
|
||||
"Alice": {
|
||||
"shifts": 1,
|
||||
"total": 50,
|
||||
"extension": "114",
|
||||
"rate": 50,
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class TestShowPay:
|
||||
@freeze_time("2026-06-08 12:00:00") # Monday 08:00 ET
|
||||
def test_falls_back_to_legacy_monday_key(self, slackbot_app, schedule):
|
||||
schedule.save_pay_record(
|
||||
"2026-06-01",
|
||||
{
|
||||
"week_start": "2026-06-01",
|
||||
"breakdown": [
|
||||
{
|
||||
"date": "2026-06-01",
|
||||
"date_label": "Jun 1",
|
||||
"day": "Mon",
|
||||
"name": "Alice",
|
||||
"extension": "114",
|
||||
"rate": 50,
|
||||
}
|
||||
],
|
||||
"totals": {
|
||||
"Alice": {
|
||||
"shifts": 1,
|
||||
"total": 50,
|
||||
"extension": "114",
|
||||
"rate": 50,
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
_save_pay(schedule, "2026-06-01", "2026-06-01")
|
||||
respond = MagicMock()
|
||||
slackbot_app._show_pay(respond, schedule)
|
||||
header = respond.call_args.kwargs["blocks"][0]["text"]["text"]
|
||||
assert "Jun 1 to Jun 7" in header
|
||||
|
||||
@freeze_time("2026-06-14 12:00:00") # Sunday 08:00 ET
|
||||
def test_sunday_shows_prior_close_before_monday_job(self, slackbot_app, schedule):
|
||||
# Monday 2026-06-08 saved the week of Sun 2026-05-31. The next close
|
||||
# (Sun 2026-06-07) is not written until Monday 2026-06-15.
|
||||
_save_pay(schedule, "2026-05-31", "2026-05-31")
|
||||
respond = MagicMock()
|
||||
slackbot_app._show_pay(respond, schedule)
|
||||
header = respond.call_args.kwargs["blocks"][0]["text"]["text"]
|
||||
assert "May 31 to Jun 6" in header
|
||||
|
||||
|
||||
class TestIsToday:
|
||||
@freeze_time(MON)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue