|
@@ -263,13 +263,13 @@ class TaskRollbackMixin:
|
|
|
# 将批次状态恢复为未处理状态(假设原状态为1)
|
|
|
allocator.update_batch_status(batch.bound_number, '1')
|
|
|
|
|
|
- # ==================== 容器状态回滚 ====================
|
|
|
+ # ==================== 托盘状态回滚 ====================
|
|
|
container_obj = ContainerListModel.objects.get(container_code=container_code)
|
|
|
|
|
|
- # 恢复容器详细状态为初始状态(假设原状态为1)
|
|
|
+ # 恢复托盘详细状态为初始状态(假设原状态为1)
|
|
|
allocator.update_container_detail_status(container_code, 1)
|
|
|
|
|
|
- # 恢复容器的目标位置为当前所在位置
|
|
|
+ # 恢复托盘的目标位置为当前所在位置
|
|
|
container_obj.target_location = task.current_location
|
|
|
container_obj.save()
|
|
|
# ==================== 删除任务记录 ====================
|
|
@@ -330,7 +330,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
}
|
|
|
return Response(data_return, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
- # 更新容器数据(部分更新)
|
|
|
+ # 更新托盘数据(部分更新)
|
|
|
serializer = ContainerListPostSerializer(
|
|
|
container_obj,
|
|
|
data=data,
|
|
@@ -530,7 +530,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
if error_response:
|
|
|
return error_response
|
|
|
|
|
|
- # 更新容器数据
|
|
|
+ # 更新托盘数据
|
|
|
if not self.update_container_data(container_obj, data):
|
|
|
return Response(
|
|
|
{'code': '400', 'message': '数据更新失败', 'data': data},
|
|
@@ -561,7 +561,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
|
|
|
# ---------- 辅助函数 ----------
|
|
|
def validate_container(self, data):
|
|
|
- """验证容器是否存在"""
|
|
|
+ """验证托盘是否存在"""
|
|
|
container = data.get('container_number')
|
|
|
container_obj = ContainerListModel.objects.filter(container_code=container).first()
|
|
|
if not container_obj:
|
|
@@ -573,7 +573,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
return container_obj, None
|
|
|
|
|
|
def update_container_data(self, container_obj, data):
|
|
|
- """更新容器数据"""
|
|
|
+ """更新托盘数据"""
|
|
|
serializer = ContainerListPostSerializer(
|
|
|
container_obj,
|
|
|
data=data,
|
|
@@ -686,7 +686,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
return Response({'code': '400', 'message': '库位分配失败', 'data': data},
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
- # 生成目标位置并更新容器
|
|
|
+ # 生成目标位置并更新托盘
|
|
|
target_location = self.generate_target_location(location)
|
|
|
container_obj.target_location = target_location
|
|
|
container_obj.save()
|
|
@@ -792,7 +792,7 @@ class ContainerWCSViewSet(viewsets.ModelViewSet):
|
|
|
# 更新库位组的统计信息
|
|
|
self.handle_group_location_status(location_code, location.location_group)
|
|
|
|
|
|
- # 更新容器状态为已出库(假设状态3表示已出库)
|
|
|
+ # 更新托盘状态为已出库(假设状态3表示已出库)
|
|
|
container_obj.status = 3
|
|
|
container_obj.save()
|
|
|
|
|
@@ -922,21 +922,21 @@ class ContainerDetailViewSet(viewsets.ModelViewSet):
|
|
|
|
|
|
def containerdetail_list(self, request):
|
|
|
"""
|
|
|
- 获取容器详情列表
|
|
|
+ 获取托盘详情列表
|
|
|
"""
|
|
|
try:
|
|
|
container_id = request.query_params.get('container')
|
|
|
if not container_id:
|
|
|
return Response(
|
|
|
- {'code': 400, 'message': '缺少容器ID参数', 'data': None},
|
|
|
+ {'code': 400, 'message': '缺少托盘ID参数', 'data': None},
|
|
|
status=status.HTTP_400_BAD_REQUEST
|
|
|
)
|
|
|
- # 获取容器对象
|
|
|
+ # 获取托盘对象
|
|
|
try:
|
|
|
container = ContainerListModel.objects.get(id=container_id)
|
|
|
except ContainerListModel.DoesNotExist:
|
|
|
return Response(
|
|
|
- {'code': 404, 'message': '指定容器不存在', 'data': None},
|
|
|
+ {'code': 404, 'message': '指定托盘不存在', 'data': None},
|
|
|
status=status.HTTP_404_NOT_FOUND
|
|
|
)
|
|
|
|
|
@@ -969,16 +969,16 @@ class ContainerDetailViewSet(viewsets.ModelViewSet):
|
|
|
container_id = request.query_params.get('container')
|
|
|
if not container_id:
|
|
|
return Response(
|
|
|
- {'code': 400, 'message': '缺少容器ID参数', 'data': None},
|
|
|
+ {'code': 400, 'message': '缺少托盘ID参数', 'data': None},
|
|
|
status=status.HTTP_400_BAD_REQUEST
|
|
|
)
|
|
|
|
|
|
- # 获取容器对象
|
|
|
+ # 获取托盘对象
|
|
|
try:
|
|
|
container = ContainerListModel.objects.get(id=container_id)
|
|
|
except ContainerListModel.DoesNotExist:
|
|
|
return Response(
|
|
|
- {'code': 404, 'message': '指定容器不存在', 'data': None},
|
|
|
+ {'code': 404, 'message': '指定托盘不存在', 'data': None},
|
|
|
status=status.HTTP_404_NOT_FOUND
|
|
|
)
|
|
|
|
|
@@ -1069,7 +1069,7 @@ class ContainerDetailViewSet(viewsets.ModelViewSet):
|
|
|
|
|
|
def pdadetail_list(self, request):
|
|
|
"""
|
|
|
- 获取PDA组盘入库的容器详情列表
|
|
|
+ 获取PDA组盘入库的托盘详情列表
|
|
|
"""
|
|
|
try:
|
|
|
container_code = request.query_params.get('container_code')
|
|
@@ -1080,7 +1080,7 @@ class ContainerDetailViewSet(viewsets.ModelViewSet):
|
|
|
)
|
|
|
|
|
|
|
|
|
- # 获取容器对象
|
|
|
+ # 获取托盘对象
|
|
|
try:
|
|
|
container = ContainerListModel.objects.get(container_code=container_code)
|
|
|
except ContainerListModel.DoesNotExist:
|
|
@@ -1579,7 +1579,7 @@ class OutTaskViewSet(APIView):
|
|
|
|
|
|
def get_container_allocation(self, batch_id):
|
|
|
"""兼容所有数据库的去重方案"""
|
|
|
- # 获取唯一容器ID列表
|
|
|
+ # 获取唯一托盘ID列表
|
|
|
container_ids = (
|
|
|
ContainerDetailModel.objects
|
|
|
.filter(batch_id=batch_id, status=2,is_delete=False)
|
|
@@ -1587,7 +1587,7 @@ class OutTaskViewSet(APIView):
|
|
|
.distinct()
|
|
|
)
|
|
|
|
|
|
- # 获取每个容器的最新明细(按id倒序)
|
|
|
+ # 获取每个托盘的最新明细(按id倒序)
|
|
|
return (
|
|
|
ContainerDetailModel.objects
|
|
|
.filter(container_id__in=container_ids,batch_id=batch_id, status=2,is_delete=False)
|
|
@@ -1605,10 +1605,10 @@ class OutTaskViewSet(APIView):
|
|
|
return_data = []
|
|
|
|
|
|
for batch_id, demand in batch_demand.items():
|
|
|
- # 获取已去重的容器列表
|
|
|
+ # 获取已去重的托盘列表
|
|
|
container_qs = self.get_container_allocation(batch_id)
|
|
|
|
|
|
- # 构建容器信息字典(自动去重)
|
|
|
+ # 构建托盘信息字典(自动去重)
|
|
|
container_map = {}
|
|
|
for cd in container_qs:
|
|
|
if cd.container_id in container_map:
|
|
@@ -1692,7 +1692,7 @@ class OutTaskViewSet(APIView):
|
|
|
def _update_allocation_status(self, allocate_container, allocate_qty,bound_list_id):
|
|
|
"""事务化更新分配状态"""
|
|
|
try:
|
|
|
- # 更新容器明细
|
|
|
+ # 更新托盘明细
|
|
|
container_detail_all = ContainerDetailModel.objects.filter(
|
|
|
container_id=allocate_container['container_number'],
|
|
|
batch_id=allocate_container['batch_id'],
|
|
@@ -1852,15 +1852,15 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
return super().get_serializer_class()
|
|
|
|
|
|
def get_out_batch_detail(self, request):
|
|
|
- """获取某个容器的出库明细"""
|
|
|
+ """获取某个托盘的出库明细"""
|
|
|
try:
|
|
|
container_code = request.query_params.get('container_code')
|
|
|
container_obj = ContainerListModel.objects.filter(container_code=container_code).first()
|
|
|
if not container_obj:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
out_batch_detail_all = out_batch_detail.objects.filter(container=container_obj,working=1,is_delete=False).all()
|
|
|
if not out_batch_detail_all:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
serializer = OutBoundFullDetailSerializer(out_batch_detail_all, many=True)
|
|
|
return Response({"code": "200", "message": "Success", "data": serializer.data}, status=status.HTTP_200_OK)
|
|
|
except Exception as e:
|
|
@@ -1873,10 +1873,10 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
container_code = request.query_params.get('container_code')
|
|
|
container_obj = ContainerListModel.objects.filter(container_code=container_code).first()
|
|
|
if not container_obj:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
out_batch_detail_all = out_batch_detail.objects.filter(container=container_obj,working=1,is_delete=False).all()
|
|
|
if not out_batch_detail_all:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
for obj in out_batch_detail_all:
|
|
|
obj.working = 0
|
|
|
obj.save()
|
|
@@ -1887,7 +1887,7 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
goods_code = obj.container_detail.batch.goods_code,
|
|
|
goods_desc = obj.container_detail.batch.goods_desc,
|
|
|
goods_qty = obj.out_goods_qty,
|
|
|
- log_content = f"出库容器 {container_code} 批次 {obj.container_detail.batch.id} 数量 {obj.out_goods_qty} 重量 {obj.container_detail.batch.goods_weight} 到 {obj.to_location.location_code} 库位",
|
|
|
+ log_content = f"出库托盘 {container_code} 批次 {obj.container_detail.batch.id} 数量 {obj.out_goods_qty}",
|
|
|
creater = "WMS",
|
|
|
openid = "WMS"
|
|
|
|
|
@@ -1902,10 +1902,10 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
container_code = request.query_params.get('container_code')
|
|
|
container_obj = ContainerListModel.objects.filter(container_code=container_code).first()
|
|
|
if not container_obj:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
out_batch_detail_all = out_batch_detail.objects.filter(container=container_obj,working=1,is_delete=False).all()
|
|
|
if not out_batch_detail_all:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 无出库明细"}, status=status.HTTP_200_OK)
|
|
|
for obj in out_batch_detail_all:
|
|
|
obj.container_detail.goods_out_qty = obj.last_out_goods_qty
|
|
|
obj.container_detail.save()
|
|
@@ -1921,7 +1921,7 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
container_code = request.query_params.get('container_code')
|
|
|
container_obj = ContainerListModel.objects.filter(container_code=container_code).first()
|
|
|
if not container_obj:
|
|
|
- return Response({"code": "500", "message": f"容器 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
container_detail_all = ContainerDetailModel.objects.filter(container=container_obj,is_delete=False).all().exclude(status__in=[3])
|
|
|
return_data=[]
|
|
|
for obj in container_detail_all:
|
|
@@ -1935,4 +1935,21 @@ class OutDetailViewSet(viewsets.ModelViewSet):
|
|
|
})
|
|
|
return Response({"code": "200", "message": "Success", "data": return_data}, status=status.HTTP_200_OK)
|
|
|
except Exception as e:
|
|
|
- return Response({"code": "500", "message": str(e)}, status=status.HTTP_200_OK)
|
|
|
+ return Response({"code": "500", "message": str(e)}, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+ def change_container_out_qty(self, request):
|
|
|
+ try:
|
|
|
+ container_code = request.data.get('container_code')
|
|
|
+ container_obj = ContainerListModel.objects.filter(container_code=container_code).first()
|
|
|
+ if not container_obj:
|
|
|
+ return Response({"code": "500", "message": f"托盘 {container_code} 不存在"}, status=status.HTTP_200_OK)
|
|
|
+ for container_detail_id, out_qty in request.data.get('detail_list').items():
|
|
|
+ container_detail_obj = ContainerDetailModel.objects.filter(id=container_detail_id,is_delete=False).first()
|
|
|
+ if not container_detail_obj:
|
|
|
+ continue
|
|
|
+ container_detail_obj.goods_out_qty += out_qty
|
|
|
+ container_detail_obj.save()
|
|
|
+ return Response({"code": "200", "message": "Success"}, status=status.HTTP_200_OK)
|
|
|
+ except Exception as e:
|
|
|
+ return Response({"code": "500", "message": str(e)}, status=status.HTTP_200_OK)
|
|
|
+
|