from apps.pm.models import ProductionPlan, SubProductionPlan
from rest_framework import serializers
from apps.sam.serializers import OrderSerializer
from apps.mtm.serializers import MaterialSimpleSerializer, ProcessSimpleSerializer
from apps.system.serializers import OrganizationSimpleSerializer


class ProductionPlanCreateFromOrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductionPlan
        fields = ['order', 'number', 'count', 'start_date', 'end_date']

class ProductionPlanSerializer(serializers.ModelSerializer):
    order_ = OrderSerializer(source='order', read_only=True)
    product_ = MaterialSimpleSerializer(source='product', read_only=True)
    class Meta:
        model = ProductionPlan
        fields ='__all__'

class ResourceCalSerializer(serializers.Serializer):
    id = serializers.IntegerField(label='产品ID')
    count = serializers.IntegerField(label='生产数量')

class ResourceCalListSerializer(serializers.ListSerializer):
    child = ResourceCalSerializer()

class SubProductionPlanListSerializer(serializers.ModelSerializer):
    workshop_ = OrganizationSimpleSerializer(source='workshop', read_only=True)
    process_ = ProcessSimpleSerializer(source='process', read_only=True)
    class Meta:
        model=SubProductionPlan
        fields = '__all__'

class SubProductionPlanUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = SubProductionPlan
        fields = ['start_date', 'end_date']
