fix: sort warehouse tree by name, fix tree batch delete cascade, and implement safe history location autofill

This commit is contained in:
DXC
2026-04-08 17:32:00 +08:00
parent c58a0a6d14
commit 4a4baa2f8f
11 changed files with 228 additions and 9 deletions

View File

@ -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)