fix: sort warehouse tree by name, fix tree batch delete cascade, and implement safe history location autofill
This commit is contained in:
@ -390,3 +390,21 @@ def get_location_suggestions():
|
||||
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||
data = BuyInboundService.get_history_locations(base_id)
|
||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 11. 获取最近一次入库的库位(跨表查询)
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_buy_bp.route('/last-location', methods=['GET'])
|
||||
@permission_required('inbound_buy')
|
||||
def get_last_location():
|
||||
"""
|
||||
获取指定物料最近一次入库的库位
|
||||
查询顺序:采购入库 -> 成品入库 -> 半成品入库,返回最新入库的库位
|
||||
"""
|
||||
base_id = request.args.get('base_id', type=int)
|
||||
if not base_id:
|
||||
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||
|
||||
location = BuyInboundService.get_last_location_by_base_id(base_id)
|
||||
return jsonify({"code": 200, "msg": "success", "data": {"location": location}})
|
||||
|
||||
@ -245,3 +245,21 @@ def calculate_bom_cost():
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 获取最近一次入库的库位(跨表查询)
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_product_bp.route('/last-location', methods=['GET'])
|
||||
@permission_required('inbound_product')
|
||||
def get_last_location():
|
||||
"""
|
||||
获取指定物料最近一次入库的库位
|
||||
查询顺序:成品入库 -> 采购入库 -> 半成品入库,返回最新入库的库位
|
||||
"""
|
||||
base_id = request.args.get('base_id', type=int)
|
||||
if not base_id:
|
||||
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||
|
||||
location = ProductInboundService.get_last_location_by_base_id(base_id)
|
||||
return jsonify({"code": 200, "msg": "success", "data": {"location": location}})
|
||||
|
||||
@ -240,3 +240,21 @@ def calculate_bom_cost():
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 获取最近一次入库的库位(跨表查询)
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_semi_bp.route('/last-location', methods=['GET'])
|
||||
@permission_required('inbound_semi')
|
||||
def get_last_location():
|
||||
"""
|
||||
获取指定物料最近一次入库的库位
|
||||
查询顺序:半成品入库 -> 采购入库 -> 成品入库,返回最新入库的库位
|
||||
"""
|
||||
base_id = request.args.get('base_id', type=int)
|
||||
if not base_id:
|
||||
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||
|
||||
location = SemiInboundService.get_last_location_by_base_id(base_id)
|
||||
return jsonify({"code": 200, "msg": "success", "data": {"location": location}})
|
||||
|
||||
@ -18,11 +18,15 @@ def build_tree(nodes, parent_id=None):
|
||||
children = build_tree(nodes, node.id)
|
||||
node_dict = node.to_dict()
|
||||
if children:
|
||||
node_dict['children'] = children
|
||||
# 子节点按 name 升序排序
|
||||
children_sorted = sorted(children, key=lambda x: x.get('name', ''))
|
||||
node_dict['children'] = children_sorted
|
||||
else:
|
||||
node_dict['children'] = []
|
||||
tree.append(node_dict)
|
||||
return tree
|
||||
# 当前层级按 name 升序排序
|
||||
tree_sorted = sorted(tree, key=lambda x: x.get('name', ''))
|
||||
return tree_sorted
|
||||
|
||||
|
||||
@warehouse_bp.route('/tree', methods=['GET'])
|
||||
@ -31,9 +35,9 @@ def get_tree():
|
||||
获取库位树形结构
|
||||
"""
|
||||
try:
|
||||
# 查询所有库位
|
||||
all_locations = SysWarehouseLocation.query.order_by(SysWarehouseLocation.level, SysWarehouseLocation.id).all()
|
||||
|
||||
# 查询所有库位,按 name 升序排序
|
||||
all_locations = SysWarehouseLocation.query.order_by(SysWarehouseLocation.name.asc()).all()
|
||||
|
||||
# 构建树形结构
|
||||
tree_data = build_tree(all_locations, parent_id=None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user