销售出库审核
This commit is contained in:
parent
588102a411
commit
947f8088fc
|
@ -95,6 +95,13 @@ class FIFOItemCreateSerializer(serializers.ModelSerializer):
|
||||||
if fifo.pu_order is not None:
|
if fifo.pu_order is not None:
|
||||||
raise ValidationError('非采购订单')
|
raise ValidationError('非采购订单')
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
def validate_batch(self, value):
|
||||||
|
if value == '':
|
||||||
|
return value
|
||||||
|
elif len(value) > 6:
|
||||||
|
return value
|
||||||
|
raise ValidationError('批次号错误')
|
||||||
|
|
||||||
class FIFOItemUpdateSerializer(serializers.ModelSerializer):
|
class FIFOItemUpdateSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -122,6 +129,13 @@ class FIFODetailInPurSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FIFOItem
|
model = FIFOItem
|
||||||
fields = ['material', 'count', 'batch', 'details', 'warehouse']
|
fields = ['material', 'count', 'batch', 'details', 'warehouse']
|
||||||
|
|
||||||
|
def validate_batch(self, value):
|
||||||
|
if value == '':
|
||||||
|
return value
|
||||||
|
elif len(value) > 6:
|
||||||
|
return value
|
||||||
|
raise ValidationError('批次号错误')
|
||||||
|
|
||||||
|
|
||||||
class MaterialBatchQuerySerializer(serializers.Serializer):
|
class MaterialBatchQuerySerializer(serializers.Serializer):
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from apps.inm.models import FIFOItemProduct, IProduct, Inventory, MaterialBatch, FIFO, FIFOItem
|
from sqlalchemy import true
|
||||||
|
from apps.inm.models import FIFOItemProduct, IProduct, Inventory, MaterialBatch, FIFO, FIFOItem, WareHouse
|
||||||
|
from apps.mtm.models import Material
|
||||||
|
from apps.sam.models import SalePack, SaleProduct
|
||||||
|
from django.db.models import Count
|
||||||
class InmService:
|
class InmService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_inm(cls, instance:FIFO, type:int=1):
|
def update_inm(cls, instance:FIFO, type:int=1):
|
||||||
|
@ -72,4 +75,60 @@ class InmService:
|
||||||
if instance.type == FIFO.FIFO_TYPE_DO_OUT:
|
if instance.type == FIFO.FIFO_TYPE_DO_OUT:
|
||||||
# 生产领料的情况直接从IProduct中删除
|
# 生产领料的情况直接从IProduct中删除
|
||||||
numbers = FIFOItemProduct.objects.filter(fifoitem=i).values_list('number', flat=True)
|
numbers = FIFOItemProduct.objects.filter(fifoitem=i).values_list('number', flat=True)
|
||||||
IProduct.objects.filter(number__in=numbers).delete()
|
IProduct.objects.filter(number__in=numbers).delete()
|
||||||
|
# 销售的话已经处理了
|
||||||
|
# elif instance.type == FIFO.FIFO_TYPE_SALE_OUT:
|
||||||
|
# ips = FIFOItemProduct.objects.filter(fifoitem=i).values_list('iproduct', flat=True)
|
||||||
|
# IProduct.objects.filter(id__in=ips).update(state=IProduct.SALED)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def sale_out_audit(cls, fifo:FIFO):
|
||||||
|
sale = fifo.sale
|
||||||
|
saleps = SaleProduct.objects.filter(sale=sale, packnum__isnull=True, remark__isnull=True)
|
||||||
|
if saleps.exists():
|
||||||
|
raise ValidationError('存在未装箱的产品')
|
||||||
|
# 创建出库条目
|
||||||
|
ips = IProduct.objects.filter(sale_iproduct__sale=sale
|
||||||
|
).exclude(sale_iproduct__packnum__isnull=True)
|
||||||
|
ips.update(state=IProduct.SALED)
|
||||||
|
items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id'))
|
||||||
|
for i in items:
|
||||||
|
warehouse = WareHouse.objects.get(id=i['warehouse'])
|
||||||
|
material = Material.objects.get(id=i['material'])
|
||||||
|
fifoitem = FIFOItem()
|
||||||
|
fifoitem.need_test = False
|
||||||
|
fifoitem.warehouse = warehouse
|
||||||
|
fifoitem.material = material
|
||||||
|
fifoitem.count = i['total']
|
||||||
|
fifoitem.batch = i['batch']
|
||||||
|
fifoitem.fifo = fifo
|
||||||
|
fifoitem.save()
|
||||||
|
items_p = ips.filter(warehouse=warehouse, batch=i['batch'])
|
||||||
|
ipxs = []
|
||||||
|
for i in items_p:
|
||||||
|
# 创建出库明细半成品
|
||||||
|
ip = {}
|
||||||
|
ip['fifoitem'] = fifoitem
|
||||||
|
ip['number'] = i.number
|
||||||
|
ip['material'] = i.material
|
||||||
|
ip['iproduct'] = i
|
||||||
|
ipxs.append(FIFOItemProduct(**ip))
|
||||||
|
FIFOItemProduct.objects.bulk_create(ipxs)
|
||||||
|
# 装箱附件处理
|
||||||
|
# SalePack.objects.filter(sale_product__in = saleps)
|
||||||
|
|
||||||
|
|
||||||
|
# 更新动态产品表情况
|
||||||
|
from apps.wpm.models import WProduct
|
||||||
|
WProduct.objects.filter(iproduct_wproduct__sale_iproduct__sale=sale).update(
|
||||||
|
act_state=WProduct.WPR_ACT_STATE_SELLED)
|
||||||
|
|
||||||
|
# 变更销售记录实际发货数
|
||||||
|
sale.count_real = ips.count()
|
||||||
|
sale.save()
|
||||||
|
# 变更订单状态
|
||||||
|
order = sale.order
|
||||||
|
if order:
|
||||||
|
order.delivered_count = IProduct.objects.filter(sale_iproduct__sale__order=order
|
||||||
|
).exclude(sale_iproduct__packnum__isnull=True).count()
|
||||||
|
order.save()
|
|
@ -184,11 +184,14 @@ class FIFOViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet):
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
@action(methods=['post'], detail=True, perms_map={'post': 'fifo_audit'}, serializer_class=serializers.Serializer)
|
@action(methods=['post'], detail=True, perms_map={'post': 'fifo_audit'}, serializer_class=serializers.Serializer)
|
||||||
|
@transaction.atomic
|
||||||
def audit(self, request, pk=None):
|
def audit(self, request, pk=None):
|
||||||
"""
|
"""
|
||||||
审核通过
|
审核通过
|
||||||
"""
|
"""
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
|
if obj.type == FIFO.FIFO_TYPE_SALE_OUT: # 如果是销售提货,需额外处理
|
||||||
|
pass
|
||||||
if not FIFOItem.objects.filter(fifo=obj).exists():
|
if not FIFOItem.objects.filter(fifo=obj).exists():
|
||||||
raise ValidationError('出入库条目为空')
|
raise ValidationError('出入库条目为空')
|
||||||
for i in FIFOItem.objects.filter(fifo=obj, need_test=True):
|
for i in FIFOItem.objects.filter(fifo=obj, need_test=True):
|
||||||
|
@ -196,12 +199,11 @@ class FIFOViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet):
|
||||||
raise APIException('未检验通过, 不可审核')
|
raise APIException('未检验通过, 不可审核')
|
||||||
if obj.is_audited:
|
if obj.is_audited:
|
||||||
raise APIException('该入库记录已审核通过')
|
raise APIException('该入库记录已审核通过')
|
||||||
with transaction.atomic():
|
obj.is_audited = True
|
||||||
obj.is_audited = True
|
obj.auditor = request.user
|
||||||
obj.auditor = request.user
|
obj.inout_date = timezone.now() # 也是审核日期
|
||||||
obj.inout_date = timezone.now() # 也是审核日期
|
obj.save()
|
||||||
obj.save()
|
InmService.update_inm(obj) # 更新库存
|
||||||
InmService.update_inm(obj) # 更新库存
|
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,11 @@ class SPackItemCreateSerializer(serializers.Serializer):
|
||||||
|
|
||||||
class SaleProductPackSerializer(serializers.ModelSerializer):
|
class SaleProductPackSerializer(serializers.ModelSerializer):
|
||||||
detail = SPackItemCreateSerializer(many=True)
|
detail = SPackItemCreateSerializer(many=True)
|
||||||
|
packnum = serializers.CharField(min_length=6)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SaleProduct
|
model = SaleProduct
|
||||||
fields = ['packnum', 'detail', 'remark']
|
fields = ['packnum', 'detail', 'remark']
|
||||||
|
|
||||||
|
|
||||||
class SRemarkItemCreateSerializer(serializers.Serializer):
|
class SRemarkItemCreateSerializer(serializers.Serializer):
|
||||||
remark = serializers.CharField()
|
remark = serializers.CharField(min_length=6)
|
||||||
|
|
|
@ -89,46 +89,10 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C
|
||||||
fifo.create_by = request.user
|
fifo.create_by = request.user
|
||||||
fifo.number = 'CK' + ranstr(7)
|
fifo.number = 'CK' + ranstr(7)
|
||||||
fifo.save()
|
fifo.save()
|
||||||
# 创建出库条目
|
|
||||||
# ips = IProduct.objects.filter(sale_iproduct__sale=obj)
|
|
||||||
# items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id'))
|
|
||||||
# for i in items:
|
|
||||||
# warehouse = WareHouse.objects.get(id=i['warehouse'])
|
|
||||||
# material = Material.objects.get(id=i['material'])
|
|
||||||
# fifoitem = FIFOItem()
|
|
||||||
# fifoitem.need_test = False
|
|
||||||
# fifoitem.warehouse = warehouse
|
|
||||||
# fifoitem.material = material
|
|
||||||
# fifoitem.count = i['total']
|
|
||||||
# fifoitem.batch = i['batch']
|
|
||||||
# fifoitem.fifo = fifo
|
|
||||||
# fifoitem.save()
|
|
||||||
# items_p = ips.filter(warehouse=warehouse, batch=i['batch'])
|
|
||||||
# ipxs = []
|
|
||||||
# for i in items_p:
|
|
||||||
# # 创建出库明细半成品
|
|
||||||
# ip = {}
|
|
||||||
# ip['fifoitem'] = fifoitem
|
|
||||||
# ip['number'] = i.number
|
|
||||||
# ip['material'] = i.material
|
|
||||||
# ip['iproduct'] = i
|
|
||||||
# ipxs.append(FIFOItemProduct(**ip))
|
|
||||||
# FIFOItemProduct.objects.bulk_create(ipxs)
|
|
||||||
|
|
||||||
# 更新动态产品表情况
|
|
||||||
# from apps.wpm.models import WProduct
|
|
||||||
# WProduct.objects.filter(iproduct_wproduct__sale_iproduct__sale=obj).update(
|
|
||||||
# act_state=WProduct.WPR_ACT_STATE_SELLED)
|
|
||||||
# 更新库存
|
|
||||||
# InmService.update_inm(fifo)
|
|
||||||
# 变更销售提货审核状态
|
|
||||||
obj.is_audited = True
|
obj.is_audited = True
|
||||||
obj.save()
|
obj.save()
|
||||||
# 变更订单状态
|
|
||||||
# if obj.order:
|
|
||||||
# order = obj.order
|
|
||||||
# order.delivered_count = order.delivered_count + obj.count
|
|
||||||
# order.save()
|
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue