Commit ·
2626da0
1
Parent(s): 68bcd4b
feat: add output_position for PDF/Excel section assignment
Browse filesEmployees who work both positions (primary_position=None) previously had
ambiguous placement in PDF/Excel output. New output_position field:
- DB: employees.output_position TEXT column (migration)
- Model: Employee.output_position Optional[PrimaryPosition]
- Form: shown only when position=両方; ホール欄 / キッチン欄 toggle
with warning badge. Single-position employees auto-inherit their position.
- Route: output_position defaults to primary_position when single-position
- PDF exporter: uses output_position ?? primary_position for section split
(kitchen_emps / hall_emps)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/database.py +1 -0
- db/repositories.py +9 -4
- export/pdf_exporter.py +6 -4
- models/employee.py +3 -2
- routes/employees.py +5 -0
- templates/employees/form.html +39 -0
db/database.py
CHANGED
|
@@ -254,6 +254,7 @@ _MIGRATIONS = [
|
|
| 254 |
("schedule_periods", "gen_message", "TEXT NOT NULL DEFAULT ''"),
|
| 255 |
("employees", "display_order", "INTEGER NOT NULL DEFAULT 0"),
|
| 256 |
("schedule_periods", "needs_regen", "INTEGER NOT NULL DEFAULT 0"),
|
|
|
|
| 257 |
]
|
| 258 |
|
| 259 |
_INDEXES = [
|
|
|
|
| 254 |
("schedule_periods", "gen_message", "TEXT NOT NULL DEFAULT ''"),
|
| 255 |
("employees", "display_order", "INTEGER NOT NULL DEFAULT 0"),
|
| 256 |
("schedule_periods", "needs_regen", "INTEGER NOT NULL DEFAULT 0"),
|
| 257 |
+
("employees", "output_position", "TEXT"),
|
| 258 |
]
|
| 259 |
|
| 260 |
_INDEXES = [
|
db/repositories.py
CHANGED
|
@@ -60,6 +60,7 @@ def get_employee(employee_id: int) -> Optional[Employee]:
|
|
| 60 |
def save_employee(emp: Employee) -> Employee:
|
| 61 |
conn = get_connection()
|
| 62 |
pp = emp.primary_position.value if emp.primary_position else None
|
|
|
|
| 63 |
pt = emp.primary_timeslot.value if emp.primary_timeslot else None
|
| 64 |
both = int(emp.can_work_both_positions)
|
| 65 |
opn = int(emp.can_open)
|
|
@@ -68,13 +69,13 @@ def save_employee(emp: Employee) -> Employee:
|
|
| 68 |
avail_d = int(emp.always_available_dinner)
|
| 69 |
if emp.id is None:
|
| 70 |
emp.id = conn.execute_insert(
|
| 71 |
-
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 72 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, cln, avail_b, avail_d, 1)
|
| 73 |
)
|
| 74 |
else:
|
| 75 |
conn.execute(
|
| 76 |
-
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, is_active=? WHERE id=?",
|
| 77 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, cln, avail_b, avail_d, int(emp.is_active), emp.id)
|
| 78 |
)
|
| 79 |
_save_fixed_patterns(conn, emp)
|
| 80 |
_save_fixed_unavailable_dates(conn, emp)
|
|
@@ -114,6 +115,7 @@ def _row_to_employee_preloaded(row, pat_map: dict, unavail_map: dict) -> Employe
|
|
| 114 |
eid = row["id"]
|
| 115 |
keys = row.keys()
|
| 116 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
|
|
|
| 117 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 118 |
return Employee(
|
| 119 |
id=eid, name=row["name"],
|
|
@@ -121,6 +123,7 @@ def _row_to_employee_preloaded(row, pat_map: dict, unavail_map: dict) -> Employe
|
|
| 121 |
hall_skill=SkillLevel(row["hall_skill"]),
|
| 122 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 123 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
|
|
|
| 124 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 125 |
can_work_both_positions=bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False,
|
| 126 |
can_open=bool(row["can_open"]) if "can_open" in keys else False,
|
|
@@ -147,6 +150,7 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 147 |
).fetchall()
|
| 148 |
keys = row.keys()
|
| 149 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
|
|
|
| 150 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 151 |
both_val = bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False
|
| 152 |
open_val = bool(row["can_open"]) if "can_open" in keys else False
|
|
@@ -160,6 +164,7 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 160 |
hall_skill=SkillLevel(row["hall_skill"]),
|
| 161 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 162 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
|
|
|
| 163 |
can_work_both_positions=both_val,
|
| 164 |
can_open=open_val,
|
| 165 |
can_cleanup=cleanup_val,
|
|
|
|
| 60 |
def save_employee(emp: Employee) -> Employee:
|
| 61 |
conn = get_connection()
|
| 62 |
pp = emp.primary_position.value if emp.primary_position else None
|
| 63 |
+
op = emp.output_position.value if emp.output_position else None
|
| 64 |
pt = emp.primary_timeslot.value if emp.primary_timeslot else None
|
| 65 |
both = int(emp.can_work_both_positions)
|
| 66 |
opn = int(emp.can_open)
|
|
|
|
| 69 |
avail_d = int(emp.always_available_dinner)
|
| 70 |
if emp.id is None:
|
| 71 |
emp.id = conn.execute_insert(
|
| 72 |
+
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, output_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 73 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, 1)
|
| 74 |
)
|
| 75 |
else:
|
| 76 |
conn.execute(
|
| 77 |
+
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, output_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, is_active=? WHERE id=?",
|
| 78 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, int(emp.is_active), emp.id)
|
| 79 |
)
|
| 80 |
_save_fixed_patterns(conn, emp)
|
| 81 |
_save_fixed_unavailable_dates(conn, emp)
|
|
|
|
| 115 |
eid = row["id"]
|
| 116 |
keys = row.keys()
|
| 117 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
| 118 |
+
op_val = row["output_position"] if "output_position" in keys and row["output_position"] else None
|
| 119 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 120 |
return Employee(
|
| 121 |
id=eid, name=row["name"],
|
|
|
|
| 123 |
hall_skill=SkillLevel(row["hall_skill"]),
|
| 124 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 125 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 126 |
+
output_position=PrimaryPosition(op_val) if op_val else None,
|
| 127 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 128 |
can_work_both_positions=bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False,
|
| 129 |
can_open=bool(row["can_open"]) if "can_open" in keys else False,
|
|
|
|
| 150 |
).fetchall()
|
| 151 |
keys = row.keys()
|
| 152 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
| 153 |
+
op_val = row["output_position"] if "output_position" in keys and row["output_position"] else None
|
| 154 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 155 |
both_val = bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False
|
| 156 |
open_val = bool(row["can_open"]) if "can_open" in keys else False
|
|
|
|
| 164 |
hall_skill=SkillLevel(row["hall_skill"]),
|
| 165 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 166 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 167 |
+
output_position=PrimaryPosition(op_val) if op_val else None,
|
| 168 |
can_work_both_positions=both_val,
|
| 169 |
can_open=open_val,
|
| 170 |
can_cleanup=cleanup_val,
|
export/pdf_exporter.py
CHANGED
|
@@ -313,10 +313,12 @@ def export_pdf(
|
|
| 313 |
n = len(dates)
|
| 314 |
|
| 315 |
# ── 従業員をキッチン/ホールに分類 ───────────────────────────────
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
| 320 |
|
| 321 |
# ── 列幅 ─────────────────────────────────────────────────────────
|
| 322 |
page_w = landscape(A4)[0] - 2 * MARGIN
|
|
|
|
| 313 |
n = len(dates)
|
| 314 |
|
| 315 |
# ── 従業員をキッチン/ホールに分類 ───────────────────────────────
|
| 316 |
+
# output_position 優先、未設定なら primary_position で判断
|
| 317 |
+
def _out_pos(e):
|
| 318 |
+
return e.output_position or e.primary_position
|
| 319 |
+
|
| 320 |
+
kitchen_emps = [e for e in employees if _out_pos(e) == PrimaryPosition.KITCHEN]
|
| 321 |
+
hall_emps = [e for e in employees if _out_pos(e) != PrimaryPosition.KITCHEN]
|
| 322 |
|
| 323 |
# ── 列幅 ─────────────────────────────────────────────────────────
|
| 324 |
page_w = landscape(A4)[0] - 2 * MARGIN
|
models/employee.py
CHANGED
|
@@ -17,8 +17,9 @@ class Employee:
|
|
| 17 |
employment_type: EmploymentType
|
| 18 |
hall_skill: SkillLevel = SkillLevel.BEGINNER
|
| 19 |
kitchen_skill: SkillLevel = SkillLevel.BEGINNER
|
| 20 |
-
primary_position: Optional[PrimaryPosition] = None # None =
|
| 21 |
-
|
|
|
|
| 22 |
can_open: bool = False # True = 朝食開店準備(5:45〜6:30)対応可
|
| 23 |
can_cleanup: bool = False # True = 朝食片付け(10:00〜11:30)対応可
|
| 24 |
always_available_breakfast: bool = False # True = 朝食に希望提出不要・毎日出勤可
|
|
|
|
| 17 |
employment_type: EmploymentType
|
| 18 |
hall_skill: SkillLevel = SkillLevel.BEGINNER
|
| 19 |
kitchen_skill: SkillLevel = SkillLevel.BEGINNER
|
| 20 |
+
primary_position: Optional[PrimaryPosition] = None # None = 両方対応
|
| 21 |
+
output_position: Optional[PrimaryPosition] = None # PDF/Excel出力時の所属欄(None→primary_positionで代替)
|
| 22 |
+
can_work_both_positions: bool = False # True = 兼務可
|
| 23 |
can_open: bool = False # True = 朝食開店準備(5:45〜6:30)対応可
|
| 24 |
can_cleanup: bool = False # True = 朝食片付け(10:00〜11:30)対応可
|
| 25 |
always_available_breakfast: bool = False # True = 朝食に希望提出不要・毎日出勤可
|
routes/employees.py
CHANGED
|
@@ -100,9 +100,13 @@ def _form_to_employee(emp_id):
|
|
| 100 |
patterns.append(FixedPattern(dow, b, d))
|
| 101 |
|
| 102 |
pp_val = f.get("primary_position") or None
|
|
|
|
| 103 |
pt_val = f.get("primary_timeslot") or None
|
| 104 |
# 所属ポジションが「どちらでも」の場合は兼務可を自動でTrue
|
| 105 |
can_work_both = (pp_val is None)
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
return Employee(
|
| 108 |
id=emp_id,
|
|
@@ -111,6 +115,7 @@ def _form_to_employee(emp_id):
|
|
| 111 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 112 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 113 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
|
|
|
| 114 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 115 |
can_work_both_positions=can_work_both,
|
| 116 |
can_open=bool(f.get("can_open")),
|
|
|
|
| 100 |
patterns.append(FixedPattern(dow, b, d))
|
| 101 |
|
| 102 |
pp_val = f.get("primary_position") or None
|
| 103 |
+
op_val = f.get("output_position") or None
|
| 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(
|
| 112 |
id=emp_id,
|
|
|
|
| 115 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 116 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 117 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 118 |
+
output_position=PrimaryPosition(op_val) if op_val else None,
|
| 119 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 120 |
can_work_both_positions=can_work_both,
|
| 121 |
can_open=bool(f.get("can_open")),
|
templates/employees/form.html
CHANGED
|
@@ -75,6 +75,33 @@
|
|
| 75 |
<div class="form-text">「両方」を選ぶとホール・キッチンどちらにも配置できます</div>
|
| 76 |
</div>
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
<!-- 習熟度(ポジションに応じて表示切替) -->
|
| 79 |
<div class="row g-3" id="skill-row">
|
| 80 |
<div class="col" id="hall-skill-block">
|
|
@@ -215,9 +242,14 @@ function onPositionChange() {
|
|
| 215 |
const checked = document.querySelector('input[name="primary_position"]:checked');
|
| 216 |
const pos = checked ? checked.value : '';
|
| 217 |
|
|
|
|
| 218 |
document.getElementById('hall-skill-block').style.display = (pos === 'kitchen') ? 'none' : '';
|
| 219 |
document.getElementById('kitchen-skill-block').style.display = (pos === 'hall') ? 'none' : '';
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
['pos-hall-label','pos-kitchen-label','pos-both-label'].forEach(id => {
|
| 222 |
document.getElementById(id).classList.remove('selected');
|
| 223 |
});
|
|
@@ -226,6 +258,13 @@ function onPositionChange() {
|
|
| 226 |
else document.getElementById('pos-both-label').classList.add('selected');
|
| 227 |
}
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
onPositionChange();
|
| 230 |
|
| 231 |
function addUnavailDate() {
|
|
|
|
| 75 |
<div class="form-text">「両方」を選ぶとホール・キッチンどちらにも配置できます</div>
|
| 76 |
</div>
|
| 77 |
|
| 78 |
+
<!-- 出力時の所属欄(両方選択時のみ表示) -->
|
| 79 |
+
<div class="mb-3" id="output-pos-block" style="display:none">
|
| 80 |
+
<label class="form-label fw-semibold">
|
| 81 |
+
シフト表・PDF上の所属欄
|
| 82 |
+
<span class="badge bg-warning text-dark ms-1" style="font-size:.7rem">要設定</span>
|
| 83 |
+
</label>
|
| 84 |
+
{% set cur_op = emp.output_position.value if emp and emp.output_position else '' %}
|
| 85 |
+
<div class="d-flex gap-2">
|
| 86 |
+
<label class="pos-btn pos-hall flex-grow-1 text-center" id="op-hall-label">
|
| 87 |
+
<input type="radio" name="output_position" value="hall" class="d-none"
|
| 88 |
+
{{ 'checked' if cur_op == 'hall' else '' }}
|
| 89 |
+
onchange="onOutputPosChange()">
|
| 90 |
+
<i class="bi bi-people-fill d-block mb-1" style="font-size:1.1rem"></i>ホール欄
|
| 91 |
+
</label>
|
| 92 |
+
<label class="pos-btn pos-kitchen flex-grow-1 text-center" id="op-kitchen-label">
|
| 93 |
+
<input type="radio" name="output_position" value="kitchen" class="d-none"
|
| 94 |
+
{{ 'checked' if cur_op == 'kitchen' else '' }}
|
| 95 |
+
onchange="onOutputPosChange()">
|
| 96 |
+
<i class="bi bi-egg-fried d-block mb-1" style="font-size:1.1rem"></i>キッチン欄
|
| 97 |
+
</label>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="form-text" style="color:#b45309">
|
| 100 |
+
<i class="bi bi-exclamation-circle me-1"></i>
|
| 101 |
+
PDF・Excelのシフト表でこのスタッフをどの欄に記載するか選択してください
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
<!-- 習熟度(ポジションに応じて表示切替) -->
|
| 106 |
<div class="row g-3" id="skill-row">
|
| 107 |
<div class="col" id="hall-skill-block">
|
|
|
|
| 242 |
const checked = document.querySelector('input[name="primary_position"]:checked');
|
| 243 |
const pos = checked ? checked.value : '';
|
| 244 |
|
| 245 |
+
// 習熟度表示切替
|
| 246 |
document.getElementById('hall-skill-block').style.display = (pos === 'kitchen') ? 'none' : '';
|
| 247 |
document.getElementById('kitchen-skill-block').style.display = (pos === 'hall') ? 'none' : '';
|
| 248 |
|
| 249 |
+
// 出力ポジションブロック:両方の時のみ表示
|
| 250 |
+
document.getElementById('output-pos-block').style.display = (pos === '') ? '' : 'none';
|
| 251 |
+
|
| 252 |
+
// ポジションボタン選択状態
|
| 253 |
['pos-hall-label','pos-kitchen-label','pos-both-label'].forEach(id => {
|
| 254 |
document.getElementById(id).classList.remove('selected');
|
| 255 |
});
|
|
|
|
| 258 |
else document.getElementById('pos-both-label').classList.add('selected');
|
| 259 |
}
|
| 260 |
|
| 261 |
+
function onOutputPosChange() {
|
| 262 |
+
const checked = document.querySelector('input[name="output_position"]:checked');
|
| 263 |
+
const op = checked ? checked.value : '';
|
| 264 |
+
document.getElementById('op-hall-label').classList.toggle('selected', op === 'hall');
|
| 265 |
+
document.getElementById('op-kitchen-label').classList.toggle('selected', op === 'kitchen');
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
onPositionChange();
|
| 269 |
|
| 270 |
function addUnavailDate() {
|