|
@@ -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
|
|
|
+
|
|
|
+
|
|
|
+ details.exclude(goods_class=new_class).update(goods_class=new_class)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if self.goods_class != new_class:
|
|
|
+ self.goods_class = new_class
|
|
|
+ super().save(update_fields=['goods_class'])
|
|
|
|
|
|
def update_batch_stats(self):
|
|
|
"""更新批次的统计数据"""
|