This commit is contained in:
zlwu committed 2026-08-04 14:02:01 +08:00
1 parent 012a2ad68e
commit 5fe53c5481
4775 files changed
+2190111 -40277

No files matched your search

+26
View File
@@ -77,6 +77,7 @@ from app.crud.crm.customer import (
get_customer,
get_park_area_list,
into_pool,
list_customer_options,
list_customers,
list_pool_customers,
soft_delete_customer,
@@ -207,6 +208,7 @@ from app.schemas.crm.customer import (
CustomerCreateBody,
CustomerDeleteBody,
CustomerListBody,
CustomerOptionsBody,
CustomerUpdateBody,
)
from app.schemas.crm.contact import (
@@ -412,6 +414,29 @@ def customer_detail(
return error_response(500, str(e))
@router.post("/customer/options")
def customer_options(
body: CustomerOptionsBody,
_user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
"""客户下拉选项(租户内只读,不做 owner 数据权限)"""
try:
tenant_no = get_tenant_no(db, _user)
keyword = (body.keyword or body.customer_name or "").strip() or None
options = list_customer_options(
db,
tenant_no,
keyword=keyword,
limit=body.limit,
)
return success_response(options)
except ValueError as e:
return error_response(400, str(e))
except Exception as e:
return error_response(500, str(e))
@router.post("/customer/add")
@oper_log(title="CRM客户管理", business_type=1, summary="新增客户【{customerName}】")
def customer_create(
@@ -741,6 +766,7 @@ def product_options(
keyword=body.keyword,
category_id=body.category_id,
user_info=user_info,
limit=body.limit,
)
return success_response(options)
except ValueError as e:
+9 -6
View File
@@ -28,6 +28,7 @@ from app.services.db.mappers import (
EMPTY_INVENTORY_DATE,
inventory_to_read,
is_empty_inventory_date,
load_user_display_name_map,
parse_date_str,
plan_to_read,
weighing_to_read,
@@ -256,12 +257,14 @@ def list_inventory(
weighing_map[weighing.inbound_outbound_id] = weighing
result_list: list[InboundOutboundRead] = []
user_name_map = load_user_display_name_map(db, [inv.create_by for inv in inventories])
for inventory in inventories:
try:
result_list.append(
inventory_to_read(
inventory,
weighing=weighing_map.get(inventory.id),
user_name_map=user_name_map,
)
)
except Exception:
@@ -310,7 +313,7 @@ def create_inventory(
db.add(row)
db.commit()
db.refresh(row)
return inventory_to_read(row)
return inventory_to_read(row, db=db)
@router.post(
@@ -365,7 +368,7 @@ def create_link_for_plan(
db.add(row)
db.commit()
db.refresh(row)
return inventory_to_read(row)
return inventory_to_read(row, db=db)
@router.get("/{id}/site-url", response_model=InventorySiteUrlRead)
@@ -398,7 +401,7 @@ def get_inventory(
.order_by(DbWeighingSlip.id.asc())
.first()
)
return inventory_to_read(row, weighing=weighing)
return inventory_to_read(row, weighing=weighing, db=db)
@router.patch("/{id}", response_model=InboundOutboundRead)
@@ -416,7 +419,7 @@ def update_inventory(
_maybe_promote_third_party_status(row)
db.commit()
db.refresh(row)
return inventory_to_read(row)
return inventory_to_read(row, db=db)
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT)
@@ -475,6 +478,6 @@ def get_inventory_related(
)
return InventoryRelatedData(
plan=plan_to_read(plan) if plan else None,
weighing=weighing_to_read(weighing) if weighing else None,
plan=plan_to_read(plan, db=db) if plan else None,
weighing=weighing_to_read(weighing, db=db) if weighing else None,
)
+25 -8
View File
@@ -24,6 +24,7 @@ from app.schemas.db.plans import (
from app.schemas.db.weighing import WeighingSlipRead
from app.services.db.mappers import (
inventory_to_read,
load_user_display_name_map,
parse_date_str,
parse_datetime_str,
plan_to_read,
@@ -177,6 +178,7 @@ def list_plans(
total += executed
return total
user_name_map = load_user_display_name_map(db, [p.create_by for p in plans])
result_list: list[PurchasePlanWithFillLink] = []
for plan in plans:
result_list.append(
@@ -184,6 +186,7 @@ def list_plans(
plan,
executed_quantity=calc_executed_for_plan(plan),
fill_link_inventory_id=plan_id_to_inv_id.get(plan.id),
user_name_map=user_name_map,
)
)
return result_list
@@ -236,7 +239,7 @@ def create_plan(
db.add(plan)
db.commit()
db.refresh(plan)
return plan_to_read(plan)
return plan_to_read(plan, db=db)
class AutoGenerateMonthlyResult(BaseModel):
@@ -267,7 +270,7 @@ def get_plan(
) -> PurchasePlanRead:
tenant_no = get_tenant_no(db, user.to_tenant_user_dict())
plan = _get_plan(db, tenant_no, id, user)
return plan_to_read(plan)
return plan_to_read(plan, db=db)
@router.patch("/{id}", response_model=PurchasePlanRead)
@@ -285,7 +288,7 @@ def update_plan(
plan.update_by = user.id
db.commit()
db.refresh(plan)
return plan_to_read(plan)
return plan_to_read(plan, db=db)
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT)
@@ -418,9 +421,13 @@ def get_plan_related(
weighing_query = weighing_query.filter(DbWeighingSlip.purchase_plan_id == plan.id)
weighings = weighing_query.order_by(DbWeighingSlip.create_time.desc()).all()
user_name_map = load_user_display_name_map(
db,
[inv.create_by for inv in inventories] + [w.create_by for w in weighings],
)
return PlanRelatedData(
inventories=[inventory_to_read(inv) for inv in inventories],
weighings=[weighing_to_read(w) for w in weighings],
inventories=[inventory_to_read(inv, user_name_map=user_name_map) for inv in inventories],
weighings=[weighing_to_read(w, user_name_map=user_name_map) for w in weighings],
)
@@ -482,8 +489,18 @@ def get_third_party_plan_page(
.all()
)
user_name_map = load_user_display_name_map(
db,
[plan.create_by]
+ [inv.create_by for inv in inventories]
+ [inv.create_by for inv in month_history],
)
return ThirdPartyPlanPageData(
plan=plan_to_read(plan),
today_inventories=[inventory_to_read(inv) for inv in inventories],
month_inventories=[inventory_to_read(inv) for inv in month_history],
plan=plan_to_read(plan, user_name_map=user_name_map),
today_inventories=[
inventory_to_read(inv, user_name_map=user_name_map) for inv in inventories
],
month_inventories=[
inventory_to_read(inv, user_name_map=user_name_map) for inv in month_history
],
)
+8 -5
View File
@@ -21,6 +21,7 @@ from app.services.db.mappers import (
datetime_end_of_day,
inventory_date_to_api,
inventory_to_read,
load_user_display_name_map,
parse_date_str,
parse_datetime_str,
plan_to_read,
@@ -183,10 +184,12 @@ def list_weighing(
for inventory in inventories:
inventory_date_map[inventory.id] = inventory_date_to_api(inventory.date)
user_name_map = load_user_display_name_map(db, [w.create_by for w in weighings])
return [
weighing_to_read(
weighing,
inventory_date=inventory_date_map.get(weighing.inbound_outbound_id or ""),
user_name_map=user_name_map,
)
for weighing in weighings
]
@@ -290,7 +293,7 @@ def create_weighing(
process_weighing_business_logic(db, row)
db.refresh(row)
return weighing_to_read(row)
return weighing_to_read(row, db=db)
@router.get("/{id}", response_model=WeighingSlipRead)
@@ -301,7 +304,7 @@ def get_weighing(
) -> WeighingSlipRead:
tenant_no = get_tenant_no(db, user.to_tenant_user_dict())
row = _get_weighing(db, tenant_no, id, user)
return weighing_to_read(row)
return weighing_to_read(row, db=db)
@router.patch("/{id}", response_model=WeighingSlipRead)
@@ -329,7 +332,7 @@ def update_weighing(
process_weighing_business_logic(db, row)
db.refresh(row)
return weighing_to_read(row)
return weighing_to_read(row, db=db)
@router.post("/{id}/void", status_code=status.HTTP_204_NO_CONTENT)
@@ -416,6 +419,6 @@ def get_weighing_related(
)
return WeighingRelatedData(
plan=plan_to_read(plan) if plan else None,
inventory=inventory_to_read(inventory) if inventory else None,
plan=plan_to_read(plan, db=db) if plan else None,
inventory=inventory_to_read(inventory, db=db) if inventory else None,
)