物料消耗计算
This commit is contained in:
parent
cf8be1af3f
commit
5bae28fba6
|
@ -15,3 +15,10 @@ class ProductionPlanSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProductionPlan
|
model = ProductionPlan
|
||||||
fields ='__all__'
|
fields ='__all__'
|
||||||
|
|
||||||
|
class ResourceCalSerializer(serializers.Serializer):
|
||||||
|
id = serializers.IntegerField(label='产品ID')
|
||||||
|
count = serializers.IntegerField(label='生产数量')
|
||||||
|
|
||||||
|
class ResourceCalListSerializer(serializers.ListSerializer):
|
||||||
|
child = ResourceCalSerializer()
|
|
@ -1,4 +1,4 @@
|
||||||
from apps.pm.views import ProductionPlanViewSet
|
from apps.pm.views import ProductionPlanViewSet, ResourceViewSet
|
||||||
from django.db.models import base
|
from django.db.models import base
|
||||||
from rest_framework import urlpatterns
|
from rest_framework import urlpatterns
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
@ -6,7 +6,7 @@ from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register('productionplan', ProductionPlanViewSet, basename='productionplan')
|
router.register('productionplan', ProductionPlanViewSet, basename='productionplan')
|
||||||
|
router.register('resource', ResourceViewSet, basename='resource')
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
from apps.mtm.models import InputMaterial
|
||||||
from apps.system.mixins import CreateUpdateModelAMixin
|
from apps.system.mixins import CreateUpdateModelAMixin
|
||||||
from apps.pm.serializers import ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer
|
from apps.pm.serializers import ProductionPlanCreateFromOrderSerializer, ProductionPlanSerializer, ResourceCalListSerializer, ResourceCalSerializer
|
||||||
from rest_framework.mixins import CreateModelMixin, ListModelMixin
|
from rest_framework.mixins import CreateModelMixin, ListModelMixin
|
||||||
from apps.pm.models import ProductionPlan
|
from apps.pm.models import ProductionPlan
|
||||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||||
|
@ -8,6 +9,7 @@ from django.shortcuts import render
|
||||||
from apps.sam.models import Order
|
from apps.sam.models import Order
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.decorators import action
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
def updateOrderPlanedCount(order):
|
def updateOrderPlanedCount(order):
|
||||||
|
@ -52,5 +54,27 @@ class ProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, CreateModel
|
||||||
updateOrderPlanedCount(instance.order)
|
updateOrderPlanedCount(instance.order)
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
class ResourceCalculate(APIView):
|
class ResourceViewSet(GenericViewSet):
|
||||||
pass
|
|
||||||
|
perms_map = {'*': '*'}
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=False, perms_map={'get':'*'}, serializer_class=ResourceCalSerializer)
|
||||||
|
def cal(self, request, pk=None):
|
||||||
|
"""
|
||||||
|
物料消耗计算
|
||||||
|
"""
|
||||||
|
rdata = request.data
|
||||||
|
serializer = self.get_serializer(data=rdata, many=True)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
res = []
|
||||||
|
for i in rdata:
|
||||||
|
materials = InputMaterial.objects.filter(subproduction__product__id=i['id'],
|
||||||
|
subproduction__is_deleted=False, is_deleted=False, material__type__in=[3,4]).order_by('material__number')
|
||||||
|
for m in materials:
|
||||||
|
for x in res:
|
||||||
|
if x['id'] == m.material.id:
|
||||||
|
x['count'] = x['count'] + m.count*i['count']
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
res.append({'id':m.material.id, 'name':m.material.name, 'type':m.material.type, 'number':m.material.number, 'count':m.count*i['count']})
|
||||||
|
return Response(res)
|
||||||
|
|
|
@ -56,7 +56,7 @@ class FitJSONRenderer(JSONRenderer):
|
||||||
data = data[prefix]
|
data = data[prefix]
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
data = data[0]
|
data = data[0]
|
||||||
response_body.msg = prefix + ":" + data # 取一部分放入msg,方便前端alert
|
response_body.msg = prefix + ":" + str(data) # 取一部分放入msg,方便前端alert
|
||||||
else:
|
else:
|
||||||
response_body.data = data
|
response_body.data = data
|
||||||
renderer_context.get("response").status_code = 200 # 统一成200响应,用code区分
|
renderer_context.get("response").status_code = 200 # 统一成200响应,用code区分
|
||||||
|
|
Loading…
Reference in New Issue