Initial commit

This commit is contained in:
汤学会
2026-06-12 16:00:56 +08:00
commit c927886888
337 changed files with 160396 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
from app.models.master_data import Bom, BomItem, Item, Material, Product, StockBalance, Warehouse
from app.models.document_archive import DocumentArchive
from app.models.org import Department, Employee, Permission, Role, RolePermission, User, UserRole
from app.models.planning import MaterialDemand
from app.models.sales import Customer, SalesOrder, SalesOrderItem
__all__ = [
"Customer",
"Department",
"DocumentArchive",
"Employee",
"Bom",
"BomItem",
"Item",
"Material",
"MaterialDemand",
"Permission",
"Product",
"Role",
"RolePermission",
"SalesOrder",
"SalesOrderItem",
"StockBalance",
"User",
"UserRole",
"Warehouse",
]
+27
View File
@@ -0,0 +1,27 @@
from __future__ import annotations
from datetime import datetime
from sqlalchemy import event
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
@event.listens_for(Base, "before_insert", propagate=True)
def set_audit_fields_before_insert(mapper, connection, target) -> None:
_ = mapper, connection
now = datetime.now()
if hasattr(target, "created_at") and getattr(target, "created_at", None) is None:
setattr(target, "created_at", now)
if hasattr(target, "updated_at") and getattr(target, "updated_at", None) is None:
setattr(target, "updated_at", now)
@event.listens_for(Base, "before_update", propagate=True)
def set_audit_fields_before_update(mapper, connection, target) -> None:
_ = mapper, connection
if hasattr(target, "updated_at"):
setattr(target, "updated_at", datetime.now())
+40
View File
@@ -0,0 +1,40 @@
from __future__ import annotations
from datetime import datetime
from sqlalchemy import BigInteger, DateTime, Index, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class DocumentArchive(Base):
__tablename__ = "document_archives"
__table_args__ = (
UniqueConstraint(
"document_type",
"business_id",
"archive_version",
"file_format",
name="uk_document_archives_version",
),
Index("idx_document_archives_business_latest", "document_type", "business_id", "archive_version"),
Index("idx_document_archives_document_no", "document_no"),
Index("idx_document_archives_status", "status", "created_at"),
)
id: Mapped[int] = mapped_column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True, autoincrement=True)
document_type: Mapped[str] = mapped_column(String(50))
business_id: Mapped[int] = mapped_column(BigInteger)
document_no: Mapped[str] = mapped_column(String(100))
archive_version: Mapped[int] = mapped_column(Integer)
template_version: Mapped[str] = mapped_column(String(50))
file_format: Mapped[str] = mapped_column(String(20))
file_name: Mapped[str] = mapped_column(String(255))
file_path: Mapped[str] = mapped_column(String(500))
file_hash: Mapped[str | None] = mapped_column(String(128), nullable=True)
status: Mapped[str] = mapped_column(String(32))
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
created_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime)
updated_at: Mapped[datetime] = mapped_column(DateTime)
+135
View File
@@ -0,0 +1,135 @@
from __future__ import annotations
from sqlalchemy import BigInteger, Date, DateTime, DECIMAL, ForeignKey, Integer, String, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class Unit(Base):
__tablename__ = "md_unit"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
unit_code: Mapped[str] = mapped_column(String(50))
unit_name: Mapped[str] = mapped_column(String(50))
precision_digits: Mapped[int] = mapped_column(Integer, server_default=text("3"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Item(Base):
__tablename__ = "md_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
item_code: Mapped[str] = mapped_column(String(50))
item_name: Mapped[str] = mapped_column(String(200))
item_type: Mapped[str] = mapped_column(String(32))
specification: Mapped[str | None] = mapped_column(String(200), nullable=True)
material_grade: Mapped[str | None] = mapped_column(String(100), nullable=True)
unit_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
sales_unit_id: Mapped[int | None] = mapped_column(ForeignKey("md_unit.id"), nullable=True)
stock_unit_id: Mapped[int | None] = mapped_column(ForeignKey("md_unit.id"), nullable=True)
purchase_unit_id: Mapped[int | None] = mapped_column(ForeignKey("md_unit.id"), nullable=True)
safety_stock_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_sale_price: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Material(Base):
__tablename__ = "md_material"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
default_supplier_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
purchase_calc_mode: Mapped[str] = mapped_column(String(32))
min_purchase_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
purchase_multiple_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
purchase_multiple_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
lead_time_days: Mapped[int] = mapped_column(server_default=text("0"))
quality_rule: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Product(Base):
__tablename__ = "md_product"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
drawing_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
product_family: Mapped[str | None] = mapped_column(String(100), nullable=True)
version_no: Mapped[str] = mapped_column(String(50))
standard_output_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
allowed_scrap_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
quality_standard: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Warehouse(Base):
__tablename__ = "wh_warehouse"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
warehouse_code: Mapped[str] = mapped_column(String(50))
warehouse_name: Mapped[str] = mapped_column(String(100))
warehouse_type: Mapped[str] = mapped_column(String(32))
manager_employee_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Bom(Base):
__tablename__ = "md_bom"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
bom_code: Mapped[str] = mapped_column(String(50))
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
version_no: Mapped[str] = mapped_column(String(50))
is_default: Mapped[int] = mapped_column(Integer)
status: Mapped[str] = mapped_column(String(32))
effective_date: Mapped[object | None] = mapped_column(Date, nullable=True)
expire_date: Mapped[object | None] = mapped_column(Date, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class BomItem(Base):
__tablename__ = "md_bom_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
bom_id: Mapped[int] = mapped_column(ForeignKey("md_bom.id"))
seq_no: Mapped[int] = mapped_column(Integer)
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
usage_type: Mapped[str] = mapped_column(String(32))
qty_per_piece: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
net_weight_per_piece_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
gross_weight_per_piece_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
loss_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
issue_over_tolerance_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class StockBalance(Base):
__tablename__ = "wh_stock_balance"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
location_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
qty_on_hand: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_on_hand_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
qty_available: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_available_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
qty_allocated: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_allocated_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
avg_unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
+143
View File
@@ -0,0 +1,143 @@
from __future__ import annotations
from sqlalchemy import BigInteger, Boolean, Date, DateTime, DECIMAL, ForeignKey, Integer, String, Text, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class MiniAppAttendancePoint(Base):
__tablename__ = "attendance_points"
name: Mapped[str] = mapped_column(String(128), primary_key=True)
latitude: Mapped[float | None] = mapped_column(DECIMAL(10, 7), nullable=True)
longitude: Mapped[float | None] = mapped_column(DECIMAL(10, 7), nullable=True)
radius_meters: Mapped[int] = mapped_column(Integer, server_default=text("500"))
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
is_active: Mapped[bool] = mapped_column(Boolean, server_default=text("1"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MiniAppPersonnel(Base):
__tablename__ = "personnel"
phone: Mapped[str] = mapped_column(String(20), primary_key=True)
name: Mapped[str] = mapped_column(String(64))
is_temporary: Mapped[bool] = mapped_column(Boolean, server_default=text("0"))
temporary_expires_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MiniAppPersonRole(Base):
__tablename__ = "person_roles"
phone: Mapped[str] = mapped_column(ForeignKey("personnel.phone"), primary_key=True)
role: Mapped[str] = mapped_column(String(32), primary_key=True)
created_at: Mapped[object] = mapped_column(DateTime)
class MiniAppPersonAttendancePoint(Base):
__tablename__ = "person_attendance_points"
phone: Mapped[str] = mapped_column(ForeignKey("personnel.phone"), primary_key=True)
attendance_point_name: Mapped[str] = mapped_column(ForeignKey("attendance_points.name"), primary_key=True)
created_at: Mapped[object] = mapped_column(DateTime)
class MiniAppProduct(Base):
__tablename__ = "products"
attendance_point_name: Mapped[str] = mapped_column(String(128), primary_key=True, server_default=text("'宁波嘉恒智能科技有限公司'"))
project_no: Mapped[str] = mapped_column(String(64), primary_key=True)
product_name: Mapped[str] = mapped_column(String(255), primary_key=True)
device_no: Mapped[str] = mapped_column(String(64), primary_key=True)
process_name: Mapped[str] = mapped_column(String(128), primary_key=True)
profile_no: Mapped[str | None] = mapped_column(String(128), nullable=True)
material_code: Mapped[str | None] = mapped_column(String(128), nullable=True)
material_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
supplier: Mapped[str | None] = mapped_column(String(255), nullable=True)
product_net_weight_kg: Mapped[float | None] = mapped_column(DECIMAL(12, 4), nullable=True)
product_gross_weight_kg: Mapped[float | None] = mapped_column(DECIMAL(12, 4), nullable=True)
scrap_loss_rate: Mapped[float | None] = mapped_column(DECIMAL(10, 6), nullable=True)
waste_price_yuan_per_kg: Mapped[float | None] = mapped_column(DECIMAL(12, 4), nullable=True)
stamping_method: Mapped[str | None] = mapped_column(String(128), nullable=True)
operator_count: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("1"))
standard_beat: Mapped[float] = mapped_column(DECIMAL(12, 3), server_default=text("0"))
standard_workload: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MiniAppProductionReport(Base):
__tablename__ = "production_reports"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
attendance_point_name: Mapped[str] = mapped_column(String(128), server_default=text("'宁波嘉恒智能科技有限公司'"))
session_id: Mapped[int] = mapped_column(BigInteger)
employee_phone: Mapped[str] = mapped_column(ForeignKey("personnel.phone"))
report_date: Mapped[object] = mapped_column(Date)
start_at: Mapped[object] = mapped_column(DateTime)
end_at: Mapped[object] = mapped_column(DateTime)
duration_minutes: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
break_minutes: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
effective_minutes: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
total_good_qty: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
total_output_qty: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
actual_beat: Mapped[float] = mapped_column(DECIMAL(12, 3), server_default=text("0"))
standard_beat: Mapped[float] = mapped_column(DECIMAL(12, 3), server_default=text("0"))
expected_workload: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
pace_rate: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
workload_rate: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32), server_default=text("'pending'"))
reviewer_phone: Mapped[str | None] = mapped_column(String(20), nullable=True)
reviewed_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
reject_reason: Mapped[str | None] = mapped_column(String(500), nullable=True)
submitted_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MiniAppProductionReportItem(Base):
__tablename__ = "production_report_items"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
report_id: Mapped[int] = mapped_column(ForeignKey("production_reports.id"))
attendance_point_name: Mapped[str] = mapped_column(String(128), server_default=text("'宁波嘉恒智能科技有限公司'"))
device_no: Mapped[str] = mapped_column(String(64))
project_no: Mapped[str] = mapped_column(String(64))
product_name: Mapped[str] = mapped_column(String(255))
material_code: Mapped[str | None] = mapped_column(String(128), nullable=True)
material_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
raw_material_batch_no: Mapped[str | None] = mapped_column(String(128), nullable=True)
process_name: Mapped[str | None] = mapped_column(String(128), nullable=True)
stamping_method: Mapped[str | None] = mapped_column(String(128), nullable=True)
standard_beat: Mapped[float] = mapped_column(DECIMAL(12, 3), server_default=text("0"))
standard_workload: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
good_qty: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
defect_qty: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
scrap_qty: Mapped[float] = mapped_column(DECIMAL(12, 2), server_default=text("0"))
allocated_minutes: Mapped[float] = mapped_column(DECIMAL(10, 2), server_default=text("0"))
started_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
class MiniAppNotice(Base):
__tablename__ = "notices"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
title: Mapped[str] = mapped_column(String(120))
content: Mapped[str] = mapped_column(Text)
sort_order: Mapped[int] = mapped_column(Integer, server_default=text("0"))
is_active: Mapped[bool] = mapped_column(Boolean, server_default=text("1"))
created_by: Mapped[str] = mapped_column(ForeignKey("personnel.phone"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MiniAppNoticePoint(Base):
__tablename__ = "notice_points"
notice_id: Mapped[int] = mapped_column(ForeignKey("notices.id"), primary_key=True)
attendance_point_name: Mapped[str] = mapped_column(ForeignKey("attendance_points.name"), primary_key=True)
created_at: Mapped[object] = mapped_column(DateTime)
+875
View File
@@ -0,0 +1,875 @@
from __future__ import annotations
from sqlalchemy import JSON, BigInteger, Date, DateTime, DECIMAL, ForeignKey, Integer, String, UniqueConstraint, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class Supplier(Base):
__tablename__ = "md_supplier"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
supplier_code: Mapped[str] = mapped_column(String(50))
supplier_name: Mapped[str] = mapped_column(String(200))
short_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
contact_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
contact_phone: Mapped[str | None] = mapped_column(String(50), nullable=True)
address: Mapped[str | None] = mapped_column(String(255), nullable=True)
lead_time_days: Mapped[int] = mapped_column(Integer, server_default=text("0"))
default_tax_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Process(Base):
__tablename__ = "md_process"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
process_code: Mapped[str] = mapped_column(String(50))
process_name: Mapped[str] = mapped_column(String(100))
process_type: Mapped[str] = mapped_column(String(32))
is_report_required: Mapped[int] = mapped_column(Integer, server_default=text("1"))
is_quality_gate: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class WorkCenter(Base):
__tablename__ = "md_work_center"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
center_code: Mapped[str] = mapped_column(String(50))
center_name: Mapped[str] = mapped_column(String(100))
dept_id: Mapped[int] = mapped_column(ForeignKey("sys_department.id"))
center_type: Mapped[str] = mapped_column(String(50))
shift_pattern: Mapped[str | None] = mapped_column(String(50), nullable=True)
capacity_hours_per_day: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ProcessRoute(Base):
__tablename__ = "md_process_route"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
route_code: Mapped[str] = mapped_column(String(50))
route_name: Mapped[str] = mapped_column(String(100))
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
version_no: Mapped[str] = mapped_column(String(50))
is_default: Mapped[int] = mapped_column(Integer, server_default=text("1"))
status: Mapped[str] = mapped_column(String(32))
effective_date: Mapped[object | None] = mapped_column(Date, nullable=True)
expire_date: Mapped[object | None] = mapped_column(Date, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ProcessRouteOperation(Base):
__tablename__ = "md_process_route_operation"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
route_id: Mapped[int] = mapped_column(ForeignKey("md_process_route.id"))
seq_no: Mapped[int] = mapped_column(Integer)
process_id: Mapped[int] = mapped_column(BigInteger)
work_center_id: Mapped[int] = mapped_column(ForeignKey("md_work_center.id"))
operation_name: Mapped[str] = mapped_column(String(100))
std_setup_minutes: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
std_cycle_seconds: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
std_labor_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
std_machine_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
std_outsource_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
allowed_scrap_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
report_required: Mapped[int] = mapped_column(Integer, server_default=text("1"))
is_key_operation: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Equipment(Base):
__tablename__ = "em_equipment"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
equipment_code: Mapped[str] = mapped_column(String(50))
equipment_name: Mapped[str] = mapped_column(String(100))
category_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
work_center_id: Mapped[int] = mapped_column(ForeignKey("md_work_center.id"))
manufacturer: Mapped[str | None] = mapped_column(String(100), nullable=True)
model_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
install_date: Mapped[object | None] = mapped_column(Date, nullable=True)
rated_power_kw: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
occupied_area_sqm: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
maintenance_cycle_hours: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
last_maintenance_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
next_maintenance_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MaintenancePlan(Base):
__tablename__ = "em_maintenance_plan"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
plan_code: Mapped[str] = mapped_column(String(50))
equipment_id: Mapped[int] = mapped_column(ForeignKey("em_equipment.id"))
plan_name: Mapped[str] = mapped_column(String(100))
maintenance_type: Mapped[str] = mapped_column(String(32))
cycle_hours: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
cycle_days: Mapped[int] = mapped_column(Integer, server_default=text("0"))
last_execute_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
next_execute_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class MaintenanceOrder(Base):
__tablename__ = "em_maintenance_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
order_no: Mapped[str] = mapped_column(String(50))
equipment_id: Mapped[int] = mapped_column(ForeignKey("em_equipment.id"))
plan_id: Mapped[int | None] = mapped_column(ForeignKey("em_maintenance_plan.id"), nullable=True)
maintenance_type: Mapped[str] = mapped_column(String(32))
start_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
end_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
downtime_minutes: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
owner_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
result_summary: Mapped[str | None] = mapped_column(String(255), nullable=True)
cost_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseOrder(Base):
__tablename__ = "po_purchase_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
po_no: Mapped[str] = mapped_column(String(50))
supplier_id: Mapped[int] = mapped_column(ForeignKey("md_supplier.id"))
order_date: Mapped[object] = mapped_column(Date)
expected_date: Mapped[object | None] = mapped_column(Date, nullable=True)
warning_lead_days: Mapped[int] = mapped_column(Integer, server_default=text("0"))
purchaser_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
target_warehouse_type: Mapped[str] = mapped_column(String(32), server_default=text("'RAW'"))
tax_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
total_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseOrderSalesOrderLink(Base):
__tablename__ = "po_purchase_order_sales_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
purchase_order_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order.id"))
sales_order_id: Mapped[int] = mapped_column(ForeignKey("so_sales_order.id"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseOrderItem(Base):
__tablename__ = "po_purchase_order_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
purchase_order_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order.id"))
line_no: Mapped[int] = mapped_column(Integer)
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
source_demand_id: Mapped[int | None] = mapped_column(ForeignKey("mrp_material_demand.id"), nullable=True)
order_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
order_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
received_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
received_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_price: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
line_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class WarehouseLocation(Base):
__tablename__ = "wh_location"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
location_code: Mapped[str] = mapped_column(String(50))
location_name: Mapped[str] = mapped_column(String(100))
zone_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
is_default: Mapped[int] = mapped_column(Integer, server_default=text("0"))
is_locked: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseReceipt(Base):
__tablename__ = "po_receipt"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
receipt_no: Mapped[str] = mapped_column(String(50))
purchase_order_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
receipt_date: Mapped[object] = mapped_column(DateTime)
receiver_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
supplier_delivery_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_waybill_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_freight_amount: Mapped[float | None] = mapped_column(DECIMAL(18, 2), nullable=True)
logistics_photo_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseReceiptItem(Base):
__tablename__ = "po_receipt_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
receipt_id: Mapped[int] = mapped_column(ForeignKey("po_receipt.id"))
line_no: Mapped[int] = mapped_column(Integer)
purchase_order_item_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order_item.id"))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
lot_no: Mapped[str] = mapped_column(String(50))
merge_to_lot_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
received_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
received_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
accepted_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
accepted_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseReturn(Base):
__tablename__ = "po_purchase_return"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
return_no: Mapped[str] = mapped_column(String(50), unique=True)
purchase_order_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
return_date: Mapped[object] = mapped_column(DateTime)
operator_user_id: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
logistics_waybill_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_freight_amount: Mapped[float | None] = mapped_column(DECIMAL(18, 2), nullable=True)
logistics_photo_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
reason: Mapped[str | None] = mapped_column(String(255), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class PurchaseReturnItem(Base):
__tablename__ = "po_purchase_return_item"
__table_args__ = (
UniqueConstraint("purchase_return_id", "line_no", name="uk_po_purchase_return_item_line"),
)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
purchase_return_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_return.id"))
line_no: Mapped[int] = mapped_column(Integer)
purchase_order_item_id: Mapped[int] = mapped_column(ForeignKey("po_purchase_order_item.id"))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
lot_id: Mapped[int] = mapped_column(ForeignKey("wh_stock_lot.id"))
return_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
reason: Mapped[str | None] = mapped_column(String(255), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class StockLot(Base):
__tablename__ = "wh_stock_lot"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
lot_no: Mapped[str] = mapped_column(String(50))
parent_lot_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
lot_role: Mapped[str] = mapped_column(String(32), server_default=text("'INVENTORY'"))
material_sub_batch_no: Mapped[str | None] = mapped_column(String(80), nullable=True)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
source_doc_type: Mapped[str] = mapped_column(String(32))
source_doc_id: Mapped[int] = mapped_column(BigInteger)
source_line_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
source_material_lot_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
source_material_sub_batch_no: Mapped[str | None] = mapped_column(String(80), nullable=True)
source_material_summary: Mapped[str | None] = mapped_column(String(1000), nullable=True)
logistics_waybill_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_freight_amount: Mapped[float | None] = mapped_column(DECIMAL(18, 2), nullable=True)
logistics_photo_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
inbound_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
inbound_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
remaining_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
remaining_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
locked_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
locked_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
production_date: Mapped[object | None] = mapped_column(Date, nullable=True)
expire_date: Mapped[object | None] = mapped_column(Date, nullable=True)
quality_status: Mapped[str] = mapped_column(String(32))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class InventoryTxn(Base):
__tablename__ = "wh_inventory_txn"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
txn_no: Mapped[str] = mapped_column(String(50))
txn_type: Mapped[str] = mapped_column(String(32))
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
qty_change: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_change_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
source_doc_type: Mapped[str] = mapped_column(String(32))
source_doc_id: Mapped[int] = mapped_column(BigInteger)
source_line_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
logistics_waybill_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_freight_amount: Mapped[float | None] = mapped_column(DECIMAL(18, 2), nullable=True)
logistics_photo_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
biz_time: Mapped[object] = mapped_column(DateTime)
operator_user_id: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class SpecialWarehouseAdjustment(Base):
__tablename__ = "wh_special_adjustment"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
adjustment_no: Mapped[str] = mapped_column(String(50), unique=True)
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
warehouse_type: Mapped[str] = mapped_column(String(32))
direction: Mapped[str] = mapped_column(String(32))
reason: Mapped[str] = mapped_column(String(1000))
status: Mapped[str] = mapped_column(String(32))
operator_user_id: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
adjusted_at: Mapped[object] = mapped_column(DateTime)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class SpecialWarehouseAdjustmentLine(Base):
__tablename__ = "wh_special_adjustment_line"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
adjustment_id: Mapped[int] = mapped_column(ForeignKey("wh_special_adjustment.id"))
line_no: Mapped[int] = mapped_column(Integer)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
lot_id: Mapped[int] = mapped_column(ForeignKey("wh_stock_lot.id"))
inventory_txn_id: Mapped[int | None] = mapped_column(ForeignKey("wh_inventory_txn.id"), nullable=True)
before_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
change_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
after_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
before_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
change_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
after_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
line_reason: Mapped[str | None] = mapped_column(String(1000), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Stocktake(Base):
__tablename__ = "wh_stocktake"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
stocktake_no: Mapped[str] = mapped_column(String(50))
status: Mapped[str] = mapped_column(String(32))
started_by_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
imported_by_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
confirmed_by_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
canceled_by_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
started_at: Mapped[object] = mapped_column(DateTime)
exported_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
imported_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
confirmed_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
canceled_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
updated_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
class StocktakeWarehouse(Base):
__tablename__ = "wh_stocktake_warehouse"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
stocktake_id: Mapped[int] = mapped_column(ForeignKey("wh_stocktake.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
warehouse_type: Mapped[str] = mapped_column(String(32))
warehouse_name: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
updated_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
class StocktakeLine(Base):
__tablename__ = "wh_stocktake_line"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
stocktake_id: Mapped[int] = mapped_column(ForeignKey("wh_stocktake.id"))
stocktake_warehouse_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stocktake_warehouse.id"), nullable=True)
line_no: Mapped[int] = mapped_column(Integer)
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
warehouse_name: Mapped[str] = mapped_column(String(100))
warehouse_type: Mapped[str] = mapped_column(String(32))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
location_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
item_code: Mapped[str] = mapped_column(String(50))
item_name: Mapped[str] = mapped_column(String(200))
item_type: Mapped[str] = mapped_column(String(32))
lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
lot_no: Mapped[str | None] = mapped_column(String(80), nullable=True)
source_material_sub_batch_no: Mapped[str | None] = mapped_column(String(80), nullable=True)
snapshot_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
snapshot_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
snapshot_unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
counted_qty: Mapped[float | None] = mapped_column(DECIMAL(18, 6), nullable=True)
counted_weight_kg: Mapped[float | None] = mapped_column(DECIMAL(18, 6), nullable=True)
diff_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
diff_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
diff_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
diff_type: Mapped[str] = mapped_column(String(32))
row_status: Mapped[str] = mapped_column(String(32))
error_message: Mapped[str | None] = mapped_column(String(500), nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
updated_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
class StocktakeAdjustment(Base):
__tablename__ = "wh_stocktake_adjustment"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
stocktake_id: Mapped[int] = mapped_column(ForeignKey("wh_stocktake.id"))
stocktake_line_id: Mapped[int] = mapped_column(ForeignKey("wh_stocktake_line.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
adjustment_lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
inventory_txn_id: Mapped[int | None] = mapped_column(ForeignKey("wh_inventory_txn.id"), nullable=True)
adjustment_type: Mapped[str] = mapped_column(String(32))
before_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
after_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
before_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
after_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
qty_change: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_change_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
created_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
updated_at: Mapped[object] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
class WorkOrder(Base):
__tablename__ = "pp_work_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
work_order_no: Mapped[str] = mapped_column(String(80))
work_order_type: Mapped[str] = mapped_column(String(32))
source_sales_order_item_id: Mapped[int | None] = mapped_column(ForeignKey("so_sales_order_item.id"), nullable=True)
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
route_id: Mapped[int] = mapped_column(ForeignKey("md_process_route.id"))
bom_id: Mapped[int] = mapped_column(ForeignKey("md_bom.id"))
planned_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
released_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
finished_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
planned_start_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
planned_end_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
actual_start_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
actual_end_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
priority_level: Mapped[int] = mapped_column(Integer, server_default=text("3"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class WorkOrderMaterial(Base):
__tablename__ = "pp_work_order_material"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
bom_item_id: Mapped[int] = mapped_column(ForeignKey("md_bom_item.id"))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
required_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
required_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
issued_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
issued_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
returned_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
returned_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class WorkOrderMaterialIssue(Base):
__tablename__ = "pp_work_order_material_issue"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
work_order_material_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order_material.id"))
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
source_lot_id: Mapped[int] = mapped_column(ForeignKey("wh_stock_lot.id"))
material_sub_batch_no: Mapped[str] = mapped_column(String(80))
issued_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
issued_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
issue_time: Mapped[object] = mapped_column(DateTime)
operator_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ProductionBatchLedger(Base):
__tablename__ = "pp_production_batch_ledger"
__table_args__ = (
UniqueConstraint("material_lot_id", "product_item_id", name="uk_production_batch_ledger_lot_product"),
)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
material_lot_id: Mapped[int] = mapped_column(ForeignKey("wh_stock_lot.id"))
material_lot_no: Mapped[str] = mapped_column(String(128))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
status: Mapped[str] = mapped_column(String(32), server_default=text("'在生产'"))
miniapp_selectable: Mapped[int] = mapped_column(Integer, server_default=text("1"))
total_issued_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
outside_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
finished_inbound_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
surplus_inbound_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_inbound_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
writeoff_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
first_issue_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
last_issue_time: Mapped[object | None] = mapped_column(DateTime, nullable=True)
locked_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
reopened_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
lock_count: Mapped[int] = mapped_column(Integer, server_default=text("0"))
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ProductionBatchLedgerTxn(Base):
__tablename__ = "pp_production_batch_ledger_txn"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
production_ledger_id: Mapped[int] = mapped_column(ForeignKey("pp_production_batch_ledger.id"))
txn_type: Mapped[str] = mapped_column(String(32))
qty_delta: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
weight_delta_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
outside_weight_after_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
source_doc_type: Mapped[str | None] = mapped_column(String(64), nullable=True)
source_doc_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
source_line_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
biz_time: Mapped[object] = mapped_column(DateTime)
operator_user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class WorkOrderOperation(Base):
__tablename__ = "pp_work_order_operation"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
route_operation_id: Mapped[int] = mapped_column(ForeignKey("md_process_route_operation.id"))
seq_no: Mapped[int] = mapped_column(Integer)
operation_name: Mapped[str] = mapped_column(String(100))
work_center_id: Mapped[int] = mapped_column(ForeignKey("md_work_center.id"))
planned_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
report_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
good_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
rework_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
std_labor_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
std_machine_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
std_outsource_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
allowed_scrap_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
is_abnormal: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class OperationReport(Base):
__tablename__ = "pp_operation_report"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
report_no: Mapped[str] = mapped_column(String(50))
work_order_id: Mapped[int | None] = mapped_column(ForeignKey("pp_work_order.id"), nullable=True)
work_order_operation_id: Mapped[int | None] = mapped_column(ForeignKey("pp_work_order_operation.id"), nullable=True)
production_ledger_id: Mapped[int | None] = mapped_column(ForeignKey("pp_production_batch_ledger.id"), nullable=True)
employee_id: Mapped[int] = mapped_column(ForeignKey("hr_employee.id"))
equipment_id: Mapped[int | None] = mapped_column(ForeignKey("em_equipment.id"), nullable=True)
report_source: Mapped[str] = mapped_column(String(32))
shift_code: Mapped[str | None] = mapped_column(String(32), nullable=True)
start_time: Mapped[object] = mapped_column(DateTime)
end_time: Mapped[object] = mapped_column(DateTime)
report_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
good_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
rework_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_reason: Mapped[str | None] = mapped_column(String(255), nullable=True)
downtime_minutes: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
extra_cost_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
is_abnormal: Mapped[int] = mapped_column(Integer, server_default=text("0"))
approved_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
approved_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ScrapRecord(Base):
__tablename__ = "pp_scrap_record"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
scrap_no: Mapped[str] = mapped_column(String(50))
report_id: Mapped[int] = mapped_column(ForeignKey("pp_operation_report.id"))
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
work_order_operation_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order_operation.id"))
item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
scrap_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_reason: Mapped[str | None] = mapped_column(String(255), nullable=True)
disposal_type: Mapped[str] = mapped_column(String(32))
saleable_scrap_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
scrap_cost_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class CompletionReceipt(Base):
__tablename__ = "pp_completion_receipt"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
receipt_no: Mapped[str] = mapped_column(String(50))
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
receipt_time: Mapped[object] = mapped_column(DateTime)
receiver_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class CompletionReceiptItem(Base):
__tablename__ = "pp_completion_receipt_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
completion_receipt_id: Mapped[int] = mapped_column(ForeignKey("pp_completion_receipt.id"))
line_no: Mapped[int] = mapped_column(Integer)
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
location_id: Mapped[int | None] = mapped_column(ForeignKey("wh_location.id"), nullable=True)
lot_no: Mapped[str] = mapped_column(String(50))
source_material_lot_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
source_material_sub_batch_no: Mapped[str | None] = mapped_column(String(80), nullable=True)
source_material_summary: Mapped[str | None] = mapped_column(String(1000), nullable=True)
receipt_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
receipt_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Delivery(Base):
__tablename__ = "so_delivery"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
delivery_no: Mapped[str] = mapped_column(String(50))
sales_order_id: Mapped[int | None] = mapped_column(ForeignKey("so_sales_order.id"), nullable=True)
customer_id: Mapped[int | None] = mapped_column(ForeignKey("md_customer.id"), nullable=True)
warehouse_id: Mapped[int] = mapped_column(ForeignKey("wh_warehouse.id"))
delivery_date: Mapped[object] = mapped_column(DateTime)
shipper_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
consignee_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
consignee_phone: Mapped[str | None] = mapped_column(String(50), nullable=True)
delivery_address: Mapped[str | None] = mapped_column(String(255), nullable=True)
logistics_waybill_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
logistics_freight_amount: Mapped[float | None] = mapped_column(DECIMAL(18, 2), nullable=True)
logistics_photo_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class DeliveryItem(Base):
__tablename__ = "so_delivery_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
delivery_id: Mapped[int] = mapped_column(ForeignKey("so_delivery.id"))
line_no: Mapped[int] = mapped_column(Integer)
sales_order_item_id: Mapped[int | None] = mapped_column(ForeignKey("so_sales_order_item.id"), nullable=True)
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
delivery_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
delivery_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_price: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
line_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ReturnOrder(Base):
__tablename__ = "rt_return_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
return_no: Mapped[str] = mapped_column(String(50))
customer_id: Mapped[int] = mapped_column(ForeignKey("md_customer.id"))
sales_order_id: Mapped[int | None] = mapped_column(ForeignKey("so_sales_order.id"), nullable=True)
delivery_id: Mapped[int | None] = mapped_column(ForeignKey("so_delivery.id"), nullable=True)
return_date: Mapped[object] = mapped_column(DateTime)
return_reason: Mapped[str | None] = mapped_column(String(255), nullable=True)
handler_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ReturnItem(Base):
__tablename__ = "rt_return_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
return_order_id: Mapped[int] = mapped_column(ForeignKey("rt_return_order.id"))
line_no: Mapped[int] = mapped_column(Integer)
sales_order_item_id: Mapped[int | None] = mapped_column(ForeignKey("so_sales_order_item.id"), nullable=True)
delivery_item_id: Mapped[int | None] = mapped_column(ForeignKey("so_delivery_item.id"), nullable=True)
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
source_lot_id: Mapped[int | None] = mapped_column(ForeignKey("wh_stock_lot.id"), nullable=True)
return_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
return_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
disposition_status: Mapped[str] = mapped_column(String(32))
responsibility_type: Mapped[str | None] = mapped_column(String(32), nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class ReturnDisposition(Base):
__tablename__ = "rt_return_disposition"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
disposition_no: Mapped[str] = mapped_column(String(50))
return_item_id: Mapped[int] = mapped_column(ForeignKey("rt_return_item.id"))
disposition_type: Mapped[str] = mapped_column(String(32))
rework_work_order_id: Mapped[int | None] = mapped_column(ForeignKey("pp_work_order.id"), nullable=True)
scrap_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
extra_cost_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
scrap_sale_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
closed_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class AccountingPeriod(Base):
__tablename__ = "fi_accounting_period"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
period_code: Mapped[str] = mapped_column(String(20))
year_no: Mapped[int] = mapped_column(Integer)
month_no: Mapped[int] = mapped_column(Integer)
start_date: Mapped[object] = mapped_column(Date)
end_date: Mapped[object] = mapped_column(Date)
close_status: Mapped[str] = mapped_column(String(32))
closed_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class OverheadEntry(Base):
__tablename__ = "fi_overhead_entry"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
period_id: Mapped[int] = mapped_column(ForeignKey("fi_accounting_period.id"))
overhead_type: Mapped[str] = mapped_column(String(32))
dept_id: Mapped[int | None] = mapped_column(ForeignKey("sys_department.id"), nullable=True)
amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
allocation_basis: Mapped[str] = mapped_column(String(32))
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class CostAllocation(Base):
__tablename__ = "fi_cost_allocation"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
period_id: Mapped[int] = mapped_column(ForeignKey("fi_accounting_period.id"))
work_order_id: Mapped[int] = mapped_column(ForeignKey("pp_work_order.id"))
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
allocation_basis_value: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
overhead_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
material_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
labor_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
machine_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
abnormal_loss_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
total_cost_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
unit_cost: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class StatementSnapshot(Base):
__tablename__ = "fi_statement_snapshot"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
snapshot_no: Mapped[str] = mapped_column(String(50))
period_id: Mapped[int] = mapped_column(ForeignKey("fi_accounting_period.id"))
statement_type: Mapped[str] = mapped_column(String(32))
report_date: Mapped[object] = mapped_column(Date)
summary_json: Mapped[dict] = mapped_column(JSON)
created_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
+181
View File
@@ -0,0 +1,181 @@
from __future__ import annotations
from sqlalchemy import DECIMAL, BigInteger, Date, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class Department(Base):
__tablename__ = "sys_department"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
dept_code: Mapped[str] = mapped_column(String(50))
dept_name: Mapped[str] = mapped_column(String(100))
parent_id: Mapped[int | None] = mapped_column(ForeignKey("sys_department.id"), nullable=True)
org_node_type: Mapped[str] = mapped_column(String(32), server_default=text("'DEPARTMENT'"))
dept_type: Mapped[str] = mapped_column(String(32))
manager_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
manager_employee_id: Mapped[int | None] = mapped_column(ForeignKey("hr_employee.id"), nullable=True)
status: Mapped[str] = mapped_column(String(32))
sort_no: Mapped[int] = mapped_column(Integer, server_default=text("0"))
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Employee(Base):
__tablename__ = "hr_employee"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
employee_code: Mapped[str] = mapped_column(String(50))
employee_name: Mapped[str] = mapped_column(String(100))
dept_id: Mapped[int] = mapped_column(ForeignKey("sys_department.id"))
mobile: Mapped[str | None] = mapped_column(String(30), nullable=True)
gender: Mapped[str | None] = mapped_column(String(16), nullable=True)
hire_date: Mapped[object | None] = mapped_column(Date, nullable=True)
job_title: Mapped[str | None] = mapped_column(String(100), nullable=True)
shift_code: Mapped[str | None] = mapped_column(String(32), nullable=True)
manager_employee_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
is_operator: Mapped[int] = mapped_column(Integer, server_default=text("0"))
is_workshop_staff: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Role(Base):
__tablename__ = "sys_role"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
role_code: Mapped[str] = mapped_column(String(50))
role_name: Mapped[str] = mapped_column(String(100))
role_scope: Mapped[str] = mapped_column(String(32))
status: Mapped[str] = mapped_column(String(32))
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class Permission(Base):
__tablename__ = "sys_permission"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
permission_code: Mapped[str] = mapped_column(String(100))
permission_name: Mapped[str] = mapped_column(String(100))
module_code: Mapped[str] = mapped_column(String(50))
action_code: Mapped[str] = mapped_column(String(50))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class RolePermission(Base):
__tablename__ = "sys_role_permission"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
role_id: Mapped[int] = mapped_column(ForeignKey("sys_role.id"))
permission_id: Mapped[int] = mapped_column(ForeignKey("sys_permission.id"))
created_at: Mapped[object] = mapped_column(DateTime)
class User(Base):
__tablename__ = "sys_user"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
username: Mapped[str] = mapped_column(String(50))
password_hash: Mapped[str] = mapped_column(String(255))
employee_id: Mapped[int] = mapped_column(ForeignKey("hr_employee.id"))
dept_id: Mapped[int] = mapped_column(ForeignKey("sys_department.id"))
nickname: Mapped[str | None] = mapped_column(String(100), nullable=True)
email: Mapped[str | None] = mapped_column(String(100), nullable=True)
is_super_admin: Mapped[int] = mapped_column(Integer, server_default=text("0"))
last_login_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class UserRole(Base):
__tablename__ = "sys_user_role"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("sys_user.id"))
role_id: Mapped[int] = mapped_column(ForeignKey("sys_role.id"))
created_at: Mapped[object] = mapped_column(DateTime)
class OrgEmployeeBinding(Base):
__tablename__ = "sys_org_employee_binding"
__table_args__ = (UniqueConstraint("dept_id", "employee_id", name="uk_org_employee_binding"),)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
dept_id: Mapped[int] = mapped_column(ForeignKey("sys_department.id"))
employee_id: Mapped[int] = mapped_column(ForeignKey("hr_employee.id"))
sort_no: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32), server_default=text("'ACTIVE'"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class OrgManagerBinding(Base):
__tablename__ = "sys_org_manager_binding"
__table_args__ = (UniqueConstraint("dept_id", "employee_id", name="uk_org_manager_binding"),)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
dept_id: Mapped[int] = mapped_column(ForeignKey("sys_department.id"))
employee_id: Mapped[int] = mapped_column(ForeignKey("hr_employee.id"))
sort_no: Mapped[int] = mapped_column(Integer, server_default=text("0"))
status: Mapped[str] = mapped_column(String(32), server_default=text("'ACTIVE'"))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class BroadcastMessage(Base):
__tablename__ = "sys_broadcast_message"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
title: Mapped[str] = mapped_column(String(100))
content: Mapped[str] = mapped_column(String(500))
tone: Mapped[str] = mapped_column(String(32), server_default=text("'INFO'"))
status: Mapped[str] = mapped_column(String(32), server_default=text("'ACTIVE'"))
starts_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
ends_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
sort_no: Mapped[int] = mapped_column(Integer, server_default=text("0"))
created_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class SystemConfig(Base):
__tablename__ = "sys_system_config"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
config_code: Mapped[str] = mapped_column(String(100), unique=True)
config_name: Mapped[str] = mapped_column(String(100))
config_value: Mapped[str] = mapped_column(String(500))
remark: Mapped[str | None] = mapped_column(String(500), nullable=True)
status: Mapped[str] = mapped_column(String(32), server_default=text("'ACTIVE'"))
created_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
updated_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class AiAssistantConfig(Base):
__tablename__ = "sys_ai_assistant_config"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
assistant_name: Mapped[str] = mapped_column(String(100), server_default=text("'嘉恒工艺助手'"))
provider_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
api_base_url: Mapped[str | None] = mapped_column(String(255), nullable=True)
api_key: Mapped[str | None] = mapped_column(String(512), nullable=True)
model_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
temperature: Mapped[float] = mapped_column(DECIMAL(6, 3), server_default=text("0.300"))
system_prompt: Mapped[str | None] = mapped_column(Text, nullable=True)
enabled: Mapped[int] = mapped_column(Integer, server_default=text("0"))
created_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
updated_by: Mapped[int | None] = mapped_column(ForeignKey("sys_user.id"), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
+29
View File
@@ -0,0 +1,29 @@
from __future__ import annotations
from sqlalchemy import BigInteger, DateTime, DECIMAL, ForeignKey, String, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class MaterialDemand(Base):
__tablename__ = "mrp_material_demand"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
demand_no: Mapped[str] = mapped_column(String(50))
sales_order_item_id: Mapped[int] = mapped_column(ForeignKey("so_sales_order_item.id"))
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
bom_item_id: Mapped[int] = mapped_column(ForeignKey("md_bom_item.id"))
order_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
theoretical_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
planned_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
available_stock_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
shortage_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
suggested_purchase_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
suggested_purchase_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
generated_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
+58
View File
@@ -0,0 +1,58 @@
from __future__ import annotations
from sqlalchemy import BigInteger, Date, DateTime, DECIMAL, ForeignKey, Integer, String, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class Customer(Base):
__tablename__ = "md_customer"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
customer_code: Mapped[str] = mapped_column(String(50))
customer_name: Mapped[str] = mapped_column(String(200))
short_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
contact_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
contact_phone: Mapped[str | None] = mapped_column(String(50), nullable=True)
address: Mapped[str | None] = mapped_column(String(255), nullable=True)
tax_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
credit_days: Mapped[int] = mapped_column(server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class SalesOrder(Base):
__tablename__ = "so_sales_order"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
order_no: Mapped[str] = mapped_column(String(50))
customer_id: Mapped[int] = mapped_column(ForeignKey("md_customer.id"))
order_date: Mapped[object] = mapped_column(Date)
promised_date: Mapped[object | None] = mapped_column(Date, nullable=True)
sales_employee_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
delivery_address: Mapped[str | None] = mapped_column(String(255), nullable=True)
tax_rate: Mapped[float] = mapped_column(DECIMAL(8, 4), server_default=text("0"))
total_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)
class SalesOrderItem(Base):
__tablename__ = "so_sales_order_item"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
sales_order_id: Mapped[int] = mapped_column(ForeignKey("so_sales_order.id"))
line_no: Mapped[int] = mapped_column(Integer)
product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
customer_part_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
order_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
delivered_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
unit_price: Mapped[float] = mapped_column(DECIMAL(18, 4), server_default=text("0"))
line_amount: Mapped[float] = mapped_column(DECIMAL(18, 2), server_default=text("0"))
promised_date: Mapped[object | None] = mapped_column(Date, nullable=True)
status: Mapped[str] = mapped_column(String(32))
created_at: Mapped[object] = mapped_column(DateTime)
updated_at: Mapped[object] = mapped_column(DateTime)