Пример #1
0
class GoodListSerializer(serializers.Serializer):
    id = serializers.UUIDField()
    name = serializers.CharField()
    description = serializers.CharField()
    control_list_entries = ControlListEntrySerializer(many=True, allow_null=True)
    part_number = serializers.CharField()
    status = KeyValueChoiceField(choices=GoodStatus.choices)
Пример #2
0
class GoodSerializerInternal(serializers.Serializer):
    id = serializers.UUIDField()
    name = serializers.CharField()
    description = serializers.CharField()
    part_number = serializers.CharField()
    control_list_entries = ControlListEntrySerializer(many=True)
    comment = serializers.CharField()
    is_good_controlled = KeyValueChoiceField(choices=GoodControlled.choices)
    report_summary = serializers.CharField(allow_blank=True, required=False)
    flags = GoodsFlagSerializer(many=True)
    documents = serializers.SerializerMethodField()
    is_pv_graded = serializers.CharField()
    grading_comment = serializers.CharField()
    pv_grading_details = PvGradingDetailsSerializer(allow_null=True, required=False)
    status = KeyValueChoiceField(choices=GoodStatus.choices)
    item_category = KeyValueChoiceField(choices=ItemCategory.choices)
    is_military_use = KeyValueChoiceField(choices=MilitaryUse.choices)
    is_component = KeyValueChoiceField(choices=Component.choices)
    uses_information_security = serializers.BooleanField()
    modified_military_use_details = serializers.CharField()
    component_details = serializers.CharField()
    information_security_details = serializers.CharField()
    missing_document_reason = KeyValueChoiceField(choices=GoodMissingDocumentReasons.choices)
    software_or_technology_details = serializers.CharField()
    firearm_details = FirearmDetailsSerializer(allow_null=True, required=False)
    is_precedent = serializers.BooleanField(required=False, default=False)

    def get_documents(self, instance):
        documents = GoodDocument.objects.filter(good=instance)
        return SimpleGoodDocumentViewSerializer(documents, many=True).data
Пример #3
0
class GoodOnLicenceViewSerializer(serializers.Serializer):
    good_on_application_id = serializers.UUIDField(source="good.id")
    usage = serializers.FloatField()
    description = serializers.CharField(source="good.good.description")
    units = KeyValueChoiceField(source="good.unit", choices=Units.choices)
    applied_for_quantity = serializers.FloatField(source="good.quantity")
    applied_for_value = serializers.FloatField(source="good.value")
    licenced_quantity = serializers.FloatField(source="quantity")
    licenced_value = serializers.FloatField(source="value")
    applied_for_value_per_item = serializers.SerializerMethodField()
    licenced_value_per_item = serializers.SerializerMethodField()
    control_list_entries = ControlListEntrySerializer(
        source="good.good.control_list_entries", many=True)
    advice = serializers.SerializerMethodField()

    def get_advice(self, instance):
        advice = instance.good.good.advice.get(
            level=AdviceLevel.FINAL, case_id=instance.licence.case_id)
        return SimpleAdviceSerializer(instance=advice).data

    def get_applied_for_value_per_item(self, instance):
        if instance.good.value and instance.good.quantity:
            return float(instance.good.value) / instance.good.quantity

    def get_licenced_value_per_item(self, instance):
        if instance.value and instance.quantity:
            return float(instance.value) / instance.quantity
Пример #4
0
class GoodsTypeOnLicenceSerializer(serializers.ModelSerializer):
    control_list_entries = ControlListEntrySerializer(many=True)

    class Meta:
        model = GoodsType
        fields = (
            "description",
            "control_list_entries",
            "usage",
        )
        read_only_fields = fields
Пример #5
0
class GoodOnApplicationViewSerializer(serializers.ModelSerializer):
    good = GoodSerializerInternal(read_only=True)
    good_application_documents = serializers.SerializerMethodField()
    unit = KeyValueChoiceField(choices=Units.choices)
    flags = serializers.SerializerMethodField()
    control_list_entries = ControlListEntrySerializer(many=True)
    audit_trail = serializers.SerializerMethodField()
    is_good_controlled = KeyValueChoiceField(choices=GoodControlled.choices)
    firearm_details = FirearmDetailsSerializer()

    class Meta:
        model = GoodOnApplication
        fields = (
            "id",
            "good",
            "application",
            "quantity",
            "unit",
            "value",
            "is_good_incorporated",
            "flags",
            "item_type",
            "other_item_type",
            "is_good_controlled",
            "control_list_entries",
            "end_use_control",
            "comment",
            "report_summary",
            "audit_trail",
            "firearm_details",
            "good_application_documents",
            "is_precedent",
        )

    def get_flags(self, instance):
        return list(instance.good.flags.values("id", "name", "colour",
                                               "label"))

    def get_good_application_documents(self, instance):
        documents = GoodOnApplicationDocument.objects.filter(
            application=instance.application, good=instance.good, safe=True)
        return GoodOnApplicationDocumentViewSerializer(documents,
                                                       many=True).data

    def get_audit_trail(self, instance):
        # this serializer is used by a few views. Most views do not need to know audit trail
        if not self.context.get("include_audit_trail"):
            return []
        return AuditSerializer(instance.audit_trail.all(), many=True).data
Пример #6
0
class GoodsTypeViewSerializer(serializers.Serializer):
    id = serializers.UUIDField(read_only=True)
    description = serializers.CharField(read_only=True)
    is_good_controlled = serializers.ChoiceField(
        choices=GoodControlled.choices)
    is_good_incorporated = serializers.BooleanField(read_only=True)
    control_list_entries = ControlListEntrySerializer(many=True,
                                                      read_only=True)
    countries = serializers.SerializerMethodField()
    document = serializers.SerializerMethodField()
    flags = serializers.SerializerMethodField()
    comment = serializers.CharField()
    report_summary = serializers.CharField(allow_blank=True, required=False)
    end_use_control = serializers.ListField(child=serializers.CharField(),
                                            required=False)

    def __init__(self,
                 instance=None,
                 data=empty,
                 default_countries=None,
                 **kwargs):
        super().__init__(instance, data, **kwargs)
        self.default_countries = default_countries

    def get_flags(self, instance):
        return list(instance.flags.filter().values("id", "name", "colour",
                                                   "label"))

    def get_countries(self, instance):
        countries = instance.countries
        if not countries.count():
            return CountrySerializer(self.default_countries or [],
                                     many=True).data
        return CountrySerializer(countries, many=True).data

    def get_document(self, instance):
        docs = GoodsTypeDocument.objects.filter(goods_type=instance).values()
        return docs[0] if docs else None
Пример #7
0
 def get_control_list_entries(self, instance):
     control_list_entries = instance.good.get_control_list_entries()
     return ControlListEntrySerializer(control_list_entries, many=True).data