feat: 采购申请完结功能移到批次主行,与出库审批一致

- 移除展开行内的单条完结按钮(需点开),改为主行'完结本批'直接可见
- 后端 batch-approve 支持 action=close(批次内已通过→已完结)
- 超管/库管在主行操作列即可看到并完结
This commit is contained in:
yueli
2026-09-01 16:21:48 +08:00
parent 8c554fdd3b
commit 4e09860b36
2 changed files with 39 additions and 7 deletions

View File

@ -273,20 +273,23 @@ def batch_approve_purchase():
action = data.get('action', 'approve')
reject_reason = data.get('reject_reason')
# 若传 batch_keyrequest_no 去掉末尾流水号的前缀),查出该批次所有待审批记录
# 若传 batch_keyrequest_no 去掉末尾流水号的前缀),查出该批次对应状态的记录
if batch_key:
from app.models.purchase import PurchaseRequest
# 完结本批 → 找「已通过(1)」的单;审批/驳回 → 找「待审批(0)」的单
target_status = 1 if action == 'close' else 0
records = PurchaseRequest.query.filter(
PurchaseRequest.request_no.like(f"{batch_key}-%"),
PurchaseRequest.status == 0
PurchaseRequest.status == target_status
).all()
ids = [r.id for r in records]
if not ids:
return jsonify({'code': 400, 'msg': '该批次没有待审批的记录'}), 400
status_text = '已通过' if action == 'close' else '待审批'
return jsonify({'code': 400, 'msg': f'该批次没有{status_text}的记录'}), 400
if not ids or not isinstance(ids, list):
return jsonify({'code': 400, 'msg': 'ids 或 batch_key 不能为空'}), 400
if action not in ('approve', 'reject'):
if action not in ('approve', 'reject', 'close'):
return jsonify({'code': 400, 'msg': '无效的审批操作'}), 400
if action == 'reject' and not reject_reason:
return jsonify({'code': 400, 'msg': '驳回时必须提供原因'}), 400