Support filtered and selected export on apply and disburse/process board pages. Co-authored-by: Cursor <cursoragent@cursor.com>
611 lines
20 KiB
Python
611 lines
20 KiB
Python
"""车辆尿素业务逻辑"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
from typing import Optional
|
|
|
|
from fastapi import HTTPException
|
|
from sqlalchemy import and_, func, or_
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.db_auth import DbUserContext
|
|
from app.core.utils import generate_uuid
|
|
from app.models.models import SysUser
|
|
from app.models.pl_models import PlVehicle, PlVehicleUreaApply, PlVehicleUreaDisburse
|
|
from app.schemas.pl.vehicle_urea import (
|
|
VehicleUreaApplyCreate,
|
|
VehicleUreaApplyRead,
|
|
VehicleUreaApplyUpdate,
|
|
VehicleUreaDisburseBoardItem,
|
|
VehicleUreaDisburseCreate,
|
|
VehicleUreaDisburseRead,
|
|
VehicleUreaDisburseUpdate,
|
|
)
|
|
from app.services.pl_data_scope import apply_pl_scope, assert_pl_row_in_scope
|
|
|
|
|
|
def _generate_seq_no(db: Session, model, column_attr: str, prefix: str) -> str:
|
|
column = getattr(model, column_attr)
|
|
last = (
|
|
db.query(model)
|
|
.filter(column.like(f"{prefix}%"))
|
|
.order_by(column.desc())
|
|
.first()
|
|
)
|
|
seq = int(getattr(last, column_attr)[-6:]) + 1 if last else 1
|
|
return f"{prefix}{seq:06d}"
|
|
|
|
|
|
def generate_apply_no(db: Session) -> str:
|
|
return _generate_seq_no(
|
|
db, PlVehicleUreaApply, "apply_no", f"SXNS{date.today():%Y%m%d}"
|
|
)
|
|
|
|
|
|
def generate_disburse_no(db: Session) -> str:
|
|
return _generate_seq_no(
|
|
db, PlVehicleUreaDisburse, "disburse_no", f"SXUF{date.today():%Y%m%d}"
|
|
)
|
|
|
|
|
|
def _resolve_user_name(db: Session, user_id: Optional[str]) -> Optional[str]:
|
|
if not user_id:
|
|
return None
|
|
row = (
|
|
db.query(SysUser)
|
|
.filter(SysUser.id == user_id, SysUser.del_flag == 0)
|
|
.first()
|
|
)
|
|
return row.nick_name or row.user_no if row else None
|
|
|
|
|
|
def _assert_vehicle_exists(db: Session, tenant_no: str, license_plate: str) -> None:
|
|
exists = (
|
|
db.query(PlVehicle.id)
|
|
.filter(
|
|
PlVehicle.tenant_no == tenant_no,
|
|
PlVehicle.license_plate == license_plate,
|
|
PlVehicle.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if not exists:
|
|
raise HTTPException(status_code=400, detail="车牌号不存在")
|
|
|
|
|
|
def _resolve_user_id(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user_id: Optional[str],
|
|
user: DbUserContext,
|
|
*,
|
|
field_label: str = "用户",
|
|
) -> str:
|
|
target = (user_id or "").strip() or user.id
|
|
row = (
|
|
db.query(SysUser.id)
|
|
.filter(
|
|
SysUser.id == target,
|
|
SysUser.tenant_no == tenant_no,
|
|
SysUser.del_flag == 0,
|
|
SysUser.status == "1",
|
|
)
|
|
.first()
|
|
)
|
|
if not row:
|
|
raise HTTPException(status_code=400, detail=f"{field_label}不存在或已停用")
|
|
return target
|
|
|
|
|
|
def _validate_apply_dates(apply_date: date, warehouse_in_date: date) -> None:
|
|
if apply_date > warehouse_in_date:
|
|
raise HTTPException(status_code=400, detail="申请时间不能晚于入库时间")
|
|
|
|
|
|
def _get_apply_row(
|
|
db: Session, tenant_no: str, apply_id: str, user: DbUserContext
|
|
) -> PlVehicleUreaApply:
|
|
row = (
|
|
db.query(PlVehicleUreaApply)
|
|
.filter(
|
|
PlVehicleUreaApply.id == apply_id,
|
|
PlVehicleUreaApply.tenant_no == tenant_no,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if not row:
|
|
raise HTTPException(status_code=404, detail="申请单不存在")
|
|
assert_pl_row_in_scope(db, row, PlVehicleUreaApply, user, tenant_no)
|
|
return row
|
|
|
|
|
|
def _get_disburse_row(
|
|
db: Session, tenant_no: str, disburse_id: str, user: DbUserContext
|
|
) -> PlVehicleUreaDisburse:
|
|
row = (
|
|
db.query(PlVehicleUreaDisburse)
|
|
.filter(
|
|
PlVehicleUreaDisburse.id == disburse_id,
|
|
PlVehicleUreaDisburse.tenant_no == tenant_no,
|
|
PlVehicleUreaDisburse.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if not row:
|
|
raise HTTPException(status_code=404, detail="发放登记不存在")
|
|
assert_pl_row_in_scope(db, row, PlVehicleUreaDisburse, user, tenant_no)
|
|
return row
|
|
|
|
|
|
def _has_active_disburse(db: Session, tenant_no: str, apply_id: str) -> bool:
|
|
return (
|
|
db.query(PlVehicleUreaDisburse.id)
|
|
.filter(
|
|
PlVehicleUreaDisburse.apply_id == apply_id,
|
|
PlVehicleUreaDisburse.tenant_no == tenant_no,
|
|
PlVehicleUreaDisburse.del_flag == 0,
|
|
)
|
|
.first()
|
|
is not None
|
|
)
|
|
|
|
|
|
def apply_to_read(row: PlVehicleUreaApply, db: Session) -> VehicleUreaApplyRead:
|
|
return VehicleUreaApplyRead(
|
|
id=row.id,
|
|
applyNo=row.apply_no,
|
|
licensePlate=row.license_plate,
|
|
applicantId=row.applicant_id,
|
|
applicantName=_resolve_user_name(db, row.applicant_id),
|
|
applyDate=row.apply_date,
|
|
warehouseInDate=row.warehouse_in_date,
|
|
unit=row.unit,
|
|
quantity=row.quantity,
|
|
applyAmount=row.apply_amount,
|
|
attachmentUrls=row.attachment_urls,
|
|
status=row.status,
|
|
remark=row.remark,
|
|
createTime=row.create_time,
|
|
updateTime=row.update_time,
|
|
)
|
|
|
|
|
|
def disburse_to_read(
|
|
row: PlVehicleUreaDisburse, db: Session, apply_no: Optional[str] = None
|
|
) -> VehicleUreaDisburseRead:
|
|
if apply_no is None and row.apply_id:
|
|
apply = (
|
|
db.query(PlVehicleUreaApply.apply_no)
|
|
.filter(
|
|
PlVehicleUreaApply.id == row.apply_id,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
apply_no = apply.apply_no if apply else None
|
|
return VehicleUreaDisburseRead(
|
|
id=row.id,
|
|
disburseNo=row.disburse_no,
|
|
applyId=row.apply_id,
|
|
applyNo=apply_no,
|
|
licensePlate=row.license_plate,
|
|
amount=row.amount,
|
|
handlerId=row.handler_id,
|
|
handlerName=_resolve_user_name(db, row.handler_id),
|
|
disburseDate=row.disburse_date,
|
|
attachmentUrls=row.attachment_urls,
|
|
remark=row.remark,
|
|
createBy=row.create_by,
|
|
createByName=_resolve_user_name(db, row.create_by),
|
|
createTime=row.create_time,
|
|
updateTime=row.update_time,
|
|
)
|
|
|
|
|
|
def _resolve_apply_for_disburse(
|
|
db: Session,
|
|
tenant_no: str,
|
|
payload: VehicleUreaDisburseCreate | VehicleUreaDisburseUpdate,
|
|
user: DbUserContext,
|
|
*,
|
|
current_disburse_id: Optional[str] = None,
|
|
) -> tuple[Optional[PlVehicleUreaApply], str]:
|
|
license_plate = (payload.license_plate or "").strip()
|
|
|
|
if payload.apply_id:
|
|
apply = _get_apply_row(db, tenant_no, payload.apply_id, user)
|
|
if apply.status != "pending":
|
|
raise HTTPException(status_code=400, detail="仅待发放申请可关联")
|
|
existing = (
|
|
db.query(PlVehicleUreaDisburse)
|
|
.filter(
|
|
PlVehicleUreaDisburse.apply_id == apply.id,
|
|
PlVehicleUreaDisburse.tenant_no == tenant_no,
|
|
PlVehicleUreaDisburse.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if existing and existing.id != current_disburse_id:
|
|
raise HTTPException(status_code=400, detail="该申请单已被关联")
|
|
return apply, apply.license_plate
|
|
|
|
if not license_plate:
|
|
raise HTTPException(status_code=400, detail="请填写车牌号或关联申请单")
|
|
_assert_vehicle_exists(db, tenant_no, license_plate)
|
|
return None, license_plate
|
|
|
|
|
|
def list_applies(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
*,
|
|
q: Optional[str] = None,
|
|
status: Optional[str] = None,
|
|
apply_date_from: Optional[date] = None,
|
|
apply_date_to: Optional[date] = None,
|
|
applicant_id: Optional[str] = None,
|
|
ids: Optional[list[str]] = None,
|
|
page: int = 1,
|
|
page_size: int = 20,
|
|
max_page_size: Optional[int] = None,
|
|
) -> tuple[list[VehicleUreaApplyRead], int]:
|
|
query = db.query(PlVehicleUreaApply).filter(
|
|
PlVehicleUreaApply.tenant_no == tenant_no,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
if q:
|
|
query = query.filter(
|
|
or_(
|
|
PlVehicleUreaApply.apply_no.contains(q),
|
|
PlVehicleUreaApply.license_plate.contains(q),
|
|
)
|
|
)
|
|
if status:
|
|
query = query.filter(PlVehicleUreaApply.status == status)
|
|
if apply_date_from:
|
|
query = query.filter(PlVehicleUreaApply.apply_date >= apply_date_from)
|
|
if apply_date_to:
|
|
query = query.filter(PlVehicleUreaApply.apply_date <= apply_date_to)
|
|
if applicant_id:
|
|
query = query.filter(PlVehicleUreaApply.applicant_id == applicant_id)
|
|
|
|
if ids:
|
|
query = query.filter(PlVehicleUreaApply.id.in_(ids))
|
|
|
|
query = apply_pl_scope(query, PlVehicleUreaApply, user, db, tenant_no)
|
|
total = query.count()
|
|
page = max(1, page)
|
|
cap = int(max_page_size) if max_page_size else 500
|
|
page_size = min(max(1, page_size), cap)
|
|
rows = (
|
|
query.order_by(PlVehicleUreaApply.create_time.desc())
|
|
.offset((page - 1) * page_size)
|
|
.limit(page_size)
|
|
.all()
|
|
)
|
|
return [apply_to_read(row, db) for row in rows], total
|
|
|
|
|
|
def get_apply(
|
|
db: Session, tenant_no: str, user: DbUserContext, apply_id: str
|
|
) -> VehicleUreaApplyRead:
|
|
row = _get_apply_row(db, tenant_no, apply_id, user)
|
|
return apply_to_read(row, db)
|
|
|
|
|
|
def create_apply(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
payload: VehicleUreaApplyCreate,
|
|
) -> VehicleUreaApplyRead:
|
|
license_plate = payload.license_plate.strip()
|
|
_assert_vehicle_exists(db, tenant_no, license_plate)
|
|
_validate_apply_dates(payload.apply_date, payload.warehouse_in_date)
|
|
applicant_id = _resolve_user_id(db, tenant_no, payload.applicant_id, user, field_label="申请人")
|
|
unit = (payload.unit or "").strip() or "吨桶"
|
|
now = datetime.now()
|
|
row = PlVehicleUreaApply(
|
|
id=generate_uuid(),
|
|
apply_no=generate_apply_no(db),
|
|
license_plate=license_plate,
|
|
applicant_id=applicant_id,
|
|
apply_date=payload.apply_date,
|
|
warehouse_in_date=payload.warehouse_in_date,
|
|
unit=unit,
|
|
quantity=payload.quantity,
|
|
apply_amount=payload.apply_amount,
|
|
attachment_urls=payload.attachment_urls,
|
|
status="pending",
|
|
tenant_no=tenant_no,
|
|
remark=payload.remark,
|
|
create_by=user.id,
|
|
create_dept_id=user.dept_id or "",
|
|
create_time=now,
|
|
update_by=user.id,
|
|
update_time=now,
|
|
del_flag=0,
|
|
)
|
|
db.add(row)
|
|
db.commit()
|
|
db.refresh(row)
|
|
return apply_to_read(row, db)
|
|
|
|
|
|
def update_apply(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
apply_id: str,
|
|
payload: VehicleUreaApplyUpdate,
|
|
) -> VehicleUreaApplyRead:
|
|
row = _get_apply_row(db, tenant_no, apply_id, user)
|
|
if row.status != "pending":
|
|
raise HTTPException(status_code=400, detail="仅待发放申请可编辑")
|
|
license_plate = payload.license_plate.strip()
|
|
_assert_vehicle_exists(db, tenant_no, license_plate)
|
|
_validate_apply_dates(payload.apply_date, payload.warehouse_in_date)
|
|
unit = (payload.unit or "").strip() or "吨桶"
|
|
row.license_plate = license_plate
|
|
row.applicant_id = _resolve_user_id(db, tenant_no, payload.applicant_id, user, field_label="申请人")
|
|
row.apply_date = payload.apply_date
|
|
row.warehouse_in_date = payload.warehouse_in_date
|
|
row.unit = unit
|
|
row.quantity = payload.quantity
|
|
row.apply_amount = payload.apply_amount
|
|
row.attachment_urls = payload.attachment_urls
|
|
row.remark = payload.remark
|
|
row.update_by = user.id
|
|
row.update_time = datetime.now()
|
|
db.commit()
|
|
db.refresh(row)
|
|
return apply_to_read(row, db)
|
|
|
|
|
|
def cancel_apply(
|
|
db: Session, tenant_no: str, user: DbUserContext, apply_id: str
|
|
) -> VehicleUreaApplyRead:
|
|
row = _get_apply_row(db, tenant_no, apply_id, user)
|
|
if row.status != "pending":
|
|
raise HTTPException(status_code=400, detail="仅待发放申请可作废")
|
|
row.status = "cancelled"
|
|
row.update_by = user.id
|
|
row.update_time = datetime.now()
|
|
db.commit()
|
|
db.refresh(row)
|
|
return apply_to_read(row, db)
|
|
|
|
|
|
def delete_applies(
|
|
db: Session, tenant_no: str, user: DbUserContext, apply_ids: list[str]
|
|
) -> None:
|
|
for apply_id in apply_ids:
|
|
row = _get_apply_row(db, tenant_no, apply_id, user)
|
|
if row.status != "pending":
|
|
raise HTTPException(status_code=400, detail="仅待发放申请可删除")
|
|
if _has_active_disburse(db, tenant_no, apply_id):
|
|
raise HTTPException(status_code=400, detail="已关联发放记录的申请不可删除")
|
|
row.del_flag = 1
|
|
row.update_by = user.id
|
|
row.update_time = datetime.now()
|
|
db.commit()
|
|
|
|
|
|
def board_item_to_read(
|
|
apply_row: PlVehicleUreaApply,
|
|
disburse_row: Optional[PlVehicleUreaDisburse],
|
|
db: Session,
|
|
) -> VehicleUreaDisburseBoardItem:
|
|
return VehicleUreaDisburseBoardItem(
|
|
applyId=apply_row.id,
|
|
applyNo=apply_row.apply_no,
|
|
licensePlate=apply_row.license_plate,
|
|
applyDate=apply_row.apply_date,
|
|
warehouseInDate=apply_row.warehouse_in_date,
|
|
unit=apply_row.unit,
|
|
quantity=apply_row.quantity,
|
|
applyAmount=apply_row.apply_amount,
|
|
applicantName=_resolve_user_name(db, apply_row.applicant_id),
|
|
applyStatus=apply_row.status,
|
|
applyRemark=apply_row.remark,
|
|
disburseId=disburse_row.id if disburse_row else None,
|
|
disburseNo=disburse_row.disburse_no if disburse_row else None,
|
|
disburseDate=disburse_row.disburse_date if disburse_row else None,
|
|
amount=disburse_row.amount if disburse_row else None,
|
|
handlerName=_resolve_user_name(db, disburse_row.handler_id) if disburse_row else None,
|
|
disburseRemark=disburse_row.remark if disburse_row else None,
|
|
)
|
|
|
|
|
|
def list_disburse_board(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
*,
|
|
q: Optional[str] = None,
|
|
apply_status: Optional[str] = None,
|
|
apply_date_from: Optional[date] = None,
|
|
apply_date_to: Optional[date] = None,
|
|
disburse_date_from: Optional[date] = None,
|
|
disburse_date_to: Optional[date] = None,
|
|
ids: Optional[list[str]] = None,
|
|
page: int = 1,
|
|
page_size: int = 20,
|
|
max_page_size: Optional[int] = None,
|
|
) -> tuple[list[VehicleUreaDisburseBoardItem], int]:
|
|
query = (
|
|
db.query(PlVehicleUreaApply, PlVehicleUreaDisburse)
|
|
.outerjoin(
|
|
PlVehicleUreaDisburse,
|
|
and_(
|
|
PlVehicleUreaDisburse.apply_id == PlVehicleUreaApply.id,
|
|
PlVehicleUreaDisburse.tenant_no == tenant_no,
|
|
PlVehicleUreaDisburse.del_flag == 0,
|
|
),
|
|
)
|
|
.filter(
|
|
PlVehicleUreaApply.tenant_no == tenant_no,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
)
|
|
if q:
|
|
query = query.filter(
|
|
or_(
|
|
PlVehicleUreaApply.apply_no.contains(q),
|
|
PlVehicleUreaApply.license_plate.contains(q),
|
|
func.coalesce(PlVehicleUreaDisburse.disburse_no, "").contains(q),
|
|
)
|
|
)
|
|
if apply_status:
|
|
query = query.filter(PlVehicleUreaApply.status == apply_status)
|
|
if apply_date_from:
|
|
query = query.filter(PlVehicleUreaApply.apply_date >= apply_date_from)
|
|
if apply_date_to:
|
|
query = query.filter(PlVehicleUreaApply.apply_date <= apply_date_to)
|
|
if disburse_date_from:
|
|
query = query.filter(PlVehicleUreaDisburse.disburse_date >= disburse_date_from)
|
|
if disburse_date_to:
|
|
query = query.filter(PlVehicleUreaDisburse.disburse_date <= disburse_date_to)
|
|
|
|
if ids:
|
|
query = query.filter(PlVehicleUreaApply.id.in_(ids))
|
|
|
|
query = apply_pl_scope(query, PlVehicleUreaApply, user, db, tenant_no)
|
|
total = query.count()
|
|
page = max(1, page)
|
|
cap = int(max_page_size) if max_page_size else 500
|
|
page_size = min(max(1, page_size), cap)
|
|
rows = (
|
|
query.order_by(PlVehicleUreaApply.create_time.desc())
|
|
.offset((page - 1) * page_size)
|
|
.limit(page_size)
|
|
.all()
|
|
)
|
|
return [
|
|
board_item_to_read(apply_row, disburse_row, db)
|
|
for apply_row, disburse_row in rows
|
|
], total
|
|
|
|
|
|
def get_disburse(
|
|
db: Session, tenant_no: str, user: DbUserContext, disburse_id: str
|
|
) -> VehicleUreaDisburseRead:
|
|
row = _get_disburse_row(db, tenant_no, disburse_id, user)
|
|
return disburse_to_read(row, db)
|
|
|
|
|
|
def create_disburse(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
payload: VehicleUreaDisburseCreate,
|
|
) -> VehicleUreaDisburseRead:
|
|
apply_row, license_plate = _resolve_apply_for_disburse(db, tenant_no, payload, user)
|
|
handler_id = _resolve_user_id(db, tenant_no, payload.handler_id, user, field_label="处理人")
|
|
now = datetime.now()
|
|
row = PlVehicleUreaDisburse(
|
|
id=generate_uuid(),
|
|
disburse_no=generate_disburse_no(db),
|
|
apply_id=apply_row.id if apply_row else None,
|
|
license_plate=license_plate,
|
|
amount=payload.amount,
|
|
handler_id=handler_id,
|
|
disburse_date=payload.disburse_date,
|
|
attachment_urls=payload.attachment_urls,
|
|
tenant_no=tenant_no,
|
|
remark=payload.remark,
|
|
create_by=user.id,
|
|
create_dept_id=user.dept_id or "",
|
|
create_time=now,
|
|
update_by=user.id,
|
|
update_time=now,
|
|
del_flag=0,
|
|
)
|
|
db.add(row)
|
|
if apply_row:
|
|
apply_row.status = "disbursed"
|
|
apply_row.update_by = user.id
|
|
apply_row.update_time = now
|
|
db.commit()
|
|
db.refresh(row)
|
|
return disburse_to_read(row, db)
|
|
|
|
|
|
def update_disburse(
|
|
db: Session,
|
|
tenant_no: str,
|
|
user: DbUserContext,
|
|
disburse_id: str,
|
|
payload: VehicleUreaDisburseUpdate,
|
|
) -> VehicleUreaDisburseRead:
|
|
row = _get_disburse_row(db, tenant_no, disburse_id, user)
|
|
old_apply_id = row.apply_id
|
|
apply_row, license_plate = _resolve_apply_for_disburse(
|
|
db, tenant_no, payload, user, current_disburse_id=disburse_id
|
|
)
|
|
handler_id = _resolve_user_id(db, tenant_no, payload.handler_id, user, field_label="处理人")
|
|
now = datetime.now()
|
|
|
|
if old_apply_id and old_apply_id != (apply_row.id if apply_row else None):
|
|
old_apply = (
|
|
db.query(PlVehicleUreaApply)
|
|
.filter(
|
|
PlVehicleUreaApply.id == old_apply_id,
|
|
PlVehicleUreaApply.tenant_no == tenant_no,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if old_apply:
|
|
old_apply.status = "pending"
|
|
old_apply.update_by = user.id
|
|
old_apply.update_time = now
|
|
|
|
row.apply_id = apply_row.id if apply_row else None
|
|
row.license_plate = license_plate
|
|
row.amount = payload.amount
|
|
row.handler_id = handler_id
|
|
row.disburse_date = payload.disburse_date
|
|
row.attachment_urls = payload.attachment_urls
|
|
row.remark = payload.remark
|
|
row.update_by = user.id
|
|
row.update_time = now
|
|
|
|
if apply_row:
|
|
apply_row.status = "disbursed"
|
|
apply_row.update_by = user.id
|
|
apply_row.update_time = now
|
|
|
|
db.commit()
|
|
db.refresh(row)
|
|
return disburse_to_read(row, db)
|
|
|
|
|
|
def delete_disburses(
|
|
db: Session, tenant_no: str, user: DbUserContext, disburse_ids: list[str]
|
|
) -> None:
|
|
now = datetime.now()
|
|
for disburse_id in disburse_ids:
|
|
row = _get_disburse_row(db, tenant_no, disburse_id, user)
|
|
apply_id = row.apply_id
|
|
row.del_flag = 1
|
|
row.update_by = user.id
|
|
row.update_time = now
|
|
if apply_id:
|
|
apply = (
|
|
db.query(PlVehicleUreaApply)
|
|
.filter(
|
|
PlVehicleUreaApply.id == apply_id,
|
|
PlVehicleUreaApply.tenant_no == tenant_no,
|
|
PlVehicleUreaApply.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if apply and apply.status == "disbursed":
|
|
apply.status = "pending"
|
|
apply.update_by = user.id
|
|
apply.update_time = now
|
|
db.commit()
|