入库出库审核
This commit is contained in:
parent
40840446a4
commit
1bec31257e
|
@ -60,6 +60,7 @@ class FIFO(CommonAModel):
|
|||
(4, '生产入库')
|
||||
)
|
||||
type = models.IntegerField('出入库类型', default=1)
|
||||
is_audited = models.BooleanField('是否审核', default=False)
|
||||
warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='仓库')
|
||||
operator = models.ForeignKey(User, verbose_name='操作人', on_delete=models.CASCADE)
|
||||
subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.DO_NOTHING, null=True, blank=True)
|
||||
|
@ -71,6 +72,7 @@ class FIFODetail(BaseModel):
|
|||
"""
|
||||
出入库详细记录
|
||||
"""
|
||||
is_tested = models.BooleanField('是否检测', default=False)
|
||||
material = models.ForeignKey(Material, verbose_name='物料类型', on_delete=models.CASCADE)
|
||||
count = models.IntegerField('数量', default=0)
|
||||
batch = models.CharField('批次号', max_length=100, null=True, blank=True)
|
||||
|
|
|
@ -1,35 +1,39 @@
|
|||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from apps.inm.models import FIFODetail, Inventory, MaterialBatch
|
||||
from apps.inm.models import Inventory, MaterialBatch, FIFO, FIFODetail
|
||||
|
||||
|
||||
@receiver(post_save, sender=FIFODetail)
|
||||
def update_by_fifodetail(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
fifo = instance.fifo
|
||||
material = instance.material
|
||||
warehouse = fifo.warehouse
|
||||
if fifo.type in [3]: # 采购入库
|
||||
def update_inm(instance:FIFO, type:int):
|
||||
"""
|
||||
更新库存(正反)
|
||||
"""
|
||||
if instance.is_audited:
|
||||
warehouse = instance.warehouse
|
||||
if instance.type in [3]: # 采购入库
|
||||
# 更新相关表
|
||||
o1, _ = Inventory.objects.get_or_create(material=material, warehouse=warehouse, \
|
||||
defaults={'material':material, 'warehouse':warehouse, 'count':0})
|
||||
o1.count = o1.count + instance.count
|
||||
o1.save()
|
||||
o2, _ = MaterialBatch.objects.get_or_create(material=material, warehouse=warehouse, batch=instance.batch,\
|
||||
defaults={'material':material, 'warehouse':warehouse, 'count':0, 'batch':instance.batch})
|
||||
o2.count = o2.count + instance.count
|
||||
o2.save()
|
||||
material.count = material.count + instance.count
|
||||
material.save()
|
||||
elif fifo.type in [1]: # 生产领料
|
||||
for i in FIFODetail.objects.filter(fifo=instance):
|
||||
material = i.material
|
||||
o1, _ = Inventory.objects.get_or_create(material=material, warehouse=warehouse, \
|
||||
defaults={'material':material, 'warehouse':warehouse, 'count':0})
|
||||
o1.count = o1.count + i.count
|
||||
o1.save()
|
||||
o2, _ = MaterialBatch.objects.get_or_create(material=material, warehouse=warehouse, batch=i.batch,\
|
||||
defaults={'material':material, 'warehouse':warehouse, 'count':0, 'batch':i.batch})
|
||||
o2.count = o2.count + i.count
|
||||
o2.save()
|
||||
material.count = material.count + i.count
|
||||
material.save()
|
||||
elif instance.type in [1]: # 生产领料
|
||||
# 更新相关表
|
||||
o1 = Inventory.objects.get(material=material, warehouse=warehouse)
|
||||
o1.count = o1.count - instance.count
|
||||
o1.save()
|
||||
o2 = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=instance.batch)
|
||||
o2.count = o2.count - instance.count
|
||||
o2.save()
|
||||
material.count = material.count - instance.count
|
||||
material.save()
|
||||
for i in FIFODetail.objects.filter(fifo=instance):
|
||||
material = i.material
|
||||
o1 = Inventory.objects.get(material=material, warehouse=warehouse)
|
||||
o1.count = o1.count - i.count
|
||||
o1.save()
|
||||
o2 = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=i.batch)
|
||||
o2.count = o2.count - i.count
|
||||
o2.save()
|
||||
material.count = material.count - i.count
|
||||
material.save()
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
from django.shortcuts import render
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
|
||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||
from apps.inm.filters import MbFilterSet
|
||||
|
||||
from apps.inm.models import FIFO, FIFODetail, MaterialBatch, WareHouse,Inventory
|
||||
from apps.inm.serializers import FIFODetailSerializer, FIFOInPurSerializer, FIFOListSerializer, MaterialBatchQuerySerializer, MaterialBatchSerializer, WareHouseSerializer, WareHouseCreateUpdateSerializer,InventorySerializer
|
||||
from apps.inm.signals import update_inm
|
||||
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
@ -96,4 +98,18 @@ class FIFOViewSet(ListModelMixin, GenericViewSet):
|
|||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save(create_by=request.user)
|
||||
return Response()
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=serializers.Serializer)
|
||||
def audit(self, request, pk=None):
|
||||
"""
|
||||
审核通过
|
||||
"""
|
||||
obj = self.get_object()
|
||||
for i in FIFODetail.objects.filter(fifo=obj):
|
||||
if not i.is_tested:
|
||||
raise APIException('未检验通过, 不可审核')
|
||||
obj.is_audited = True
|
||||
obj.save()
|
||||
update_inm(obj) # 更新库存
|
||||
return Response()
|
||||
|
|
@ -38,4 +38,9 @@ class AnalysisItem(CommonAModel):
|
|||
rules =models.JSONField('判定规则', default=list)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '检验分析项'
|
||||
verbose_name = '检验分析项'
|
||||
|
||||
class TestRecord(CommonAModel):
|
||||
"""
|
||||
检验记录
|
||||
"""
|
Loading…
Reference in New Issue