提交军检接口
This commit is contained in:
parent
e83c5ff59f
commit
332c4b7729
|
|
@ -2,7 +2,6 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, MaterialBatch, WareHouse,Inventory
|
from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, MaterialBatch, WareHouse,Inventory
|
||||||
from apps.qm.models import TestRecord, TestRecordItem
|
from apps.qm.models import TestRecord, TestRecordItem
|
||||||
from apps.sam.serializers import OrderSimpleSerializer
|
|
||||||
|
|
||||||
from apps.system.serializers import UserSimpleSerializer
|
from apps.system.serializers import UserSimpleSerializer
|
||||||
from apps.mtm.serializers import MaterialSimpleSerializer
|
from apps.mtm.serializers import MaterialSimpleSerializer
|
||||||
|
|
@ -41,18 +40,10 @@ class MaterialBatchSerializer(serializers. ModelSerializer):
|
||||||
class IProductListSerializer(serializers.ModelSerializer):
|
class IProductListSerializer(serializers.ModelSerializer):
|
||||||
material_= MaterialSimpleSerializer(source='material', read_only=True)
|
material_= MaterialSimpleSerializer(source='material', read_only=True)
|
||||||
warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True)
|
warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True)
|
||||||
order_ = serializers.SerializerMethodField()
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IProduct
|
model = IProduct
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
def get_order_(self, obj):
|
|
||||||
if obj.wproduct:
|
|
||||||
order = obj.wproduct.subproduction_plan.production_plan.order
|
|
||||||
if order:
|
|
||||||
return OrderSimpleSerializer(instance=order).data
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class FIFOListSerializer(serializers.ModelSerializer):
|
class FIFOListSerializer(serializers.ModelSerializer):
|
||||||
auditor_ = UserSimpleSerializer(source='auditor', read_only=True)
|
auditor_ = UserSimpleSerializer(source='auditor', read_only=True)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.9 on 2021-12-06 05:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('sam', '0006_auto_20211206_0958'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='saleproduct',
|
||||||
|
name='remark',
|
||||||
|
field=models.TextField(blank=True, null=True, verbose_name='备注'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -94,6 +94,7 @@ class SaleProduct(BaseModel):
|
||||||
iproduct = models.ForeignKey('inm.iproduct', verbose_name='关联库存产品', on_delete=models.CASCADE, related_name='sale_iproduct')
|
iproduct = models.ForeignKey('inm.iproduct', verbose_name='关联库存产品', on_delete=models.CASCADE, related_name='sale_iproduct')
|
||||||
is_mtested = models.BooleanField('是否军检', default=False)
|
is_mtested = models.BooleanField('是否军检', default=False)
|
||||||
is_mtestok = models.BooleanField('是否军检合格', default=True)
|
is_mtestok = models.BooleanField('是否军检合格', default=True)
|
||||||
|
remark = models.TextField('备注', null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (
|
unique_together = (
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from django.db import transaction
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from apps.inm.models import IProduct
|
from apps.inm.models import IProduct
|
||||||
|
from apps.inm.serializers import IProductListSerializer
|
||||||
|
|
||||||
from .models import Contract, Customer, Order, Sale, SaleProduct
|
from .models import Contract, Customer, Order, Sale, SaleProduct
|
||||||
|
|
||||||
|
|
@ -94,3 +95,23 @@ class SaleListSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Sale
|
model = Sale
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class SaleProductListSerializer(serializers.ModelSerializer):
|
||||||
|
iproduct_ = IProductListSerializer(source='iproduct', read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = SaleProduct
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class SaleProductCreateSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SaleProduct
|
||||||
|
fields = ['sale', 'iproduct']
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
validated_data['number'] = validated_data['iproduct'].number
|
||||||
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
class SaleProductMtestSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SaleProduct
|
||||||
|
fields = ['remark', 'is_mtestok']
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
|
from rest_framework import exceptions
|
||||||
from apps.sam.serializers import ContractCreateUpdateSerializer, ContractSerializer, CustomerCreateUpdateSerializer, CustomerSerializer, OrderCreateUpdateSerializer, OrderSerializer, SaleCreateSerializer, SaleListSerializer
|
from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
|
||||||
from apps.sam.models import Contract, Customer, Order, Sale
|
from apps.sam.serializers import ContractCreateUpdateSerializer, ContractSerializer, CustomerCreateUpdateSerializer, CustomerSerializer, OrderCreateUpdateSerializer, OrderSerializer, SaleCreateSerializer, SaleListSerializer, SaleProductCreateSerializer, SaleProductListSerializer
|
||||||
|
from apps.sam.models import Contract, Customer, Order, Sale, SaleProduct
|
||||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||||
from apps.system.mixins import CreateUpdateCustomMixin
|
from apps.system.mixins import CreateUpdateCustomMixin
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
@ -76,7 +77,7 @@ class SaleViewSet(CreateUpdateCustomMixin, ListModelMixin, RetrieveModelMixin, C
|
||||||
销售记录
|
销售记录
|
||||||
"""
|
"""
|
||||||
perms_map = {'*': '*'}
|
perms_map = {'*': '*'}
|
||||||
queryset = Sale.objects.select_related('customer', 'order', 'product').all()
|
queryset = Sale.objects.select_related('customer', 'order', 'product', 'order__contract').all()
|
||||||
serializer_class = SaleListSerializer
|
serializer_class = SaleListSerializer
|
||||||
search_fields = ['customer__name', 'order__number']
|
search_fields = ['customer__name', 'order__number']
|
||||||
filterset_fields = ['product', 'order', 'customer']
|
filterset_fields = ['product', 'order', 'customer']
|
||||||
|
|
@ -88,4 +89,34 @@ class SaleViewSet(CreateUpdateCustomMixin, ListModelMixin, RetrieveModelMixin, C
|
||||||
return SaleCreateSerializer
|
return SaleCreateSerializer
|
||||||
elif self.action == 'retrieve':
|
elif self.action == 'retrieve':
|
||||||
return SaleListSerializer
|
return SaleListSerializer
|
||||||
return super().get_serializer_class()
|
return super().get_serializer_class()
|
||||||
|
|
||||||
|
class SaleProductViewSet(ListModelMixin, DestroyModelMixin, CreateModelMixin, GenericViewSet):
|
||||||
|
"""
|
||||||
|
销售记录关联产品
|
||||||
|
"""
|
||||||
|
perms_map = {'*': '*'}
|
||||||
|
queryset = SaleProduct.objects.select_related('iproduct', 'iproduct__material', 'iproduct__warehouse').all()
|
||||||
|
serializer_class = SaleProductListSerializer
|
||||||
|
search_fields = []
|
||||||
|
filterset_fields = ['sale', 'iproduct']
|
||||||
|
ordering_fields = ['create_time']
|
||||||
|
ordering = ['id']
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.action == 'create':
|
||||||
|
return SaleProductCreateSerializer
|
||||||
|
return super().get_serializer_class()
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=True, perms_map={'post':'*'})
|
||||||
|
def mtest(self, request, pk=None):
|
||||||
|
"""
|
||||||
|
军检
|
||||||
|
"""
|
||||||
|
obj = self.get_object()
|
||||||
|
if obj.is_mtested:
|
||||||
|
raise exceptions.APIException('已进行军检')
|
||||||
|
obj.remark = request.data.get('remark', None)
|
||||||
|
obj.is_mtestok = request.data.get('is_mtestok')
|
||||||
|
obj.save()
|
||||||
|
return Response()
|
||||||
Loading…
Reference in New Issue