init: mini-erp-fabric-demo 迷你 ERP + 治理演示底座(FastAPI+MySQL+Docker,含业务/架构/数据字典文档与稽核脚本)
This commit is contained in:
commit
509fd32518
38 files changed
+3920
No files matched your search
@@ -0,0 +1,159 @@
|
||||
from .models import (
|
||||
AliasMapping,
|
||||
Customer,
|
||||
PurchaseOrder,
|
||||
SalesOrder,
|
||||
Sku,
|
||||
Stock,
|
||||
StockFlow,
|
||||
Supplier,
|
||||
)
|
||||
|
||||
|
||||
def mask_phone(phone: str | None) -> str | None:
|
||||
if not phone:
|
||||
return phone
|
||||
if len(phone) >= 7:
|
||||
return phone[:3] + "****" + phone[-4:]
|
||||
return "****"
|
||||
|
||||
|
||||
def _dt(v):
|
||||
return v.strftime("%Y-%m-%d %H:%M:%S") if v else None
|
||||
|
||||
|
||||
def supplier_out(s: Supplier) -> dict:
|
||||
return {
|
||||
"id": s.id,
|
||||
"code": s.supplier_code,
|
||||
"name": s.supplier_name,
|
||||
"contact_person": s.contact_person,
|
||||
"contact_phone": mask_phone(s.contact_phone),
|
||||
"address": s.address,
|
||||
"status": s.status,
|
||||
"remark": s.remark,
|
||||
"created_at": _dt(s.created_at),
|
||||
"updated_at": _dt(s.updated_at),
|
||||
}
|
||||
|
||||
|
||||
def customer_out(c: Customer) -> dict:
|
||||
return {
|
||||
"id": c.id,
|
||||
"code": c.customer_code,
|
||||
"name": c.customer_name,
|
||||
"contact_person": c.contact_person,
|
||||
"contact_phone": mask_phone(c.contact_phone),
|
||||
"address": c.address,
|
||||
"status": c.status,
|
||||
"remark": c.remark,
|
||||
"created_at": _dt(c.created_at),
|
||||
"updated_at": _dt(c.updated_at),
|
||||
}
|
||||
|
||||
|
||||
def sku_out(s: Sku) -> dict:
|
||||
return {
|
||||
"id": s.id,
|
||||
"code": s.sku_code,
|
||||
"name": s.sku_name,
|
||||
"category": s.category,
|
||||
"spec": s.spec,
|
||||
"unit": s.unit,
|
||||
"purchase_price": float(s.purchase_price),
|
||||
"sale_price": float(s.sale_price),
|
||||
"safety_stock": float(s.safety_stock),
|
||||
"status": s.status,
|
||||
"remark": s.remark,
|
||||
"created_at": _dt(s.created_at),
|
||||
"updated_at": _dt(s.updated_at),
|
||||
}
|
||||
|
||||
|
||||
def alias_out(a: AliasMapping, entity_code: str | None, entity_name: str | None) -> dict:
|
||||
return {
|
||||
"id": a.id,
|
||||
"entity_type": a.entity_type,
|
||||
"entity_id": a.entity_id,
|
||||
"entity_code": entity_code,
|
||||
"entity_name": entity_name,
|
||||
"alias": a.alias,
|
||||
"source_system": a.source_system,
|
||||
"remark": a.remark,
|
||||
"created_at": _dt(a.created_at),
|
||||
}
|
||||
|
||||
|
||||
def _item_out(it) -> dict:
|
||||
return {
|
||||
"id": it.id,
|
||||
"line_no": it.line_no,
|
||||
"sku_id": it.sku_id,
|
||||
"sku_code": it.sku.sku_code,
|
||||
"sku_name": it.sku.sku_name,
|
||||
"unit": it.sku.unit,
|
||||
"qty": float(it.qty),
|
||||
"price": float(it.price),
|
||||
"amount": float(it.amount),
|
||||
}
|
||||
|
||||
|
||||
def order_out(o, with_items: bool = True) -> dict:
|
||||
if isinstance(o, PurchaseOrder):
|
||||
master_id, master = o.supplier_id, o.supplier
|
||||
master_code, master_name = master.supplier_code, master.supplier_name
|
||||
executed_at = o.received_at
|
||||
else:
|
||||
master_id, master = o.customer_id, o.customer
|
||||
master_code, master_name = master.customer_code, master.customer_name
|
||||
executed_at = o.shipped_at
|
||||
data = {
|
||||
"id": o.id,
|
||||
"order_no": o.order_no,
|
||||
"master_id": master_id,
|
||||
"master_code": master_code,
|
||||
"master_name": master_name,
|
||||
"order_date": o.order_date.isoformat(),
|
||||
"status": o.status,
|
||||
"total_amount": float(o.total_amount),
|
||||
"item_count": len(o.items),
|
||||
"handler": o.handler,
|
||||
"remark": o.remark,
|
||||
"executed_at": _dt(executed_at),
|
||||
"created_at": _dt(o.created_at),
|
||||
"updated_at": _dt(o.updated_at),
|
||||
}
|
||||
if with_items:
|
||||
data["items"] = [_item_out(it) for it in o.items]
|
||||
return data
|
||||
|
||||
|
||||
def stock_out(s: Stock) -> dict:
|
||||
return {
|
||||
"id": s.id,
|
||||
"sku_id": s.sku_id,
|
||||
"sku_code": s.sku.sku_code,
|
||||
"sku_name": s.sku.sku_name,
|
||||
"category": s.sku.category,
|
||||
"unit": s.sku.unit,
|
||||
"qty_on_hand": float(s.qty_on_hand),
|
||||
"safety_stock": float(s.sku.safety_stock),
|
||||
"low_stock": s.qty_on_hand < s.sku.safety_stock,
|
||||
"updated_at": _dt(s.updated_at),
|
||||
}
|
||||
|
||||
|
||||
def flow_out(f: StockFlow) -> dict:
|
||||
return {
|
||||
"id": f.id,
|
||||
"sku_id": f.sku_id,
|
||||
"sku_code": f.sku.sku_code,
|
||||
"sku_name": f.sku.sku_name,
|
||||
"unit": f.sku.unit,
|
||||
"biz_type": f.biz_type,
|
||||
"biz_order_no": f.biz_order_no,
|
||||
"qty_delta": float(f.qty_delta),
|
||||
"qty_after": float(f.qty_after),
|
||||
"remark": f.remark,
|
||||
"created_at": _dt(f.created_at),
|
||||
}
|
||||
Reference in new issue
Block a user