|
@@ -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):
|
|
|
"""更新批次的统计数据"""
|