采购入库信号

This commit is contained in:
caoqianming 2021-10-28 09:46:26 +08:00
parent 39179e0cb6
commit 616ebdac4e
9 changed files with 46 additions and 4 deletions

View File

@ -4,4 +4,5 @@ class InmConfig(AppConfig):
name = 'apps.inm'
verbose_name = '库存管理'
def ready(self):
import apps.inm.signals

View File

@ -64,6 +64,7 @@ class FIFO(CommonAModel):
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)
inout_date = models.DateField('出入库日期')
remark = models.CharField('备注', max_length=1000, default='')
class FIFODetail(BaseModel):

View File

@ -81,4 +81,5 @@ class FIFOInPurSerializer(serializers.ModelSerializer):
IProduct.objects.bulk_create(p_list)
else:
serialier = FIFODetailInPurSerializer(data=i)
serialier.save(fifo=obj)
fifod = serialier.save(fifo=obj)

View File

@ -0,0 +1,24 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from apps.inm.models import FIFODetail, Inventory, MaterialBatch
@receiver(post_save, sender=FIFODetail)
def create_user(sender, instance, created, **kwargs):
if created:
fifo = instance.fifo
material = instance.material
warehouse = fifo.warehouse
if fifo.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.save()
material.count = material.count + 1
material.save()

View File

@ -54,7 +54,7 @@ class SubProductionPlan(CommonAModel):
class SubProductionProgress(BaseModel):
"""
子计划生产进度统计表
子计划生产进度统计表/物料消耗
"""
type_choices=(
(1, '输入物料'),
@ -65,3 +65,4 @@ class SubProductionProgress(BaseModel):
type = models.IntegerField('物料应用类型', default=1)
count = models.IntegerField('应出入数')
count_real = models.IntegerField('实际出入数', default=0)
count_current = models.IntegerField('当前数量', default=0)

View File

@ -43,4 +43,4 @@ class SubProductionProgressSerializer(serializers.ModelSerializer):
material_ = MaterialSimpleSerializer(source='material', read_only=True)
class Meta:
model = SubProductionProgress
fields = '__all__'
fields = '__all__'

View File

@ -136,6 +136,16 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo
obj.save()
return Response()
raise APIException('计划状态有误')
@action(methods=['get'], detail=True, perms_map={'get':'*'}, serializer_class=serializers.Serializer)
def pick_need(self, request, pk=None):
"""
领料需求清单
"""
obj = self.get_object()
instance = SubProductionProgress.objects.filter(subproduction_plan=obj, type=1)
serializer = SubProductionProgressSerializer(instance=instance, many=True)
return Response(serializer.data)
class ResourceViewSet(GenericViewSet):

View File

@ -2,6 +2,7 @@ from django.db import models
from django.db.models.base import Model
import django.utils.timezone as timezone
from django.db.models.query import QuerySet
from apps.pm.models import SubProductionPlan
from apps.system.models import CommonAModel, CommonBModel, Organization, User, Dict, File
from utils.model import SoftModel, BaseModel
from simple_history.models import HistoricalRecords
@ -22,6 +23,7 @@ class Product(CommonAModel):
act_state = models.IntegerField('进行状态', default=0)
parent = models.ForeignKey('self', verbose_name='上一级', on_delete=models.CASCADE, db_constraint=False)
remark = models.CharField('备注', max_length=200, null=True, blank=True)
subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.CASCADE)
class ProductForm(CommonAModel):
"""

View File

@ -1,2 +1,4 @@
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer