Commit ·
a4b0406
1
Parent(s): 33a73dd
feat: 予約客数入力・増員機能と朝食タイムテーブル制約の実装
Browse files[予約客数]
- reservation_counts テーブル追加(period_id × date × breakfast/dinner)
- app_settings テーブル追加(キー値ストア)
- スケジュールビューの朝食/ディナー各タブに「予約数」行を追加
クリックで日毎の予約客数を入力、閾値超過日を赤ハイライト
- 設定画面に「予約客数による増員設定」セクションを追加
朝食/ディナーそれぞれ閾値・増員数を設定可能
- ソルバーが予約超過日の min_staff を自動増加
[朝食タイムテーブル]
- Employee に can_open フラグ追加(朝食開店準備5:45〜対応可)
- 従業員管理に「朝食開店準備対応可」チェックボックスを追加
- 設定画面にタイムテーブル情報表示と「開店準備必要人数」設定を追加
- ソルバー制約: 朝食シフトに can_open スタッフを必要数アサイン
不足する日は警告を出力(hard constraint は人数充足時のみ)
- スケジュールビューの名前セルに [開] バッジ表示
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/database.py +28 -0
- db/repositories.py +70 -4
- models/employee.py +1 -0
- optimizer/solver.py +45 -5
- ui/employee_view.py +7 -0
- ui/schedule_view.py +150 -7
- ui/settings_view.py +96 -0
db/database.py
CHANGED
|
@@ -106,6 +106,20 @@ def initialize_db():
|
|
| 106 |
note TEXT NOT NULL DEFAULT '',
|
| 107 |
UNIQUE(period_id, date)
|
| 108 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
""")
|
| 110 |
|
| 111 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
|
@@ -119,6 +133,7 @@ def initialize_db():
|
|
| 119 |
("shift_assignments","is_reinforcement", "INTEGER NOT NULL DEFAULT 0"),
|
| 120 |
("shift_assignments","reinf_start", "TEXT DEFAULT NULL"),
|
| 121 |
("shift_assignments","reinf_end", "TEXT DEFAULT NULL"),
|
|
|
|
| 122 |
]
|
| 123 |
for table, col, definition in migrations:
|
| 124 |
try:
|
|
@@ -139,5 +154,18 @@ def initialize_db():
|
|
| 139 |
(slot, pos, mn, mx, ml)
|
| 140 |
)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
conn.commit()
|
| 143 |
conn.close()
|
|
|
|
| 106 |
note TEXT NOT NULL DEFAULT '',
|
| 107 |
UNIQUE(period_id, date)
|
| 108 |
);
|
| 109 |
+
|
| 110 |
+
CREATE TABLE IF NOT EXISTS reservation_counts (
|
| 111 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 112 |
+
period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
|
| 113 |
+
date TEXT NOT NULL,
|
| 114 |
+
breakfast INTEGER NOT NULL DEFAULT 0,
|
| 115 |
+
dinner INTEGER NOT NULL DEFAULT 0,
|
| 116 |
+
UNIQUE(period_id, date)
|
| 117 |
+
);
|
| 118 |
+
|
| 119 |
+
CREATE TABLE IF NOT EXISTS app_settings (
|
| 120 |
+
key TEXT PRIMARY KEY,
|
| 121 |
+
value TEXT NOT NULL DEFAULT ''
|
| 122 |
+
);
|
| 123 |
""")
|
| 124 |
|
| 125 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
|
|
|
| 133 |
("shift_assignments","is_reinforcement", "INTEGER NOT NULL DEFAULT 0"),
|
| 134 |
("shift_assignments","reinf_start", "TEXT DEFAULT NULL"),
|
| 135 |
("shift_assignments","reinf_end", "TEXT DEFAULT NULL"),
|
| 136 |
+
("employees", "can_open", "INTEGER NOT NULL DEFAULT 0"),
|
| 137 |
]
|
| 138 |
for table, col, definition in migrations:
|
| 139 |
try:
|
|
|
|
| 154 |
(slot, pos, mn, mx, ml)
|
| 155 |
)
|
| 156 |
|
| 157 |
+
# アプリ設定デフォルト値を投入(既に存在する場合は無視)
|
| 158 |
+
default_app_settings = [
|
| 159 |
+
("reserv_threshold_breakfast", "50"),
|
| 160 |
+
("reserv_extra_breakfast", "1"),
|
| 161 |
+
("reserv_threshold_dinner", "40"),
|
| 162 |
+
("reserv_extra_dinner", "1"),
|
| 163 |
+
("open_prep_required", "2"),
|
| 164 |
+
]
|
| 165 |
+
for key, val in default_app_settings:
|
| 166 |
+
cur.execute(
|
| 167 |
+
"INSERT OR IGNORE INTO app_settings (key, value) VALUES (?,?)", (key, val)
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
conn.commit()
|
| 171 |
conn.close()
|
db/repositories.py
CHANGED
|
@@ -35,16 +35,17 @@ def save_employee(emp: Employee) -> Employee:
|
|
| 35 |
pp = emp.primary_position.value if emp.primary_position else None
|
| 36 |
pt = emp.primary_timeslot.value if emp.primary_timeslot else None
|
| 37 |
both = int(emp.can_work_both_positions)
|
|
|
|
| 38 |
if emp.id is None:
|
| 39 |
cur = conn.execute(
|
| 40 |
-
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, primary_timeslot, can_work_both_positions, is_active) VALUES (?,?,?,?,?,?,?,?)",
|
| 41 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, 1)
|
| 42 |
)
|
| 43 |
emp.id = cur.lastrowid
|
| 44 |
else:
|
| 45 |
conn.execute(
|
| 46 |
-
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, primary_timeslot=?, can_work_both_positions=?, is_active=? WHERE id=?",
|
| 47 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, int(emp.is_active), emp.id)
|
| 48 |
)
|
| 49 |
_save_fixed_patterns(conn, emp)
|
| 50 |
_save_fixed_unavailable_dates(conn, emp)
|
|
@@ -80,6 +81,7 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 80 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
| 81 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 82 |
both_val = bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False
|
|
|
|
| 83 |
return Employee(
|
| 84 |
id=row["id"],
|
| 85 |
name=row["name"],
|
|
@@ -88,6 +90,7 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 88 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 89 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 90 |
can_work_both_positions=both_val,
|
|
|
|
| 91 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 92 |
is_active=bool(row["is_active"]),
|
| 93 |
fixed_patterns=[
|
|
@@ -288,6 +291,69 @@ def remove_assignment(period_id: int, employee_id: int, date: str, time_slot: Ti
|
|
| 288 |
|
| 289 |
# ── 備考 ────────────────────────────────────────────────────────────────
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
def get_employee_pattern_history(emp_id: int) -> list[tuple[str, int]]:
|
| 292 |
"""従業員の過去の希望パターン頻度を [(pattern_id, count), ...] で返す(降順)"""
|
| 293 |
conn = get_connection()
|
|
|
|
| 35 |
pp = emp.primary_position.value if emp.primary_position else None
|
| 36 |
pt = emp.primary_timeslot.value if emp.primary_timeslot else None
|
| 37 |
both = int(emp.can_work_both_positions)
|
| 38 |
+
opn = int(emp.can_open)
|
| 39 |
if emp.id is None:
|
| 40 |
cur = conn.execute(
|
| 41 |
+
"INSERT INTO employees (name, employment_type, hall_skill, kitchen_skill, primary_position, primary_timeslot, can_work_both_positions, can_open, is_active) VALUES (?,?,?,?,?,?,?,?,?)",
|
| 42 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, 1)
|
| 43 |
)
|
| 44 |
emp.id = cur.lastrowid
|
| 45 |
else:
|
| 46 |
conn.execute(
|
| 47 |
+
"UPDATE employees SET name=?, employment_type=?, hall_skill=?, kitchen_skill=?, primary_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, is_active=? WHERE id=?",
|
| 48 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, pt, both, opn, int(emp.is_active), emp.id)
|
| 49 |
)
|
| 50 |
_save_fixed_patterns(conn, emp)
|
| 51 |
_save_fixed_unavailable_dates(conn, emp)
|
|
|
|
| 81 |
pp_val = row["primary_position"] if "primary_position" in keys and row["primary_position"] else None
|
| 82 |
pt_val = row["primary_timeslot"] if "primary_timeslot" in keys and row["primary_timeslot"] else None
|
| 83 |
both_val = bool(row["can_work_both_positions"]) if "can_work_both_positions" in keys else False
|
| 84 |
+
open_val = bool(row["can_open"]) if "can_open" in keys else False
|
| 85 |
return Employee(
|
| 86 |
id=row["id"],
|
| 87 |
name=row["name"],
|
|
|
|
| 90 |
kitchen_skill=SkillLevel(row["kitchen_skill"]),
|
| 91 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
| 92 |
can_work_both_positions=both_val,
|
| 93 |
+
can_open=open_val,
|
| 94 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 95 |
is_active=bool(row["is_active"]),
|
| 96 |
fixed_patterns=[
|
|
|
|
| 291 |
|
| 292 |
# ── 備考 ────────────────────────────────────────────────────────────────
|
| 293 |
|
| 294 |
+
# ── 予約客数 ─────────────────────────────────────────────────────────────
|
| 295 |
+
|
| 296 |
+
def get_reservation_counts(period_id: int) -> dict[str, dict[str, int]]:
|
| 297 |
+
"""期間の予約客数を {date_str: {"breakfast": int, "dinner": int}} で返す"""
|
| 298 |
+
conn = get_connection()
|
| 299 |
+
rows = conn.execute(
|
| 300 |
+
"SELECT date, breakfast, dinner FROM reservation_counts WHERE period_id=? ORDER BY date",
|
| 301 |
+
(period_id,)
|
| 302 |
+
).fetchall()
|
| 303 |
+
conn.close()
|
| 304 |
+
return {r["date"]: {"breakfast": r["breakfast"], "dinner": r["dinner"]} for r in rows}
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def save_reservation_count(period_id: int, date_str: str, breakfast: int, dinner: int):
|
| 308 |
+
"""予約客数を保存"""
|
| 309 |
+
conn = get_connection()
|
| 310 |
+
conn.execute(
|
| 311 |
+
"""INSERT INTO reservation_counts (period_id, date, breakfast, dinner) VALUES (?,?,?,?)
|
| 312 |
+
ON CONFLICT(period_id, date) DO UPDATE SET
|
| 313 |
+
breakfast=excluded.breakfast, dinner=excluded.dinner""",
|
| 314 |
+
(period_id, date_str, breakfast, dinner)
|
| 315 |
+
)
|
| 316 |
+
conn.commit()
|
| 317 |
+
conn.close()
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
# ── アプリ設定 ────────────────────────────────────────────────────────────
|
| 321 |
+
|
| 322 |
+
def get_app_setting(key: str, default: str = "") -> str:
|
| 323 |
+
conn = get_connection()
|
| 324 |
+
row = conn.execute("SELECT value FROM app_settings WHERE key=?", (key,)).fetchone()
|
| 325 |
+
conn.close()
|
| 326 |
+
return row["value"] if row else default
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def save_app_setting(key: str, value: str):
|
| 330 |
+
conn = get_connection()
|
| 331 |
+
conn.execute(
|
| 332 |
+
"INSERT INTO app_settings (key, value) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
| 333 |
+
(key, value)
|
| 334 |
+
)
|
| 335 |
+
conn.commit()
|
| 336 |
+
conn.close()
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def get_all_app_settings() -> dict[str, str]:
|
| 340 |
+
conn = get_connection()
|
| 341 |
+
rows = conn.execute("SELECT key, value FROM app_settings").fetchall()
|
| 342 |
+
conn.close()
|
| 343 |
+
return {r["key"]: r["value"] for r in rows}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def save_all_app_settings(settings: dict[str, str]):
|
| 347 |
+
conn = get_connection()
|
| 348 |
+
for key, value in settings.items():
|
| 349 |
+
conn.execute(
|
| 350 |
+
"INSERT INTO app_settings (key, value) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
| 351 |
+
(key, value)
|
| 352 |
+
)
|
| 353 |
+
conn.commit()
|
| 354 |
+
conn.close()
|
| 355 |
+
|
| 356 |
+
|
| 357 |
def get_employee_pattern_history(emp_id: int) -> list[tuple[str, int]]:
|
| 358 |
"""従業員の過去の希望パターン頻度を [(pattern_id, count), ...] で返す(降順)"""
|
| 359 |
conn = get_connection()
|
models/employee.py
CHANGED
|
@@ -19,6 +19,7 @@ class Employee:
|
|
| 19 |
kitchen_skill: SkillLevel = SkillLevel.BEGINNER
|
| 20 |
primary_position: Optional[PrimaryPosition] = None # None = 未設定(旧データ互換)
|
| 21 |
can_work_both_positions: bool = False # True = 兼務可(主所属外でも対応可)
|
|
|
|
| 22 |
primary_timeslot: Optional[TimeSlot] = None # None = どちらでも可
|
| 23 |
fixed_patterns: list[FixedPattern] = field(default_factory=list)
|
| 24 |
fixed_unavailable_dates: list[str] = field(default_factory=list) # YYYY-MM-DD
|
|
|
|
| 19 |
kitchen_skill: SkillLevel = SkillLevel.BEGINNER
|
| 20 |
primary_position: Optional[PrimaryPosition] = None # None = 未設定(旧データ互換)
|
| 21 |
can_work_both_positions: bool = False # True = 兼務可(主所属外でも対応可)
|
| 22 |
+
can_open: bool = False # True = 朝食開店準備(5:45)対応可
|
| 23 |
primary_timeslot: Optional[TimeSlot] = None # None = どちらでも可
|
| 24 |
fixed_patterns: list[FixedPattern] = field(default_factory=list)
|
| 25 |
fixed_unavailable_dates: list[str] = field(default_factory=list) # YYYY-MM-DD
|
optimizer/solver.py
CHANGED
|
@@ -76,9 +76,20 @@ def solve(
|
|
| 76 |
|
| 77 |
active_employees = [e for e in employees if e.is_active]
|
| 78 |
|
| 79 |
-
# DB から制約を読み込む
|
| 80 |
from db import repositories as repo
|
| 81 |
shift_constraints = repo.get_shift_constraints()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# ── 決定変数 ────────────────────────────────────────────────────────
|
| 84 |
# assign[e_id][date_str][slot][pos] = BoolVar
|
|
@@ -134,21 +145,32 @@ def solve(
|
|
| 134 |
]
|
| 135 |
model.add(sum(all_vars) <= 1)
|
| 136 |
|
| 137 |
-
# 4. 人員数制約(最低/最大)
|
| 138 |
for ds in date_strs:
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
for slot in slots:
|
| 141 |
for pos in positions:
|
| 142 |
key = (slot, pos)
|
| 143 |
constraint = shift_constraints.get(key)
|
| 144 |
if not constraint:
|
| 145 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
staff_vars = [
|
| 147 |
assign[emp.id][ds][slot.value][pos.value]
|
| 148 |
for emp in active_employees
|
| 149 |
]
|
| 150 |
-
model.add(sum(staff_vars) >=
|
| 151 |
-
model.add(sum(staff_vars) <=
|
| 152 |
|
| 153 |
# 5. リーダー配置制約(絶対制約:リーダーの最低配置数)
|
| 154 |
for ds in date_strs:
|
|
@@ -168,6 +190,24 @@ def solve(
|
|
| 168 |
]
|
| 169 |
model.add(sum(leader_vars) >= min_leader)
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
# 6. 正社員の両時間帯掛け持ちは最小化(ソフト制約で対応)
|
| 172 |
# 両時間帯掛け持ち変数
|
| 173 |
double_vars: dict[tuple[int, str], cp_model.IntVar] = {}
|
|
|
|
| 76 |
|
| 77 |
active_employees = [e for e in employees if e.is_active]
|
| 78 |
|
| 79 |
+
# DB から制約・予約客数・アプリ設定を読み込む
|
| 80 |
from db import repositories as repo
|
| 81 |
shift_constraints = repo.get_shift_constraints()
|
| 82 |
+
reservation_counts = repo.get_reservation_counts(period.id)
|
| 83 |
+
try:
|
| 84 |
+
reserv_thresh_b = int(repo.get_app_setting("reserv_threshold_breakfast", "50"))
|
| 85 |
+
reserv_extra_b = int(repo.get_app_setting("reserv_extra_breakfast", "1"))
|
| 86 |
+
reserv_thresh_d = int(repo.get_app_setting("reserv_threshold_dinner", "40"))
|
| 87 |
+
reserv_extra_d = int(repo.get_app_setting("reserv_extra_dinner", "1"))
|
| 88 |
+
open_prep_req = int(repo.get_app_setting("open_prep_required", "2"))
|
| 89 |
+
except Exception:
|
| 90 |
+
reserv_thresh_b = 50; reserv_extra_b = 1
|
| 91 |
+
reserv_thresh_d = 40; reserv_extra_d = 1
|
| 92 |
+
open_prep_req = 2
|
| 93 |
|
| 94 |
# ── 決定変数 ────────────────────────────────────────────────────────
|
| 95 |
# assign[e_id][date_str][slot][pos] = BoolVar
|
|
|
|
| 145 |
]
|
| 146 |
model.add(sum(all_vars) <= 1)
|
| 147 |
|
| 148 |
+
# 4. 人員数制約(最低/最大)+予約客数による増員
|
| 149 |
for ds in date_strs:
|
| 150 |
+
rc = reservation_counts.get(ds, {})
|
| 151 |
+
b_count = rc.get("breakfast", 0)
|
| 152 |
+
d_count = rc.get("dinner", 0)
|
| 153 |
for slot in slots:
|
| 154 |
for pos in positions:
|
| 155 |
key = (slot, pos)
|
| 156 |
constraint = shift_constraints.get(key)
|
| 157 |
if not constraint:
|
| 158 |
continue
|
| 159 |
+
base_min = constraint["min"]
|
| 160 |
+
base_max = constraint["max"]
|
| 161 |
+
# 予約超過時の増員
|
| 162 |
+
if slot == TimeSlot.BREAKFAST and b_count >= reserv_thresh_b > 0:
|
| 163 |
+
base_min += reserv_extra_b
|
| 164 |
+
base_max = max(base_max, base_min)
|
| 165 |
+
elif slot == TimeSlot.DINNER and d_count >= reserv_thresh_d > 0:
|
| 166 |
+
base_min += reserv_extra_d
|
| 167 |
+
base_max = max(base_max, base_min)
|
| 168 |
staff_vars = [
|
| 169 |
assign[emp.id][ds][slot.value][pos.value]
|
| 170 |
for emp in active_employees
|
| 171 |
]
|
| 172 |
+
model.add(sum(staff_vars) >= base_min)
|
| 173 |
+
model.add(sum(staff_vars) <= base_max)
|
| 174 |
|
| 175 |
# 5. リーダー配置制約(絶対制約:リーダーの最低配置数)
|
| 176 |
for ds in date_strs:
|
|
|
|
| 190 |
]
|
| 191 |
model.add(sum(leader_vars) >= min_leader)
|
| 192 |
|
| 193 |
+
# 5b. 開店準備制約: 朝食に open_prep_req 人以上の can_open スタッフを配置
|
| 194 |
+
if open_prep_req > 0:
|
| 195 |
+
for ds in date_strs:
|
| 196 |
+
can_open_requested = [
|
| 197 |
+
emp for emp in active_employees
|
| 198 |
+
if emp.can_open and req_map.get((emp.id, ds, TimeSlot.BREAKFAST.value))
|
| 199 |
+
]
|
| 200 |
+
if len(can_open_requested) >= open_prep_req:
|
| 201 |
+
open_vars = [
|
| 202 |
+
assign[emp.id][ds][TimeSlot.BREAKFAST.value][pos.value]
|
| 203 |
+
for emp in can_open_requested for pos in positions
|
| 204 |
+
]
|
| 205 |
+
model.add(sum(open_vars) >= open_prep_req)
|
| 206 |
+
elif can_open_requested:
|
| 207 |
+
warnings.append(
|
| 208 |
+
f"{ds}: 開店準備対応可スタッフが {len(can_open_requested)} 名(必要 {open_prep_req} 名)"
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
# 6. 正社員の両時間帯掛け持ちは最小化(ソフト制約で対応)
|
| 212 |
# 両時間帯掛け持ち変数
|
| 213 |
double_vars: dict[tuple[int, str], cp_model.IntVar] = {}
|
ui/employee_view.py
CHANGED
|
@@ -251,6 +251,10 @@ class EmployeeDialog(QDialog):
|
|
| 251 |
self.can_both_check = QCheckBox("兼務可(主所属外のポジションにも入れる)")
|
| 252 |
form.addRow("", self.can_both_check)
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
self.primary_ts_combo = QComboBox()
|
| 255 |
self.primary_ts_combo.addItem("どちらでも", None)
|
| 256 |
self.primary_ts_combo.addItem("朝食専任", TimeSlot.BREAKFAST)
|
|
@@ -376,6 +380,7 @@ class EmployeeDialog(QDialog):
|
|
| 376 |
idx_pp = self.primary_pos_combo.findData(emp.primary_position)
|
| 377 |
self.primary_pos_combo.setCurrentIndex(idx_pp if idx_pp >= 0 else 0)
|
| 378 |
self.can_both_check.setChecked(emp.can_work_both_positions)
|
|
|
|
| 379 |
idx_pt = self.primary_ts_combo.findData(emp.primary_timeslot)
|
| 380 |
self.primary_ts_combo.setCurrentIndex(idx_pt if idx_pt >= 0 else 0)
|
| 381 |
|
|
@@ -402,6 +407,7 @@ class EmployeeDialog(QDialog):
|
|
| 402 |
emp_type = self.emp_type_combo.currentData()
|
| 403 |
primary_position = self.primary_pos_combo.currentData()
|
| 404 |
can_work_both = self.can_both_check.isChecked()
|
|
|
|
| 405 |
primary_timeslot = self.primary_ts_combo.currentData()
|
| 406 |
hall_skill = self.hall_skill_combo.currentData()
|
| 407 |
kitchen_skill = self.kitchen_skill_combo.currentData()
|
|
@@ -426,6 +432,7 @@ class EmployeeDialog(QDialog):
|
|
| 426 |
kitchen_skill=kitchen_skill,
|
| 427 |
primary_position=primary_position,
|
| 428 |
can_work_both_positions=can_work_both,
|
|
|
|
| 429 |
primary_timeslot=primary_timeslot,
|
| 430 |
fixed_patterns=patterns,
|
| 431 |
fixed_unavailable_dates=unavail_dates,
|
|
|
|
| 251 |
self.can_both_check = QCheckBox("兼務可(主所属外のポジションにも入れる)")
|
| 252 |
form.addRow("", self.can_both_check)
|
| 253 |
|
| 254 |
+
self.can_open_check = QCheckBox("朝食開店準備対応可(5:45〜 入れる)")
|
| 255 |
+
self.can_open_check.setToolTip("チェックすると朝食の開店準備シフト(5:45〜)に対応可能として扱います")
|
| 256 |
+
form.addRow("", self.can_open_check)
|
| 257 |
+
|
| 258 |
self.primary_ts_combo = QComboBox()
|
| 259 |
self.primary_ts_combo.addItem("どちらでも", None)
|
| 260 |
self.primary_ts_combo.addItem("朝食専任", TimeSlot.BREAKFAST)
|
|
|
|
| 380 |
idx_pp = self.primary_pos_combo.findData(emp.primary_position)
|
| 381 |
self.primary_pos_combo.setCurrentIndex(idx_pp if idx_pp >= 0 else 0)
|
| 382 |
self.can_both_check.setChecked(emp.can_work_both_positions)
|
| 383 |
+
self.can_open_check.setChecked(emp.can_open)
|
| 384 |
idx_pt = self.primary_ts_combo.findData(emp.primary_timeslot)
|
| 385 |
self.primary_ts_combo.setCurrentIndex(idx_pt if idx_pt >= 0 else 0)
|
| 386 |
|
|
|
|
| 407 |
emp_type = self.emp_type_combo.currentData()
|
| 408 |
primary_position = self.primary_pos_combo.currentData()
|
| 409 |
can_work_both = self.can_both_check.isChecked()
|
| 410 |
+
can_open = self.can_open_check.isChecked()
|
| 411 |
primary_timeslot = self.primary_ts_combo.currentData()
|
| 412 |
hall_skill = self.hall_skill_combo.currentData()
|
| 413 |
kitchen_skill = self.kitchen_skill_combo.currentData()
|
|
|
|
| 432 |
kitchen_skill=kitchen_skill,
|
| 433 |
primary_position=primary_position,
|
| 434 |
can_work_both_positions=can_work_both,
|
| 435 |
+
can_open=can_open,
|
| 436 |
primary_timeslot=primary_timeslot,
|
| 437 |
fixed_patterns=patterns,
|
| 438 |
fixed_unavailable_dates=unavail_dates,
|
ui/schedule_view.py
CHANGED
|
@@ -42,8 +42,10 @@ class ScheduleView(QWidget):
|
|
| 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] = {}
|
| 45 |
-
self._notes: dict[str, str] = {}
|
| 46 |
-
self.
|
|
|
|
|
|
|
| 47 |
self._build_ui()
|
| 48 |
self._load_periods()
|
| 49 |
|
|
@@ -108,9 +110,10 @@ class ScheduleView(QWidget):
|
|
| 108 |
|
| 109 |
(tab_b, self.emp_table_b, self.sum_table_b,
|
| 110 |
self._btn_other_b, self._warn_label_b,
|
| 111 |
-
self._notes_table) = self._make_tab_widget(TimeSlot.BREAKFAST)
|
| 112 |
(tab_d, self.emp_table_d, self.sum_table_d,
|
| 113 |
-
self._btn_other_d, self._warn_label_d,
|
|
|
|
| 114 |
|
| 115 |
self.tab_widget.addTab(tab_b, "🌅 朝食")
|
| 116 |
self.tab_widget.addTab(tab_d, "🌆 ディナー")
|
|
@@ -160,6 +163,23 @@ class ScheduleView(QWidget):
|
|
| 160 |
warn_label.setVisible(False)
|
| 161 |
vbox.addWidget(warn_label)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# 備考テーブル(朝食タブのみ)
|
| 164 |
notes_table = None
|
| 165 |
if slot == TimeSlot.BREAKFAST:
|
|
@@ -212,6 +232,8 @@ class ScheduleView(QWidget):
|
|
| 212 |
# 水平スクロール同期(emp_table ↔ sum_table、朝食タブは notes_table も同期)
|
| 213 |
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 214 |
sum_table.horizontalScrollBar().setValue)
|
|
|
|
|
|
|
| 215 |
if notes_table is not None:
|
| 216 |
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 217 |
notes_table.horizontalScrollBar().setValue)
|
|
@@ -221,7 +243,7 @@ class ScheduleView(QWidget):
|
|
| 221 |
sep.setFrameShape(QFrame.Shape.HLine)
|
| 222 |
vbox.insertWidget(vbox.count() - 1, sep) # sum_tableの直前に挿入
|
| 223 |
|
| 224 |
-
return container, emp_table, sum_table, btn, warn_label, notes_table
|
| 225 |
|
| 226 |
def _sync_col_width(self, col_idx: int, new_width: int, slot: TimeSlot):
|
| 227 |
"""従業員テーブルの列幅変更を集計・備考テーブルに反映"""
|
|
@@ -230,6 +252,9 @@ class ScheduleView(QWidget):
|
|
| 230 |
sum_t.setColumnWidth(col_idx, new_width)
|
| 231 |
if slot == TimeSlot.BREAKFAST and self._notes_table and col_idx < self._notes_table.columnCount():
|
| 232 |
self._notes_table.setColumnWidth(col_idx, new_width)
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
def _on_toggle_other(self, slot: TimeSlot, checked: bool):
|
| 235 |
self._show_other[slot] = checked
|
|
@@ -343,7 +368,8 @@ class ScheduleView(QWidget):
|
|
| 343 |
(r.employee_id, r.date): r
|
| 344 |
for r in requests
|
| 345 |
}
|
| 346 |
-
self._notes
|
|
|
|
| 347 |
|
| 348 |
# ── 描画 ──────────────────────────────────────────────────────────────
|
| 349 |
|
|
@@ -516,10 +542,14 @@ class ScheduleView(QWidget):
|
|
| 516 |
# 警告更新
|
| 517 |
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map, shift_constraints)
|
| 518 |
|
| 519 |
-
# 備考テーブル
|
| 520 |
if slot == TimeSlot.BREAKFAST:
|
| 521 |
self._col_date_strs_b = col_date_strs
|
| 522 |
self._render_notes_row()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
|
| 524 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
| 525 |
c = theme.c
|
|
@@ -539,6 +569,8 @@ class ScheduleView(QWidget):
|
|
| 539 |
skill_k = SKILL_BADGE.get(emp.kitchen_skill, "")
|
| 540 |
pp_base = f"[{emp.primary_position.label()[:1]}]" if emp.primary_position else ""
|
| 541 |
pp = f"{pp_base}[兼]" if emp.can_work_both_positions else pp_base
|
|
|
|
|
|
|
| 542 |
is_other = emp.id in other_ids
|
| 543 |
is_reinf_emp = bool(reinf_emp_ids and emp.id in reinf_emp_ids)
|
| 544 |
other_slot = TimeSlot.DINNER if slot == TimeSlot.BREAKFAST else TimeSlot.BREAKFAST
|
|
@@ -665,6 +697,73 @@ class ScheduleView(QWidget):
|
|
| 665 |
else:
|
| 666 |
warn_label.setVisible(False)
|
| 667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
# ── 備考テーブル ──────────────────────────────────────────────────────
|
| 669 |
|
| 670 |
def _render_notes_row(self):
|
|
@@ -1176,6 +1275,50 @@ class NoteEditDialog(QDialog):
|
|
| 1176 |
return self._edit.text().strip()
|
| 1177 |
|
| 1178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1179 |
# ── ポジション選択ダイアログ ──────────────────────────────────────────────
|
| 1180 |
|
| 1181 |
class PositionSelectDialog(QDialog):
|
|
|
|
| 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] = {}
|
| 45 |
+
self._notes: dict[str, str] = {} # {date_str: note}
|
| 46 |
+
self._reservations: dict[str, dict[str, int]] = {} # {date_str: {"breakfast": int, "dinner": int}}
|
| 47 |
+
self._col_date_strs_b: list[str | None] = [] # 朝食タブの日付列リスト
|
| 48 |
+
self._col_date_strs_d: list[str | None] = [] # ディナータブの日付列リスト
|
| 49 |
self._build_ui()
|
| 50 |
self._load_periods()
|
| 51 |
|
|
|
|
| 110 |
|
| 111 |
(tab_b, self.emp_table_b, self.sum_table_b,
|
| 112 |
self._btn_other_b, self._warn_label_b,
|
| 113 |
+
self._notes_table, self._reserv_table_b) = self._make_tab_widget(TimeSlot.BREAKFAST)
|
| 114 |
(tab_d, self.emp_table_d, self.sum_table_d,
|
| 115 |
+
self._btn_other_d, self._warn_label_d,
|
| 116 |
+
_, self._reserv_table_d) = self._make_tab_widget(TimeSlot.DINNER)
|
| 117 |
|
| 118 |
self.tab_widget.addTab(tab_b, "🌅 朝食")
|
| 119 |
self.tab_widget.addTab(tab_d, "🌆 ディナー")
|
|
|
|
| 163 |
warn_label.setVisible(False)
|
| 164 |
vbox.addWidget(warn_label)
|
| 165 |
|
| 166 |
+
# 予約数テーブル(両タブ共通)
|
| 167 |
+
reserv_table = QTableWidget()
|
| 168 |
+
reserv_table.setRowCount(1)
|
| 169 |
+
reserv_table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
| 170 |
+
reserv_table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
|
| 171 |
+
reserv_table.verticalHeader().setVisible(False)
|
| 172 |
+
reserv_table.horizontalHeader().setVisible(False)
|
| 173 |
+
reserv_table.setShowGrid(True)
|
| 174 |
+
reserv_table.setFixedHeight(26)
|
| 175 |
+
reserv_table.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
| 176 |
+
reserv_table.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
| 177 |
+
reserv_table.setRowHeight(0, 22)
|
| 178 |
+
reserv_table.setToolTip("クリックしてその日の予約客数を入力できます。シフト生成時の増員判定に使用されます。")
|
| 179 |
+
reserv_table.cellClicked.connect(
|
| 180 |
+
lambda r, c, s=slot: self._on_reserv_cell_clicked(c, s))
|
| 181 |
+
vbox.addWidget(reserv_table)
|
| 182 |
+
|
| 183 |
# 備考テーブル(朝食タブのみ)
|
| 184 |
notes_table = None
|
| 185 |
if slot == TimeSlot.BREAKFAST:
|
|
|
|
| 232 |
# 水平スクロール同期(emp_table ↔ sum_table、朝食タブは notes_table も同期)
|
| 233 |
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 234 |
sum_table.horizontalScrollBar().setValue)
|
| 235 |
+
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 236 |
+
reserv_table.horizontalScrollBar().setValue)
|
| 237 |
if notes_table is not None:
|
| 238 |
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 239 |
notes_table.horizontalScrollBar().setValue)
|
|
|
|
| 243 |
sep.setFrameShape(QFrame.Shape.HLine)
|
| 244 |
vbox.insertWidget(vbox.count() - 1, sep) # sum_tableの直前に挿入
|
| 245 |
|
| 246 |
+
return container, emp_table, sum_table, btn, warn_label, notes_table, reserv_table
|
| 247 |
|
| 248 |
def _sync_col_width(self, col_idx: int, new_width: int, slot: TimeSlot):
|
| 249 |
"""従業員テーブルの列幅変更を集計・備考テーブルに反映"""
|
|
|
|
| 252 |
sum_t.setColumnWidth(col_idx, new_width)
|
| 253 |
if slot == TimeSlot.BREAKFAST and self._notes_table and col_idx < self._notes_table.columnCount():
|
| 254 |
self._notes_table.setColumnWidth(col_idx, new_width)
|
| 255 |
+
reserv_t = self._reserv_table_b if slot == TimeSlot.BREAKFAST else self._reserv_table_d
|
| 256 |
+
if col_idx < reserv_t.columnCount():
|
| 257 |
+
reserv_t.setColumnWidth(col_idx, new_width)
|
| 258 |
|
| 259 |
def _on_toggle_other(self, slot: TimeSlot, checked: bool):
|
| 260 |
self._show_other[slot] = checked
|
|
|
|
| 368 |
(r.employee_id, r.date): r
|
| 369 |
for r in requests
|
| 370 |
}
|
| 371 |
+
self._notes = repo.get_schedule_notes(self._period.id)
|
| 372 |
+
self._reservations = repo.get_reservation_counts(self._period.id)
|
| 373 |
|
| 374 |
# ── 描画 ──────────────────────────────────────────────────────────────
|
| 375 |
|
|
|
|
| 542 |
# 警告更新
|
| 543 |
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map, shift_constraints)
|
| 544 |
|
| 545 |
+
# 備考・予約数テーブル更新
|
| 546 |
if slot == TimeSlot.BREAKFAST:
|
| 547 |
self._col_date_strs_b = col_date_strs
|
| 548 |
self._render_notes_row()
|
| 549 |
+
self._render_reserv_row(TimeSlot.BREAKFAST, col_date_strs, self._reserv_table_b)
|
| 550 |
+
else:
|
| 551 |
+
self._col_date_strs_d = col_date_strs
|
| 552 |
+
self._render_reserv_row(TimeSlot.DINNER, col_date_strs, self._reserv_table_d)
|
| 553 |
|
| 554 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
| 555 |
c = theme.c
|
|
|
|
| 569 |
skill_k = SKILL_BADGE.get(emp.kitchen_skill, "")
|
| 570 |
pp_base = f"[{emp.primary_position.label()[:1]}]" if emp.primary_position else ""
|
| 571 |
pp = f"{pp_base}[兼]" if emp.can_work_both_positions else pp_base
|
| 572 |
+
if emp.can_open and slot == TimeSlot.BREAKFAST:
|
| 573 |
+
pp = pp + "[開]"
|
| 574 |
is_other = emp.id in other_ids
|
| 575 |
is_reinf_emp = bool(reinf_emp_ids and emp.id in reinf_emp_ids)
|
| 576 |
other_slot = TimeSlot.DINNER if slot == TimeSlot.BREAKFAST else TimeSlot.BREAKFAST
|
|
|
|
| 697 |
else:
|
| 698 |
warn_label.setVisible(False)
|
| 699 |
|
| 700 |
+
# ── 予約数テーブル ────────────────────────────────────────────────────
|
| 701 |
+
|
| 702 |
+
def _render_reserv_row(self, slot: TimeSlot, col_date_strs: list, reserv_table: QTableWidget):
|
| 703 |
+
if not col_date_strs:
|
| 704 |
+
return
|
| 705 |
+
slot_key = "breakfast" if slot == TimeSlot.BREAKFAST else "dinner"
|
| 706 |
+
label = "朝食予約" if slot == TimeSlot.BREAKFAST else "夜予約"
|
| 707 |
+
emp_table = self.emp_table_b if slot == TimeSlot.BREAKFAST else self.emp_table_d
|
| 708 |
+
n_cols = len(col_date_strs)
|
| 709 |
+
reserv_table.setColumnCount(n_cols)
|
| 710 |
+
for c_i in range(n_cols):
|
| 711 |
+
reserv_table.setColumnWidth(c_i, emp_table.columnWidth(c_i))
|
| 712 |
+
|
| 713 |
+
# 閾値を読んで超過日のハイライト判定
|
| 714 |
+
try:
|
| 715 |
+
thresh = int(repo.get_app_setting(
|
| 716 |
+
"reserv_threshold_breakfast" if slot == TimeSlot.BREAKFAST else "reserv_threshold_dinner",
|
| 717 |
+
"50" if slot == TimeSlot.BREAKFAST else "40"
|
| 718 |
+
))
|
| 719 |
+
except Exception:
|
| 720 |
+
thresh = 999
|
| 721 |
+
c = theme.c
|
| 722 |
+
for col_idx, ds in enumerate(col_date_strs):
|
| 723 |
+
if col_idx == 0 or ds is None:
|
| 724 |
+
item = QTableWidgetItem(label if col_idx == 0 else "")
|
| 725 |
+
item.setBackground(QBrush(QColor(c["surface2"])))
|
| 726 |
+
item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 727 |
+
item.setForeground(QBrush(QColor(c["text3"])))
|
| 728 |
+
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 729 |
+
else:
|
| 730 |
+
count = self._reservations.get(ds, {}).get(slot_key, 0)
|
| 731 |
+
text = str(count) if count > 0 else "-"
|
| 732 |
+
item = QTableWidgetItem(text)
|
| 733 |
+
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 734 |
+
item.setFont(QFont("", 8))
|
| 735 |
+
if count > 0 and count >= thresh:
|
| 736 |
+
item.setBackground(QBrush(QColor("#FEE2E2"))) # 赤系: 閾値超過
|
| 737 |
+
item.setForeground(QBrush(QColor(c["text"])))
|
| 738 |
+
elif count > 0:
|
| 739 |
+
item.setBackground(QBrush(QColor("#FEF3C7"))) # 黄系: 入力あり
|
| 740 |
+
item.setForeground(QBrush(QColor(c["text"])))
|
| 741 |
+
else:
|
| 742 |
+
item.setBackground(QBrush(QColor(c["bg"])))
|
| 743 |
+
item.setForeground(QBrush(QColor(c["text3"])))
|
| 744 |
+
reserv_table.setItem(0, col_idx, item)
|
| 745 |
+
|
| 746 |
+
def _on_reserv_cell_clicked(self, col: int, slot: TimeSlot):
|
| 747 |
+
if not self._period:
|
| 748 |
+
return
|
| 749 |
+
col_date_strs = self._col_date_strs_b if slot == TimeSlot.BREAKFAST else self._col_date_strs_d
|
| 750 |
+
if not col_date_strs or col == 0 or col >= len(col_date_strs) - 1:
|
| 751 |
+
return
|
| 752 |
+
ds = col_date_strs[col]
|
| 753 |
+
if not ds:
|
| 754 |
+
return
|
| 755 |
+
slot_key = "breakfast" if slot == TimeSlot.BREAKFAST else "dinner"
|
| 756 |
+
current = self._reservations.get(ds, {}).get(slot_key, 0)
|
| 757 |
+
dlg = ReservationEditDialog(ds, slot, current, parent=self)
|
| 758 |
+
if dlg.exec() == QDialog.DialogCode.Accepted:
|
| 759 |
+
count = dlg.count
|
| 760 |
+
rc = self._reservations.setdefault(ds, {"breakfast": 0, "dinner": 0}).copy()
|
| 761 |
+
rc[slot_key] = count
|
| 762 |
+
self._reservations[ds] = rc
|
| 763 |
+
repo.save_reservation_count(self._period.id, ds, rc["breakfast"], rc["dinner"])
|
| 764 |
+
reserv_table = self._reserv_table_b if slot == TimeSlot.BREAKFAST else self._reserv_table_d
|
| 765 |
+
self._render_reserv_row(slot, col_date_strs, reserv_table)
|
| 766 |
+
|
| 767 |
# ── 備考テーブル ──────────────────────────────────────────────────────
|
| 768 |
|
| 769 |
def _render_notes_row(self):
|
|
|
|
| 1275 |
return self._edit.text().strip()
|
| 1276 |
|
| 1277 |
|
| 1278 |
+
# ── 予約客数編集ダイアログ ────────────────────────────────────────────────
|
| 1279 |
+
|
| 1280 |
+
class ReservationEditDialog(QDialog):
|
| 1281 |
+
def __init__(self, date_str: str, slot: TimeSlot, current_count: int, parent=None):
|
| 1282 |
+
super().__init__(parent)
|
| 1283 |
+
d = date.fromisoformat(date_str)
|
| 1284 |
+
dow = DAY_OF_WEEK_LABELS[d.weekday()]
|
| 1285 |
+
slot_label = "朝食" if slot == TimeSlot.BREAKFAST else "ディナー"
|
| 1286 |
+
self.setWindowTitle(f"{d.month}/{d.day}({dow}) {slot_label}予約客数")
|
| 1287 |
+
self.setFixedWidth(320)
|
| 1288 |
+
|
| 1289 |
+
layout = QVBoxLayout(self)
|
| 1290 |
+
layout.setSpacing(10)
|
| 1291 |
+
layout.addWidget(QLabel(f"日付: {d.month}月{d.day}日 ({dow}) {slot_label}"))
|
| 1292 |
+
|
| 1293 |
+
from PyQt6.QtWidgets import QSpinBox
|
| 1294 |
+
self._spin = QSpinBox()
|
| 1295 |
+
self._spin.setRange(0, 999)
|
| 1296 |
+
self._spin.setValue(current_count)
|
| 1297 |
+
self._spin.setFixedHeight(36)
|
| 1298 |
+
self._spin.setSuffix(" 名")
|
| 1299 |
+
layout.addWidget(self._spin)
|
| 1300 |
+
|
| 1301 |
+
hint = QLabel("0 で入力するとデータを消去します。設定した閾値を超えると増員が発生します。")
|
| 1302 |
+
hint.setStyleSheet("font-size:11px; color:#6b7280;")
|
| 1303 |
+
hint.setWordWrap(True)
|
| 1304 |
+
layout.addWidget(hint)
|
| 1305 |
+
|
| 1306 |
+
btn_row = QHBoxLayout()
|
| 1307 |
+
btn_cancel = QPushButton("キャンセル")
|
| 1308 |
+
btn_cancel.clicked.connect(self.reject)
|
| 1309 |
+
btn_ok = QPushButton("保存")
|
| 1310 |
+
btn_ok.setDefault(True)
|
| 1311 |
+
btn_ok.clicked.connect(self.accept)
|
| 1312 |
+
btn_row.addStretch()
|
| 1313 |
+
btn_row.addWidget(btn_cancel)
|
| 1314 |
+
btn_row.addWidget(btn_ok)
|
| 1315 |
+
layout.addLayout(btn_row)
|
| 1316 |
+
|
| 1317 |
+
@property
|
| 1318 |
+
def count(self) -> int:
|
| 1319 |
+
return self._spin.value()
|
| 1320 |
+
|
| 1321 |
+
|
| 1322 |
# ── ポジション選択ダイアログ ──────────────────────────────────────────────
|
| 1323 |
|
| 1324 |
class PositionSelectDialog(QDialog):
|
ui/settings_view.py
CHANGED
|
@@ -169,7 +169,77 @@ class SettingsView(QWidget):
|
|
| 169 |
constraint_layout.addWidget(self._btn_save_constraints)
|
| 170 |
layout.addWidget(constraint_group)
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
self._load_constraints()
|
|
|
|
| 173 |
|
| 174 |
self._apply_styles()
|
| 175 |
|
|
@@ -182,6 +252,27 @@ class SettingsView(QWidget):
|
|
| 182 |
mx_spin.setValue(c["max"])
|
| 183 |
ldr_spin.setValue(c["min_leader"])
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
def _on_save_constraints(self):
|
| 186 |
from db import repositories as repo
|
| 187 |
constraints = {}
|
|
@@ -207,6 +298,11 @@ class SettingsView(QWidget):
|
|
| 207 |
|
| 208 |
def _apply_styles(self):
|
| 209 |
c = theme.c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
self._btn_save_constraints.setStyleSheet(
|
| 211 |
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 212 |
f"border-radius:6px; padding:0 16px; color:{c['text']}; }}"
|
|
|
|
| 169 |
constraint_layout.addWidget(self._btn_save_constraints)
|
| 170 |
layout.addWidget(constraint_group)
|
| 171 |
|
| 172 |
+
# ── 予約客数設定 ──────────────────────────────────────────────────
|
| 173 |
+
reserv_group = QGroupBox("予約客数による増員設定")
|
| 174 |
+
reserv_layout = QVBoxLayout(reserv_group)
|
| 175 |
+
reserv_layout.setSpacing(8)
|
| 176 |
+
note_r = QLabel(
|
| 177 |
+
"1日の予約客数が閾値を超えた場合、その時間帯の最低スタッフ数を増員します。\n"
|
| 178 |
+
"予約客数はシフト表確認・編集画面の各タブで日毎に入力できます。"
|
| 179 |
+
)
|
| 180 |
+
note_r.setWordWrap(True)
|
| 181 |
+
reserv_layout.addWidget(note_r)
|
| 182 |
+
|
| 183 |
+
reserv_grid = QWidget()
|
| 184 |
+
reserv_form = QFormLayout(reserv_grid)
|
| 185 |
+
reserv_form.setSpacing(6)
|
| 186 |
+
|
| 187 |
+
self._reserv_spins: dict[str, QSpinBox] = {}
|
| 188 |
+
for key, label, default in [
|
| 189 |
+
("reserv_threshold_breakfast", "朝食: 予約が N 人以上で増員", 50),
|
| 190 |
+
("reserv_extra_breakfast", " 増員数(人)", 1),
|
| 191 |
+
("reserv_threshold_dinner", "ディナー: 予約が N 人以上で増員", 40),
|
| 192 |
+
("reserv_extra_dinner", " 増員数(人)", 1),
|
| 193 |
+
]:
|
| 194 |
+
sp = QSpinBox()
|
| 195 |
+
sp.setRange(0, 999)
|
| 196 |
+
sp.setFixedWidth(80)
|
| 197 |
+
sp.setValue(default)
|
| 198 |
+
sp.setMinimumHeight(28)
|
| 199 |
+
self._reserv_spins[key] = sp
|
| 200 |
+
reserv_form.addRow(label, sp)
|
| 201 |
+
|
| 202 |
+
reserv_layout.addWidget(reserv_grid)
|
| 203 |
+
|
| 204 |
+
# ── 朝食タイムテーブル制約 ────────────────────────────────────────
|
| 205 |
+
timetable_sep = QFrame()
|
| 206 |
+
timetable_sep.setFrameShape(QFrame.Shape.HLine)
|
| 207 |
+
reserv_layout.addWidget(timetable_sep)
|
| 208 |
+
|
| 209 |
+
timetable_note = QLabel(
|
| 210 |
+
"【朝食タイムテーブル】\n"
|
| 211 |
+
"5:45〜6:30 開店準備(開店準備対応可スタッフ 必須人数)\n"
|
| 212 |
+
"6:30〜10:00 朝食営業(上記の人員設定どおり)\n"
|
| 213 |
+
"10:00〜11:30 片付け・レイアウト準備(リーダー必須、最高2名・最低1名)"
|
| 214 |
+
)
|
| 215 |
+
timetable_note.setWordWrap(True)
|
| 216 |
+
timetable_note.setStyleSheet("font-size:11px;")
|
| 217 |
+
reserv_layout.addWidget(timetable_note)
|
| 218 |
+
|
| 219 |
+
open_row = QWidget()
|
| 220 |
+
open_form = QFormLayout(open_row)
|
| 221 |
+
open_form.setSpacing(6)
|
| 222 |
+
self._open_prep_spin = QSpinBox()
|
| 223 |
+
self._open_prep_spin.setRange(0, 10)
|
| 224 |
+
self._open_prep_spin.setFixedWidth(80)
|
| 225 |
+
self._open_prep_spin.setValue(2)
|
| 226 |
+
self._open_prep_spin.setMinimumHeight(28)
|
| 227 |
+
self._open_prep_spin.setToolTip(
|
| 228 |
+
"朝食開店準備(5:45〜)に必要な「開店準備対応可」スタッフの最低人数。\n"
|
| 229 |
+
"従業員管理で「朝食開店準備対応可」をチェックした従業員が対象です。"
|
| 230 |
+
)
|
| 231 |
+
open_form.addRow("開店準備 必要人数(人)", self._open_prep_spin)
|
| 232 |
+
reserv_layout.addWidget(open_row)
|
| 233 |
+
|
| 234 |
+
btn_save_reserv = QPushButton("予約・タイムテーブル設定を保存")
|
| 235 |
+
btn_save_reserv.setFixedHeight(36)
|
| 236 |
+
btn_save_reserv.clicked.connect(self._on_save_reserv_settings)
|
| 237 |
+
reserv_layout.addWidget(btn_save_reserv)
|
| 238 |
+
self._btn_save_reserv = btn_save_reserv
|
| 239 |
+
layout.addWidget(reserv_group)
|
| 240 |
+
|
| 241 |
self._load_constraints()
|
| 242 |
+
self._load_reserv_settings()
|
| 243 |
|
| 244 |
self._apply_styles()
|
| 245 |
|
|
|
|
| 252 |
mx_spin.setValue(c["max"])
|
| 253 |
ldr_spin.setValue(c["min_leader"])
|
| 254 |
|
| 255 |
+
def _load_reserv_settings(self):
|
| 256 |
+
from db import repositories as repo
|
| 257 |
+
settings = repo.get_all_app_settings()
|
| 258 |
+
defaults = {
|
| 259 |
+
"reserv_threshold_breakfast": "50",
|
| 260 |
+
"reserv_extra_breakfast": "1",
|
| 261 |
+
"reserv_threshold_dinner": "40",
|
| 262 |
+
"reserv_extra_dinner": "1",
|
| 263 |
+
"open_prep_required": "2",
|
| 264 |
+
}
|
| 265 |
+
for key, sp in self._reserv_spins.items():
|
| 266 |
+
sp.setValue(int(settings.get(key, defaults.get(key, "0"))))
|
| 267 |
+
self._open_prep_spin.setValue(int(settings.get("open_prep_required", "2")))
|
| 268 |
+
|
| 269 |
+
def _on_save_reserv_settings(self):
|
| 270 |
+
from db import repositories as repo
|
| 271 |
+
settings = {key: str(sp.value()) for key, sp in self._reserv_spins.items()}
|
| 272 |
+
settings["open_prep_required"] = str(self._open_prep_spin.value())
|
| 273 |
+
repo.save_all_app_settings(settings)
|
| 274 |
+
QMessageBox.information(self, "保存完了", "予約・タイムテーブル設定を保存しました。")
|
| 275 |
+
|
| 276 |
def _on_save_constraints(self):
|
| 277 |
from db import repositories as repo
|
| 278 |
constraints = {}
|
|
|
|
| 298 |
|
| 299 |
def _apply_styles(self):
|
| 300 |
c = theme.c
|
| 301 |
+
self._btn_save_reserv.setStyleSheet(
|
| 302 |
+
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 303 |
+
f"border-radius:6px; padding:0 16px; color:{c['text']}; }}"
|
| 304 |
+
f" QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 305 |
+
)
|
| 306 |
self._btn_save_constraints.setStyleSheet(
|
| 307 |
f"QPushButton {{ background:{c['surface']}; border:1px solid {c['border2']}; "
|
| 308 |
f"border-radius:6px; padding:0 16px; color:{c['text']}; }}"
|