Fix admin API gaps for users, exchange checks, and parser logs
This commit is contained in:
@@ -296,6 +296,7 @@ class ParserLoadLogSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
|
||||
source_display = serializers.CharField(source="get_source_display", read_only=True)
|
||||
organizations_count = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = ParserLoadLog
|
||||
@@ -305,6 +306,7 @@ class ParserLoadLogSerializer(serializers.ModelSerializer):
|
||||
"source",
|
||||
"source_display",
|
||||
"records_count",
|
||||
"organizations_count",
|
||||
"status",
|
||||
"error_message",
|
||||
"created_at",
|
||||
@@ -312,6 +314,57 @@ class ParserLoadLogSerializer(serializers.ModelSerializer):
|
||||
]
|
||||
read_only_fields = fields
|
||||
|
||||
def get_organizations_count(self, obj) -> int:
|
||||
if obj.source == ParserLoadLog.Source.FNS_REPORTS:
|
||||
return (
|
||||
FinancialReport.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(ogrn="")
|
||||
.values("ogrn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
if obj.source == ParserLoadLog.Source.INDUSTRIAL:
|
||||
return (
|
||||
IndustrialCertificateRecord.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(inn="")
|
||||
.values("inn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
if obj.source == ParserLoadLog.Source.INDUSTRIAL_PRODUCTS:
|
||||
return (
|
||||
IndustrialProductRecord.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(inn="")
|
||||
.values("inn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
if obj.source == ParserLoadLog.Source.MANUFACTURES:
|
||||
return (
|
||||
ManufacturerRecord.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(inn="")
|
||||
.values("inn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
if obj.source == ParserLoadLog.Source.INSPECTIONS:
|
||||
return (
|
||||
InspectionRecord.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(inn="")
|
||||
.values("inn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
if obj.source == ParserLoadLog.Source.PROCUREMENTS:
|
||||
return (
|
||||
ProcurementRecord.objects.filter(load_batch=obj.batch_id)
|
||||
.exclude(customer_inn="")
|
||||
.values("customer_inn")
|
||||
.distinct()
|
||||
.count()
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
class ProxySerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user