m1m02530125 Claude Sonnet 4.6 commited on
Commit
627b8d1
·
1 Parent(s): 17a285e

fix: output_position always derived from primary_position for single-pos employees

Browse files

Bug: hidden radio buttons in the output_position block (shown only for
両方 employees) were still submitted when saving a hall/kitchen employee,
overwriting output_position with stale values from a previous edit.

Fix 1 (routes/employees.py): when primary_position is set (not both),
always force output_position = primary_position, ignoring form value.

Fix 2 (db/database.py): on startup, repair existing DB rows where
primary_position is set but output_position is NULL or mismatched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. db/database.py +11 -0
  2. routes/employees.py +3 -2
db/database.py CHANGED
@@ -289,6 +289,17 @@ def initialize_db():
289
  if conn.backend == "postgres":
290
  conn._conn.autocommit = False
291
 
 
 
 
 
 
 
 
 
 
 
 
292
  for slot, pos, mn, mx, ml in [
293
  ("breakfast", "hall", 3, 4, 1),
294
  ("breakfast", "kitchen", 3, 3, 1),
 
289
  if conn.backend == "postgres":
290
  conn._conn.autocommit = False
291
 
292
+ # 既存データの output_position 不整合を修正:
293
+ # primary_position が設定されているのに output_position が異なる or NULL の従業員を修正
294
+ try:
295
+ conn.execute(
296
+ "UPDATE employees SET output_position = primary_position"
297
+ " WHERE primary_position IS NOT NULL"
298
+ " AND (output_position IS NULL OR output_position != primary_position)"
299
+ )
300
+ except Exception:
301
+ pass
302
+
303
  for slot, pos, mn, mx, ml in [
304
  ("breakfast", "hall", 3, 4, 1),
305
  ("breakfast", "kitchen", 3, 3, 1),
routes/employees.py CHANGED
@@ -104,8 +104,9 @@ def _form_to_employee(emp_id):
104
  pt_val = f.get("primary_timeslot") or None
105
  # 所属ポジションが「どちらでも」の場合は兼務可を自動でTrue
106
  can_work_both = (pp_val is None)
107
- # 単一ポジションの場合は出力ポジションをそれに合わせる
108
- if pp_val and not op_val:
 
109
  op_val = pp_val
110
 
111
  return Employee(
 
104
  pt_val = f.get("primary_timeslot") or None
105
  # 所属ポジションが「どちらでも」の場合は兼務可を自動でTrue
106
  can_work_both = (pp_val is None)
107
+ # 単一ポジション(ホール/キッチン)の場合は output_position を必ず primary_position に合わせる
108
+ # (非表示の radio ボタンが古い値を送信する問題を防ぐ)
109
+ if pp_val:
110
  op_val = pp_val
111
 
112
  return Employee(