采购入库信号
This commit is contained in:
parent
39179e0cb6
commit
616ebdac4e
|
@ -4,4 +4,5 @@ class InmConfig(AppConfig):
|
||||||
name = 'apps.inm'
|
name = 'apps.inm'
|
||||||
verbose_name = '库存管理'
|
verbose_name = '库存管理'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import apps.inm.signals
|
||||||
|
|
|
@ -64,6 +64,7 @@ class FIFO(CommonAModel):
|
||||||
operator = models.ForeignKey(User, verbose_name='操作人', on_delete=models.CASCADE)
|
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)
|
subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.DO_NOTHING, null=True, blank=True)
|
||||||
inout_date = models.DateField('出入库日期')
|
inout_date = models.DateField('出入库日期')
|
||||||
|
remark = models.CharField('备注', max_length=1000, default='')
|
||||||
|
|
||||||
|
|
||||||
class FIFODetail(BaseModel):
|
class FIFODetail(BaseModel):
|
||||||
|
|
|
@ -81,4 +81,5 @@ class FIFOInPurSerializer(serializers.ModelSerializer):
|
||||||
IProduct.objects.bulk_create(p_list)
|
IProduct.objects.bulk_create(p_list)
|
||||||
else:
|
else:
|
||||||
serialier = FIFODetailInPurSerializer(data=i)
|
serialier = FIFODetailInPurSerializer(data=i)
|
||||||
serialier.save(fifo=obj)
|
fifod = serialier.save(fifo=obj)
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -54,7 +54,7 @@ class SubProductionPlan(CommonAModel):
|
||||||
|
|
||||||
class SubProductionProgress(BaseModel):
|
class SubProductionProgress(BaseModel):
|
||||||
"""
|
"""
|
||||||
子计划生产进度统计表
|
子计划生产进度统计表/物料消耗
|
||||||
"""
|
"""
|
||||||
type_choices=(
|
type_choices=(
|
||||||
(1, '输入物料'),
|
(1, '输入物料'),
|
||||||
|
@ -65,3 +65,4 @@ class SubProductionProgress(BaseModel):
|
||||||
type = models.IntegerField('物料应用类型', default=1)
|
type = models.IntegerField('物料应用类型', default=1)
|
||||||
count = models.IntegerField('应出入数')
|
count = models.IntegerField('应出入数')
|
||||||
count_real = models.IntegerField('实际出入数', default=0)
|
count_real = models.IntegerField('实际出入数', default=0)
|
||||||
|
count_current = models.IntegerField('当前数量', default=0)
|
||||||
|
|
|
@ -43,4 +43,4 @@ class SubProductionProgressSerializer(serializers.ModelSerializer):
|
||||||
material_ = MaterialSimpleSerializer(source='material', read_only=True)
|
material_ = MaterialSimpleSerializer(source='material', read_only=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SubProductionProgress
|
model = SubProductionProgress
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
|
@ -136,6 +136,16 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo
|
||||||
obj.save()
|
obj.save()
|
||||||
return Response()
|
return Response()
|
||||||
raise APIException('计划状态有误')
|
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):
|
class ResourceViewSet(GenericViewSet):
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.db import models
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
import django.utils.timezone as timezone
|
import django.utils.timezone as timezone
|
||||||
from django.db.models.query import QuerySet
|
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 apps.system.models import CommonAModel, CommonBModel, Organization, User, Dict, File
|
||||||
from utils.model import SoftModel, BaseModel
|
from utils.model import SoftModel, BaseModel
|
||||||
from simple_history.models import HistoricalRecords
|
from simple_history.models import HistoricalRecords
|
||||||
|
@ -22,6 +23,7 @@ class Product(CommonAModel):
|
||||||
act_state = models.IntegerField('进行状态', default=0)
|
act_state = models.IntegerField('进行状态', default=0)
|
||||||
parent = models.ForeignKey('self', verbose_name='上一级', on_delete=models.CASCADE, db_constraint=False)
|
parent = models.ForeignKey('self', verbose_name='上一级', on_delete=models.CASCADE, db_constraint=False)
|
||||||
remark = models.CharField('备注', max_length=200, null=True, blank=True)
|
remark = models.CharField('备注', max_length=200, null=True, blank=True)
|
||||||
|
subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联子生产计划', on_delete=models.CASCADE)
|
||||||
|
|
||||||
class ProductForm(CommonAModel):
|
class ProductForm(CommonAModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
from rest_framework import serializers
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue