Commit ·
3631ef5
1
Parent(s): eac2541
feat: アルバイトの社会保険加入フラグを追加、シフト生成で優先配置
Browse files- employees に has_social_insurance カラムを追加
- スタッフ管理画面(PT のみ)に「社会保険に加入している」チェックボックスを追加
- ソルバーに P3c を追加:未加入 PT にペナルティ(300)を与え、加入済み PT を優先配置
(P1 人件費 > P3c 社保優先 > P3 希望充当の順で機能)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- db/database.py +1 -0
- db/repositories.py +9 -5
- models/employee.py +1 -0
- optimizer/solver.py +22 -0
- routes/employees.py +1 -0
- templates/employees/form.html +25 -11
db/database.py
CHANGED
|
@@ -272,6 +272,7 @@ _MIGRATIONS = [
|
|
| 272 |
("schedule_periods", "needs_regen", "INTEGER NOT NULL DEFAULT 0"),
|
| 273 |
("employees", "output_position", "TEXT"),
|
| 274 |
("employees", "hourly_wage", "INTEGER NOT NULL DEFAULT 0"),
|
|
|
|
| 275 |
]
|
| 276 |
|
| 277 |
_INDEXES = [
|
|
|
|
| 272 |
("schedule_periods", "needs_regen", "INTEGER NOT NULL DEFAULT 0"),
|
| 273 |
("employees", "output_position", "TEXT"),
|
| 274 |
("employees", "hourly_wage", "INTEGER NOT NULL DEFAULT 0"),
|
| 275 |
+
("employees", "has_social_insurance", "INTEGER NOT NULL DEFAULT 0"),
|
| 276 |
]
|
| 277 |
|
| 278 |
_INDEXES = [
|
db/repositories.py
CHANGED
|
@@ -67,18 +67,19 @@ def save_employee(emp: Employee) -> Employee:
|
|
| 67 |
cln = int(emp.can_cleanup)
|
| 68 |
avail_b = int(emp.always_available_breakfast)
|
| 69 |
avail_d = int(emp.always_available_dinner)
|
|
|
|
| 70 |
if emp.id is None:
|
| 71 |
# 末尾に追加されるよう MAX(display_order)+1 をセット
|
| 72 |
row = conn.execute("SELECT COALESCE(MAX(display_order), -1) AS max_order FROM employees").fetchone()
|
| 73 |
next_order = (row["max_order"] if row else -1) + 1
|
| 74 |
emp.id = conn.execute_insert(
|
| 75 |
-
"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, hourly_wage, is_active, display_order) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 76 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, 1, next_order)
|
| 77 |
)
|
| 78 |
else:
|
| 79 |
conn.execute(
|
| 80 |
-
"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=?, hourly_wage=?, is_active=? WHERE id=?",
|
| 81 |
-
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, int(emp.is_active), emp.id)
|
| 82 |
)
|
| 83 |
_save_fixed_patterns(conn, emp)
|
| 84 |
_save_fixed_unavailable_dates(conn, emp)
|
|
@@ -167,6 +168,7 @@ def _row_to_employee_preloaded(row, pat_map: dict, unavail_map: dict) -> Employe
|
|
| 167 |
always_available_breakfast=bool(row["always_available_breakfast"]) if "always_available_breakfast" in keys else False,
|
| 168 |
always_available_dinner=bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False,
|
| 169 |
hourly_wage=int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0,
|
|
|
|
| 170 |
is_active=bool(row["is_active"]),
|
| 171 |
fixed_patterns=[
|
| 172 |
FixedPattern(p["day_of_week"], bool(p["breakfast"]), bool(p["dinner"]))
|
|
@@ -194,7 +196,8 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 194 |
cleanup_val = bool(row["can_cleanup"]) if "can_cleanup" in keys else False
|
| 195 |
avail_b_val = bool(row["always_available_breakfast"]) if "always_available_breakfast" in keys else False
|
| 196 |
avail_d_val = bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False
|
| 197 |
-
wage_val
|
|
|
|
| 198 |
return Employee(
|
| 199 |
id=row["id"],
|
| 200 |
name=row["name"],
|
|
@@ -209,6 +212,7 @@ def _row_to_employee(row, conn) -> Employee:
|
|
| 209 |
always_available_breakfast=avail_b_val,
|
| 210 |
always_available_dinner=avail_d_val,
|
| 211 |
hourly_wage=wage_val,
|
|
|
|
| 212 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 213 |
is_active=bool(row["is_active"]),
|
| 214 |
fixed_patterns=[
|
|
|
|
| 67 |
cln = int(emp.can_cleanup)
|
| 68 |
avail_b = int(emp.always_available_breakfast)
|
| 69 |
avail_d = int(emp.always_available_dinner)
|
| 70 |
+
si = int(emp.has_social_insurance)
|
| 71 |
if emp.id is None:
|
| 72 |
# 末尾に追加されるよう MAX(display_order)+1 をセット
|
| 73 |
row = conn.execute("SELECT COALESCE(MAX(display_order), -1) AS max_order FROM employees").fetchone()
|
| 74 |
next_order = (row["max_order"] if row else -1) + 1
|
| 75 |
emp.id = conn.execute_insert(
|
| 76 |
+
"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, hourly_wage, has_social_insurance, is_active, display_order) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 77 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, 1, next_order)
|
| 78 |
)
|
| 79 |
else:
|
| 80 |
conn.execute(
|
| 81 |
+
"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=?, hourly_wage=?, has_social_insurance=?, is_active=? WHERE id=?",
|
| 82 |
+
(emp.name, emp.employment_type.value, emp.hall_skill.value, emp.kitchen_skill.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, int(emp.is_active), emp.id)
|
| 83 |
)
|
| 84 |
_save_fixed_patterns(conn, emp)
|
| 85 |
_save_fixed_unavailable_dates(conn, emp)
|
|
|
|
| 168 |
always_available_breakfast=bool(row["always_available_breakfast"]) if "always_available_breakfast" in keys else False,
|
| 169 |
always_available_dinner=bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False,
|
| 170 |
hourly_wage=int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0,
|
| 171 |
+
has_social_insurance=bool(row["has_social_insurance"]) if "has_social_insurance" in keys else False,
|
| 172 |
is_active=bool(row["is_active"]),
|
| 173 |
fixed_patterns=[
|
| 174 |
FixedPattern(p["day_of_week"], bool(p["breakfast"]), bool(p["dinner"]))
|
|
|
|
| 196 |
cleanup_val = bool(row["can_cleanup"]) if "can_cleanup" in keys else False
|
| 197 |
avail_b_val = bool(row["always_available_breakfast"]) if "always_available_breakfast" in keys else False
|
| 198 |
avail_d_val = bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False
|
| 199 |
+
wage_val = int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0
|
| 200 |
+
si_val = bool(row["has_social_insurance"]) if "has_social_insurance" in keys else False
|
| 201 |
return Employee(
|
| 202 |
id=row["id"],
|
| 203 |
name=row["name"],
|
|
|
|
| 212 |
always_available_breakfast=avail_b_val,
|
| 213 |
always_available_dinner=avail_d_val,
|
| 214 |
hourly_wage=wage_val,
|
| 215 |
+
has_social_insurance=si_val,
|
| 216 |
primary_timeslot=TimeSlot(pt_val) if pt_val else None,
|
| 217 |
is_active=bool(row["is_active"]),
|
| 218 |
fixed_patterns=[
|
models/employee.py
CHANGED
|
@@ -26,6 +26,7 @@ class Employee:
|
|
| 26 |
always_available_dinner: bool = False # True = ディナーに希望提出不要・毎日出勤可
|
| 27 |
primary_timeslot: Optional[TimeSlot] = None # None = どちらでも可
|
| 28 |
hourly_wage: int = 0
|
|
|
|
| 29 |
fixed_patterns: list[FixedPattern] = field(default_factory=list)
|
| 30 |
fixed_unavailable_dates: list[str] = field(default_factory=list) # YYYY-MM-DD
|
| 31 |
is_active: bool = True
|
|
|
|
| 26 |
always_available_dinner: bool = False # True = ディナーに希望提出不要・毎日出勤可
|
| 27 |
primary_timeslot: Optional[TimeSlot] = None # None = どちらでも可
|
| 28 |
hourly_wage: int = 0
|
| 29 |
+
has_social_insurance: bool = False
|
| 30 |
fixed_patterns: list[FixedPattern] = field(default_factory=list)
|
| 31 |
fixed_unavailable_dates: list[str] = field(default_factory=list) # YYYY-MM-DD
|
| 32 |
is_active: bool = True
|
optimizer/solver.py
CHANGED
|
@@ -470,6 +470,19 @@ def solve(
|
|
| 470 |
|
| 471 |
# P3b: primary_timeslot 専任制約は P5 のハード制約でカバー済みのため削除(FIX⑦)
|
| 472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
# P4: 人員バランス = ポジション毎の総シフト数の偏差を最小化
|
| 474 |
# 各日の各(スロット×ポジション)の担当人数を均等にするため、
|
| 475 |
# 1日の担当数の最大・最小差をペナルティに
|
|
@@ -832,6 +845,15 @@ def _solve_best_effort(
|
|
| 832 |
model.add(worked >= 1).only_enforce_if(not_worked.negated())
|
| 833 |
penalty_terms.append(PT_PENALTY * not_worked)
|
| 834 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 835 |
# FIX⑥: ベストエフォートにも P5 スロット分業のソフト誘導を追加
|
| 836 |
BE_BREAKFAST_FT_COST = 500_000
|
| 837 |
BE_DINNER_PT_COST = 300_000
|
|
|
|
| 470 |
|
| 471 |
# P3b: primary_timeslot 専任制約は P5 のハード制約でカバー済みのため削除(FIX⑦)
|
| 472 |
|
| 473 |
+
# P3c: 社会保険加入アルバイト優先配置
|
| 474 |
+
# 未加入PTが割り当てられたときにペナルティを与え、加入済みPTを優先する
|
| 475 |
+
SI_PREF_PENALTY = 300
|
| 476 |
+
for emp in active_employees:
|
| 477 |
+
if emp.employment_type == EmploymentType.FULL_TIME:
|
| 478 |
+
continue
|
| 479 |
+
if emp.has_social_insurance:
|
| 480 |
+
continue # 加入済みはペナルティなし
|
| 481 |
+
for ds in date_strs:
|
| 482 |
+
for slot in slots:
|
| 483 |
+
for pos in positions:
|
| 484 |
+
penalty_terms.append(SI_PREF_PENALTY * assign[emp.id][ds][slot.value][pos.value])
|
| 485 |
+
|
| 486 |
# P4: 人員バランス = ポジション毎の総シフト数の偏差を最小化
|
| 487 |
# 各日の各(スロット×ポジション)の担当人数を均等にするため、
|
| 488 |
# 1日の担当数の最大・最小差をペナルティに
|
|
|
|
| 845 |
model.add(worked >= 1).only_enforce_if(not_worked.negated())
|
| 846 |
penalty_terms.append(PT_PENALTY * not_worked)
|
| 847 |
|
| 848 |
+
# 社会保険加入アルバイト優先(ベストエフォートフェーズでも同様)
|
| 849 |
+
for emp in active_employees:
|
| 850 |
+
if emp.employment_type == EmploymentType.FULL_TIME or emp.has_social_insurance:
|
| 851 |
+
continue
|
| 852 |
+
for ds in date_strs:
|
| 853 |
+
for slot in slots:
|
| 854 |
+
for pos in positions:
|
| 855 |
+
penalty_terms.append(300 * assign[emp.id][ds][slot.value][pos.value])
|
| 856 |
+
|
| 857 |
# FIX⑥: ベストエフォートにも P5 スロット分業のソフト誘導を追加
|
| 858 |
BE_BREAKFAST_FT_COST = 500_000
|
| 859 |
BE_DINNER_PT_COST = 300_000
|
routes/employees.py
CHANGED
|
@@ -124,6 +124,7 @@ def _form_to_employee(emp_id):
|
|
| 124 |
name=f["name"].strip(),
|
| 125 |
employment_type=EmploymentType(f["employment_type"]),
|
| 126 |
hourly_wage=int(f.get("hourly_wage") or 0),
|
|
|
|
| 127 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 128 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 129 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
|
|
|
| 124 |
name=f["name"].strip(),
|
| 125 |
employment_type=EmploymentType(f["employment_type"]),
|
| 126 |
hourly_wage=int(f.get("hourly_wage") or 0),
|
| 127 |
+
has_social_insurance=bool(f.get("has_social_insurance")),
|
| 128 |
hall_skill=SkillLevel(f.get("hall_skill") or "novice"),
|
| 129 |
kitchen_skill=SkillLevel(f.get("kitchen_skill") or "novice"),
|
| 130 |
primary_position=PrimaryPosition(pp_val) if pp_val else None,
|
templates/employees/form.html
CHANGED
|
@@ -53,17 +53,31 @@
|
|
| 53 |
</div>
|
| 54 |
|
| 55 |
{% if emp and emp.employment_type.value == 'part_time' or not emp %}
|
| 56 |
-
<div
|
| 57 |
-
<
|
| 58 |
-
<
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
<
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
</div>
|
| 68 |
</div>
|
| 69 |
{% endif %}
|
|
|
|
| 53 |
</div>
|
| 54 |
|
| 55 |
{% if emp and emp.employment_type.value == 'part_time' or not emp %}
|
| 56 |
+
<div id="pt-only-fields">
|
| 57 |
+
<div class="mb-3">
|
| 58 |
+
<label class="form-label fw-semibold">個人昇給額
|
| 59 |
+
<span class="text-muted fw-normal small">(基本給への上乗せ額)</span>
|
| 60 |
+
</label>
|
| 61 |
+
<div class="input-group" style="max-width:180px">
|
| 62 |
+
<span class="input-group-text">+</span>
|
| 63 |
+
<input type="number" name="hourly_wage" class="form-control"
|
| 64 |
+
min="0" max="9999" step="1"
|
| 65 |
+
value="{{ emp.hourly_wage if emp else 0 }}"
|
| 66 |
+
placeholder="0">
|
| 67 |
+
<span class="input-group-text">円/時</span>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
<div class="mb-3">
|
| 71 |
+
<label class="form-label fw-semibold">社会保険</label>
|
| 72 |
+
<div class="form-check">
|
| 73 |
+
<input class="form-check-input" type="checkbox" name="has_social_insurance"
|
| 74 |
+
id="has_si" value="1"
|
| 75 |
+
{{ 'checked' if emp and emp.has_social_insurance else '' }}>
|
| 76 |
+
<label class="form-check-label small" for="has_si">
|
| 77 |
+
社会保険に加入している
|
| 78 |
+
<span class="text-muted fw-normal">(シフト生成時に優先配置)</span>
|
| 79 |
+
</label>
|
| 80 |
+
</div>
|
| 81 |
</div>
|
| 82 |
</div>
|
| 83 |
{% endif %}
|