feat: 更新material的count
This commit is contained in:
parent
095eaabbb9
commit
0cd2802b04
|
@ -1,5 +1,6 @@
|
||||||
from apps.inm.models import MIO, MIOItem, MaterialBatch
|
from apps.inm.models import MIO, MIOItem, MaterialBatch
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
|
from django.db.models.aggregates import Sum
|
||||||
|
|
||||||
|
|
||||||
class InmService:
|
class InmService:
|
||||||
|
@ -39,4 +40,8 @@ class InmService:
|
||||||
mb.count = mb.count - i.count
|
mb.count = mb.count - i.count
|
||||||
if mb.count < 0:
|
if mb.count < 0:
|
||||||
raise ValidationError('批次库存不足,操作失败')
|
raise ValidationError('批次库存不足,操作失败')
|
||||||
mb.save()
|
mb.save()
|
||||||
|
else:
|
||||||
|
raise ValidationError('不支持的操作')
|
||||||
|
material.count = MaterialBatch.objects.filter(material=material).aggregate(total=Sum('count')).get('total', 0)
|
||||||
|
material.save()
|
Loading…
Reference in New Issue