Browse Source

托盘更新

flower_mr 1 ngày trước cách đây
mục cha
commit
3f76e44eb3
4 tập tin đã thay đổi với 4480 bổ sung4 xóa
  1. 0 3
      bin/queries.py
  2. 23 1
      container/models.py
  3. 2097 0
      logs/error.log
  4. 2360 0
      logs/server.log

+ 0 - 3
bin/queries.py

@@ -75,9 +75,6 @@ class LocationQueries:
             # 统计该拖盘上的不同批次数目
             batch_count =  len(set([item.batch.id for item in detail_all]))
             if batch_count > 1:
-                for item in detail_all:
-                    item.goods_class = 3
-                    item.save()
                 return {
                     'status': None,
                     'number': 'ContainerScattered'+str(container_code)+str(timezone.now().strftime('%Y%m%d')),

+ 23 - 1
container/models.py

@@ -90,7 +90,7 @@ class ContainerDetailModel(models.Model):
         # 更新批次数据
         if self.batch:
             # 避免循环更新 - 仅在数量相关字段变更时才更新
-            if 'update_fields' not in kwargs or any(field in kwargs['update_fields'] for field in ['goods_qty', 'goods_out_qty']):
+            if 'update_fields' not in kwargs or any(field in kwargs['update_fields'] for field in ['goods_qty', 'goods_out_qty','is_delete']):
                 self.update_batch_stats()
             
             # # 根据出库数量更新状态
@@ -112,6 +112,28 @@ class ContainerDetailModel(models.Model):
             if self.status == 3 and self.goods_qty - self.goods_out_qty > 0 :
                 self.status = 2  # 在库
                 super().save(*args, **kwargs)
+
+
+             # 更新货物分类(关键修改点)
+            if not kwargs.get('skip_class_update', False):
+                # 获取托盘上所有物料(排除已删除和已出库的)
+                details = ContainerDetailModel.objects.filter(
+                    container=self.container.id,
+                    is_delete=False
+                ).exclude(status=3)
+                
+                # 统计不同批次数目
+                batch_count = details.values('batch').distinct().count()
+                new_class = 1 if batch_count == 1 else 3
+                
+                # 批量更新所有相关物料的goods_class
+                details.exclude(goods_class=new_class).update(goods_class=new_class)
+                
+                # 如果当前物料的class需要更新
+           
+                if self.goods_class != new_class:
+                    self.goods_class = new_class
+                    super().save(update_fields=['goods_class'])
     
     def update_batch_stats(self):
         """更新批次的统计数据"""

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2097 - 0
logs/error.log


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2360 - 0
logs/server.log