Commit ·
8aaa498
1
Parent(s): 9bc450b
fix: 応援要員の時刻がPDF/Excel出力に反映されない問題を修正
Browse files- PDF/Excelエクスポーターの_get_shift_textが4タプルのassignments値を
旧2タプル形式で扱っていたため、応援要員の時刻が固定値になっていた
- 応援要員(is_reinforcement=True)はreinf_start/reinf_endを優先して表示
- Excelの集計ループでpos_vが4タプルになりcount_mapキーが狂い0名表示に
なっていた問題を修正
- schedule_view.pyのバグ修正も含む(refresh/set_period_by_id/ヘッダークリック/
DB呼び出し最適化/コメント修正)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- export/excel_exporter.py +26 -4
- export/pdf_exporter.py +24 -3
- ui/schedule_view.py +18 -15
export/excel_exporter.py
CHANGED
|
@@ -83,6 +83,8 @@ def _get_shift_text(
|
|
| 83 |
備考付きシフト: "6.5 オムレツ 15"
|
| 84 |
有給 : "有給"
|
| 85 |
休み : "-"
|
|
|
|
|
|
|
| 86 |
"""
|
| 87 |
from utils.shift_patterns import PATTERN_MAP
|
| 88 |
|
|
@@ -94,12 +96,31 @@ def _get_shift_text(
|
|
| 94 |
return "有給", "leave"
|
| 95 |
|
| 96 |
# アサイン確認
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
| 100 |
-
if not
|
| 101 |
return "-", "off"
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# 時刻取得(パターンから)
|
| 104 |
if req and req.pattern_id == "double":
|
| 105 |
s, e = "6", "23"
|
|
@@ -254,7 +275,8 @@ def export_excel(
|
|
| 254 |
# ──────────────────────────────────────────────────────────────────
|
| 255 |
count_map = defaultdict(int)
|
| 256 |
skilled_map = defaultdict(int)
|
| 257 |
-
for (emp_id, ds, slot_v),
|
|
|
|
| 258 |
count_map[(ds, slot_v, pos_v)] += 1
|
| 259 |
emp = next((e for e in employees if e.id == emp_id), None)
|
| 260 |
if emp and emp.is_skilled(pos_v):
|
|
|
|
| 83 |
備考付きシフト: "6.5 オムレツ 15"
|
| 84 |
有給 : "有給"
|
| 85 |
休み : "-"
|
| 86 |
+
|
| 87 |
+
assignments の値は (position_value, is_reinforcement, reinf_start, reinf_end) の4タプル。
|
| 88 |
"""
|
| 89 |
from utils.shift_patterns import PATTERN_MAP
|
| 90 |
|
|
|
|
| 96 |
return "有給", "leave"
|
| 97 |
|
| 98 |
# アサイン確認
|
| 99 |
+
b_raw = assignments.get((emp_id, date_str, TimeSlot.BREAKFAST.value))
|
| 100 |
+
d_raw = assignments.get((emp_id, date_str, TimeSlot.DINNER.value))
|
| 101 |
|
| 102 |
+
if not b_raw and not d_raw:
|
| 103 |
return "-", "off"
|
| 104 |
|
| 105 |
+
# 4タプルから位置情報を展開
|
| 106 |
+
b_pos, b_is_reinf, b_rs, b_re = b_raw if b_raw else (None, False, None, None)
|
| 107 |
+
d_pos, d_is_reinf, d_rs, d_re = d_raw if d_raw else (None, False, None, None)
|
| 108 |
+
|
| 109 |
+
# 応援要員は reinf_start/reinf_end を優先して使用
|
| 110 |
+
if b_is_reinf or d_is_reinf:
|
| 111 |
+
if b_raw and not d_raw and b_rs and b_re:
|
| 112 |
+
s, e = _to_decimal(b_rs), _to_decimal(b_re)
|
| 113 |
+
elif d_raw and not b_raw and d_rs and d_re:
|
| 114 |
+
s, e = _to_decimal(d_rs), _to_decimal(d_re)
|
| 115 |
+
elif b_raw and d_raw:
|
| 116 |
+
s = _to_decimal(b_rs) if b_rs else "6"
|
| 117 |
+
e = _to_decimal(d_re) if d_re else "23"
|
| 118 |
+
else:
|
| 119 |
+
s, e = _slot_default(b_pos, d_pos)
|
| 120 |
+
if note:
|
| 121 |
+
return f"{s} {note} {e}", "assigned_note"
|
| 122 |
+
return f"{s} - {e}", "assigned"
|
| 123 |
+
|
| 124 |
# 時刻取得(パターンから)
|
| 125 |
if req and req.pattern_id == "double":
|
| 126 |
s, e = "6", "23"
|
|
|
|
| 275 |
# ──────────────────────────────────────────────────────────────────
|
| 276 |
count_map = defaultdict(int)
|
| 277 |
skilled_map = defaultdict(int)
|
| 278 |
+
for (emp_id, ds, slot_v), asgn_val in assignments.items():
|
| 279 |
+
pos_v = asgn_val[0] if isinstance(asgn_val, tuple) else asgn_val
|
| 280 |
count_map[(ds, slot_v, pos_v)] += 1
|
| 281 |
emp = next((e for e in employees if e.id == emp_id), None)
|
| 282 |
if emp and emp.is_skilled(pos_v):
|
export/pdf_exporter.py
CHANGED
|
@@ -92,6 +92,8 @@ def _get_shift_text(
|
|
| 92 |
"""
|
| 93 |
(セルテキスト, スタイル種別) を返す。
|
| 94 |
スタイル種別: 'assigned' | 'assigned_note' | 'leave' | 'off'
|
|
|
|
|
|
|
| 95 |
"""
|
| 96 |
from utils.shift_patterns import PATTERN_MAP
|
| 97 |
|
|
@@ -101,12 +103,31 @@ def _get_shift_text(
|
|
| 101 |
if "有給" in note:
|
| 102 |
return "有給", "leave"
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
-
if not
|
| 108 |
return "-", "off"
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
if req and req.pattern_id == "double":
|
| 111 |
s, e = "6", "23"
|
| 112 |
elif req and req.pattern_id == "custom" and req.custom_start and req.custom_end:
|
|
|
|
| 92 |
"""
|
| 93 |
(セルテキスト, スタイル種別) を返す。
|
| 94 |
スタイル種別: 'assigned' | 'assigned_note' | 'leave' | 'off'
|
| 95 |
+
|
| 96 |
+
assignments の値は (position_value, is_reinforcement, reinf_start, reinf_end) の4タプル。
|
| 97 |
"""
|
| 98 |
from utils.shift_patterns import PATTERN_MAP
|
| 99 |
|
|
|
|
| 103 |
if "有給" in note:
|
| 104 |
return "有給", "leave"
|
| 105 |
|
| 106 |
+
b_raw = assignments.get((emp_id, date_str, TimeSlot.BREAKFAST.value))
|
| 107 |
+
d_raw = assignments.get((emp_id, date_str, TimeSlot.DINNER.value))
|
| 108 |
|
| 109 |
+
if not b_raw and not d_raw:
|
| 110 |
return "-", "off"
|
| 111 |
|
| 112 |
+
# 4タプルから位置情報を展開
|
| 113 |
+
b_pos, b_is_reinf, b_rs, b_re = b_raw if b_raw else (None, False, None, None)
|
| 114 |
+
d_pos, d_is_reinf, d_rs, d_re = d_raw if d_raw else (None, False, None, None)
|
| 115 |
+
|
| 116 |
+
# 応援要員は reinf_start/reinf_end を優先して使用
|
| 117 |
+
if b_is_reinf or d_is_reinf:
|
| 118 |
+
if b_raw and not d_raw and b_rs and b_re:
|
| 119 |
+
s, e = _to_decimal(b_rs), _to_decimal(b_re)
|
| 120 |
+
elif d_raw and not b_raw and d_rs and d_re:
|
| 121 |
+
s, e = _to_decimal(d_rs), _to_decimal(d_re)
|
| 122 |
+
elif b_raw and d_raw:
|
| 123 |
+
s = _to_decimal(b_rs) if b_rs else "6"
|
| 124 |
+
e = _to_decimal(d_re) if d_re else "23"
|
| 125 |
+
else:
|
| 126 |
+
s, e = _slot_default(b_pos, d_pos)
|
| 127 |
+
if note:
|
| 128 |
+
return f"{s} {note} {e}", "assigned_note"
|
| 129 |
+
return f"{s}-{e}", "assigned"
|
| 130 |
+
|
| 131 |
if req and req.pattern_id == "double":
|
| 132 |
s, e = "6", "23"
|
| 133 |
elif req and req.pattern_id == "custom" and req.custom_start and req.custom_end:
|
ui/schedule_view.py
CHANGED
|
@@ -38,7 +38,7 @@ class ScheduleView(QWidget):
|
|
| 38 |
super().__init__(parent)
|
| 39 |
self._period = None
|
| 40 |
self._employees: list[Employee] = []
|
| 41 |
-
# {(emp_id, date, slot_value): (position_value, is_reinforcement)}
|
| 42 |
self._assignments: dict[tuple[int, str, str], AssignVal] = {}
|
| 43 |
self._requests: dict[tuple[int, str], tuple[bool, bool]] = {}
|
| 44 |
self._raw_requests: dict[tuple[int, str], ShiftRequest] = {}
|
|
@@ -268,6 +268,8 @@ class ScheduleView(QWidget):
|
|
| 268 |
if p and p.id == period_id:
|
| 269 |
self.period_combo.setCurrentIndex(i)
|
| 270 |
return
|
|
|
|
|
|
|
| 271 |
self._render_table()
|
| 272 |
|
| 273 |
def set_period_by_id(self, period_id: int):
|
|
@@ -275,14 +277,13 @@ class ScheduleView(QWidget):
|
|
| 275 |
for i in range(self.period_combo.count()):
|
| 276 |
p = self.period_combo.itemData(i)
|
| 277 |
if p and p.id == period_id:
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
self._update_confirm_button()
|
| 286 |
return
|
| 287 |
|
| 288 |
def _on_period_changed(self, idx):
|
|
@@ -424,6 +425,7 @@ class ScheduleView(QWidget):
|
|
| 424 |
emp_rows.append(("employee", emp))
|
| 425 |
|
| 426 |
# 集計
|
|
|
|
| 427 |
count_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 428 |
leader_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 429 |
for (emp_id, ds, slot_v), (pos_v, *_) in self._assignments.items():
|
|
@@ -475,11 +477,11 @@ class ScheduleView(QWidget):
|
|
| 475 |
sum_table.setColumnWidth(n_cols - 1, 36)
|
| 476 |
|
| 477 |
for pi, pos in enumerate(Position):
|
| 478 |
-
self._fill_summary_row(sum_table, pi, pos, slot, col_date_strs, count_map, leader_map)
|
| 479 |
sum_table.setRowHeight(pi, 28)
|
| 480 |
|
| 481 |
# 警告更新
|
| 482 |
-
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map)
|
| 483 |
|
| 484 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
| 485 |
c = theme.c
|
|
@@ -567,14 +569,13 @@ class ScheduleView(QWidget):
|
|
| 567 |
|
| 568 |
def _fill_summary_row(self, table: QTableWidget, row: int, pos: Position,
|
| 569 |
slot: TimeSlot, col_date_strs: list,
|
| 570 |
-
count_map: dict, leader_map: dict):
|
| 571 |
label_item = QTableWidgetItem(pos.label())
|
| 572 |
label_item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 573 |
label_item.setBackground(QBrush(QColor(theme.c["surface2"])))
|
| 574 |
label_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 575 |
table.setItem(row, 0, label_item)
|
| 576 |
|
| 577 |
-
shift_constraints = repo.get_shift_constraints()
|
| 578 |
constraint = shift_constraints.get((slot, pos), {})
|
| 579 |
min_req = constraint.get("min", 0)
|
| 580 |
min_leader = constraint.get("min_leader", 0)
|
|
@@ -600,8 +601,8 @@ class ScheduleView(QWidget):
|
|
| 600 |
table.setItem(row, len(col_date_strs) - 1, QTableWidgetItem(""))
|
| 601 |
|
| 602 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 603 |
-
dates: list, count_map: dict, leader_map: dict
|
| 604 |
-
|
| 605 |
violations = []
|
| 606 |
for d in dates:
|
| 607 |
ds = d.isoformat()
|
|
@@ -627,6 +628,8 @@ class ScheduleView(QWidget):
|
|
| 627 |
def _on_date_header_clicked(self, col: int, slot: TimeSlot, table: QTableWidget):
|
| 628 |
if col == 0 or col >= table.columnCount() - 1:
|
| 629 |
return
|
|
|
|
|
|
|
| 630 |
dates = self._period.date_range()
|
| 631 |
date_idx = col - 1
|
| 632 |
if date_idx < 0 or date_idx >= len(dates):
|
|
|
|
| 38 |
super().__init__(parent)
|
| 39 |
self._period = None
|
| 40 |
self._employees: list[Employee] = []
|
| 41 |
+
# {(emp_id, date, slot_value): (position_value, is_reinforcement, reinf_start, reinf_end)}
|
| 42 |
self._assignments: dict[tuple[int, str, str], AssignVal] = {}
|
| 43 |
self._requests: dict[tuple[int, str], tuple[bool, bool]] = {}
|
| 44 |
self._raw_requests: dict[tuple[int, str], ShiftRequest] = {}
|
|
|
|
| 268 |
if p and p.id == period_id:
|
| 269 |
self.period_combo.setCurrentIndex(i)
|
| 270 |
return
|
| 271 |
+
if self._period:
|
| 272 |
+
self._load_data()
|
| 273 |
self._render_table()
|
| 274 |
|
| 275 |
def set_period_by_id(self, period_id: int):
|
|
|
|
| 277 |
for i in range(self.period_combo.count()):
|
| 278 |
p = self.period_combo.itemData(i)
|
| 279 |
if p and p.id == period_id:
|
| 280 |
+
self.period_combo.blockSignals(True)
|
| 281 |
+
self.period_combo.setCurrentIndex(i)
|
| 282 |
+
self.period_combo.blockSignals(False)
|
| 283 |
+
self._period = p
|
| 284 |
+
self._load_data()
|
| 285 |
+
self._render_table()
|
| 286 |
+
self._update_confirm_button()
|
|
|
|
| 287 |
return
|
| 288 |
|
| 289 |
def _on_period_changed(self, idx):
|
|
|
|
| 425 |
emp_rows.append(("employee", emp))
|
| 426 |
|
| 427 |
# 集計
|
| 428 |
+
shift_constraints = repo.get_shift_constraints()
|
| 429 |
count_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 430 |
leader_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 431 |
for (emp_id, ds, slot_v), (pos_v, *_) in self._assignments.items():
|
|
|
|
| 477 |
sum_table.setColumnWidth(n_cols - 1, 36)
|
| 478 |
|
| 479 |
for pi, pos in enumerate(Position):
|
| 480 |
+
self._fill_summary_row(sum_table, pi, pos, slot, col_date_strs, count_map, leader_map, shift_constraints)
|
| 481 |
sum_table.setRowHeight(pi, 28)
|
| 482 |
|
| 483 |
# 警告更新
|
| 484 |
+
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map, shift_constraints)
|
| 485 |
|
| 486 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
| 487 |
c = theme.c
|
|
|
|
| 569 |
|
| 570 |
def _fill_summary_row(self, table: QTableWidget, row: int, pos: Position,
|
| 571 |
slot: TimeSlot, col_date_strs: list,
|
| 572 |
+
count_map: dict, leader_map: dict, shift_constraints: dict):
|
| 573 |
label_item = QTableWidgetItem(pos.label())
|
| 574 |
label_item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 575 |
label_item.setBackground(QBrush(QColor(theme.c["surface2"])))
|
| 576 |
label_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 577 |
table.setItem(row, 0, label_item)
|
| 578 |
|
|
|
|
| 579 |
constraint = shift_constraints.get((slot, pos), {})
|
| 580 |
min_req = constraint.get("min", 0)
|
| 581 |
min_leader = constraint.get("min_leader", 0)
|
|
|
|
| 601 |
table.setItem(row, len(col_date_strs) - 1, QTableWidgetItem(""))
|
| 602 |
|
| 603 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 604 |
+
dates: list, count_map: dict, leader_map: dict,
|
| 605 |
+
shift_constraints: dict):
|
| 606 |
violations = []
|
| 607 |
for d in dates:
|
| 608 |
ds = d.isoformat()
|
|
|
|
| 628 |
def _on_date_header_clicked(self, col: int, slot: TimeSlot, table: QTableWidget):
|
| 629 |
if col == 0 or col >= table.columnCount() - 1:
|
| 630 |
return
|
| 631 |
+
if not self._period:
|
| 632 |
+
return
|
| 633 |
dates = self._period.date_range()
|
| 634 |
date_idx = col - 1
|
| 635 |
if date_idx < 0 or date_idx >= len(dates):
|