fix(inbound/buy): 批号自增改为按物料精准取最近一条

- 新增 get_latest_batch_record_by_base_id:SQL 直接 filter(base_id)+order by in_date/id desc first(),O(1) 不分页
- 新增 GET /inbound/buy/latest-record
- 修复原“拉全表前1000条再前端过滤”导致的历史被截断→批号退回000001/重复入库被拦(如 CCAB0029)
This commit is contained in:
yueli
2026-09-08 18:16:04 +08:00
parent b4971f057e
commit 2b0e335790
2 changed files with 37 additions and 0 deletions

View File

@ -353,3 +353,18 @@ def get_last_location():
location = BuyInboundService.get_last_location_by_base_id(base_id)
return jsonify({"code": 200, "msg": "success", "data": {"location": location}})
@inbound_buy_bp.route('/latest-record', methods=['GET'])
@permission_required('inbound_buy')
def get_latest_batch_record():
"""
按物料精准取最近一次采购入库记录(批号自增用)。
返回 data: {'has_history': bool, 'mode': 'serial'|'batch', 'latest_batch': str}
"""
base_id = request.args.get('base_id', type=int)
if not base_id:
return jsonify({"code": 400, "msg": "base_id required"}), 400
data = BuyInboundService.get_latest_batch_record_by_base_id(base_id)
return jsonify({"code": 200, "msg": "success", "data": data})