销售记录删除bug
This commit is contained in:
parent
fbebb176aa
commit
7d715146a2
|
@ -55,18 +55,19 @@ class InmService:
|
||||||
o1 = Inventory.objects.get(material=material, warehouse=warehouse)
|
o1 = Inventory.objects.get(material=material, warehouse=warehouse)
|
||||||
temp_count = o1.count - i.count
|
temp_count = o1.count - i.count
|
||||||
if temp_count < 0:
|
if temp_count < 0:
|
||||||
raise ValidationError('库存不足,操作失败')
|
raise ValidationError('仓库库存不足,操作失败')
|
||||||
o1.count = temp_count
|
o1.count = temp_count
|
||||||
o1.save()
|
o1.save()
|
||||||
|
print(i.batch)
|
||||||
o2 = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=i.batch)
|
o2 = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=i.batch)
|
||||||
temp_count = o2.count - i.count
|
temp_count = o2.count - i.count
|
||||||
if temp_count < 0:
|
if temp_count < 0:
|
||||||
raise ValidationError('库存不足,操作失败')
|
raise ValidationError('批次库存不足,操作失败')
|
||||||
o2.count = temp_count
|
o2.count = temp_count
|
||||||
o2.save()
|
o2.save()
|
||||||
temp_count = material.count - i.count
|
temp_count = material.count - i.count
|
||||||
if temp_count < 0:
|
if temp_count < 0:
|
||||||
raise ValidationError('库存不足,操作失败')
|
raise ValidationError('物料库存不足,操作失败')
|
||||||
material.count = temp_count
|
material.count = temp_count
|
||||||
material.save()
|
material.save()
|
||||||
|
|
||||||
|
@ -87,8 +88,8 @@ class InmService:
|
||||||
if saleps.exists():
|
if saleps.exists():
|
||||||
raise ValidationError('存在未装箱的产品')
|
raise ValidationError('存在未装箱的产品')
|
||||||
# 创建出库条目
|
# 创建出库条目
|
||||||
ips = IProduct.objects.filter(sale_iproduct__sale=sale
|
ips = IProduct.objects.filter(sale_iproduct__sale=sale,
|
||||||
).exclude(sale_iproduct__packnum__isnull=True)
|
sale_iproduct__packnum__isnull=False)
|
||||||
ips.update(state=IProduct.SALED)
|
ips.update(state=IProduct.SALED)
|
||||||
items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id'))
|
items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id'))
|
||||||
for i in items:
|
for i in items:
|
||||||
|
@ -119,7 +120,7 @@ class InmService:
|
||||||
|
|
||||||
# 更新动态产品表情况
|
# 更新动态产品表情况
|
||||||
from apps.wpm.models import WProduct
|
from apps.wpm.models import WProduct
|
||||||
WProduct.objects.filter(iproduct_wproduct__sale_iproduct__sale=sale).update(
|
WProduct.objects.filter(id__in=ips.values_list('wproduct', flat=True)).update(
|
||||||
act_state=WProduct.WPR_ACT_STATE_SELLED)
|
act_state=WProduct.WPR_ACT_STATE_SELLED)
|
||||||
|
|
||||||
# 变更销售记录实际发货数
|
# 变更销售记录实际发货数
|
||||||
|
@ -129,5 +130,5 @@ class InmService:
|
||||||
order = sale.order
|
order = sale.order
|
||||||
if order:
|
if order:
|
||||||
order.delivered_count = IProduct.objects.filter(sale_iproduct__sale__order=order
|
order.delivered_count = IProduct.objects.filter(sale_iproduct__sale__order=order
|
||||||
).exclude(sale_iproduct__packnum__isnull=True).count()
|
, sale_iproduct__packnum__isnull=False).count()
|
||||||
order.save()
|
order.save()
|
|
@ -42,7 +42,8 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C
|
||||||
if obj.is_audited:
|
if obj.is_audited:
|
||||||
raise exceptions.APIException('该销售记录已审核,不可删除')
|
raise exceptions.APIException('该销售记录已审核,不可删除')
|
||||||
obj.delete()
|
obj.delete()
|
||||||
IProduct.objects.filter(sale_iproduct__sale=obj).update()
|
IProduct.objects.filter(sale_iproduct__sale=obj).update(state=IProduct.SALE_OK)
|
||||||
|
return Response()
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
Loading…
Reference in New Issue