76 lines
3.1 KiB
Python
76 lines
3.1 KiB
Python
"""Organization master data: departments, positions, job levels, dictionaries."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import JSON, Boolean, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from ..db.base import Base, PKMixin, TimestampMixin
|
|
|
|
|
|
class Department(PKMixin, TimestampMixin, Base):
|
|
"""Company hierarchy. ``parent_id = 0`` means root."""
|
|
|
|
__tablename__ = "org_department"
|
|
|
|
name: Mapped[str] = mapped_column(String(64))
|
|
code: Mapped[str | None] = mapped_column(String(32), unique=True)
|
|
parent_id: Mapped[int] = mapped_column(Integer, default=0, index=True)
|
|
dep_path: Mapped[str | None] = mapped_column(String(512))
|
|
level: Mapped[int] = mapped_column(Integer, default=1)
|
|
is_parent: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
leader_employee_id: Mapped[int | None] = mapped_column(Integer)
|
|
cost_center: Mapped[str | None] = mapped_column(String(64))
|
|
sort: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
remark: Mapped[str | None] = mapped_column(String(255))
|
|
|
|
|
|
class Position(PKMixin, TimestampMixin, Base):
|
|
__tablename__ = "org_position"
|
|
|
|
name: Mapped[str] = mapped_column(String(64), unique=True)
|
|
code: Mapped[str | None] = mapped_column(String(32), unique=True)
|
|
category: Mapped[str | None] = mapped_column(String(32))
|
|
sort: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
remark: Mapped[str | None] = mapped_column(String(255))
|
|
|
|
|
|
class JobLevel(PKMixin, TimestampMixin, Base):
|
|
__tablename__ = "org_job_level"
|
|
|
|
name: Mapped[str] = mapped_column(String(64), unique=True)
|
|
code: Mapped[str | None] = mapped_column(String(32), unique=True)
|
|
grade: Mapped[int] = mapped_column(Integer, default=1)
|
|
sort: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
# 每个职级可配置多个报销项目,例如交通、住宿、通讯、餐费。
|
|
# 以 JSON 数组保存项目明细,避免为数量不固定的项目创建多张关联表。
|
|
expense_standards: Mapped[list[dict] | None] = mapped_column(JSON)
|
|
remark: Mapped[str | None] = mapped_column(String(255))
|
|
|
|
@property
|
|
def expense_standard_count(self) -> int:
|
|
return len(self.expense_standards or [])
|
|
|
|
|
|
class DictType(PKMixin, Base):
|
|
__tablename__ = "org_dict_type"
|
|
|
|
code: Mapped[str] = mapped_column(String(64), unique=True)
|
|
name: Mapped[str] = mapped_column(String(64))
|
|
builtin: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
remark: Mapped[str | None] = mapped_column(String(255))
|
|
|
|
|
|
class DictItem(PKMixin, Base):
|
|
__tablename__ = "org_dict_item"
|
|
|
|
type_code: Mapped[str] = mapped_column(String(64), index=True)
|
|
label: Mapped[str] = mapped_column(String(64))
|
|
value: Mapped[str] = mapped_column(String(64))
|
|
extra: Mapped[str | None] = mapped_column(Text)
|
|
sort: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|