fix: align ci with organization redesign
This commit is contained in:
@@ -33,6 +33,7 @@ from django.conf import settings
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db.models import Model, Q
|
||||
from django.utils import timezone
|
||||
from organizations.models import Organization as CanonicalOrganization
|
||||
from registers.models import (
|
||||
Organization,
|
||||
Register,
|
||||
@@ -155,9 +156,37 @@ class BackupExportService:
|
||||
.values_list("id", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
active_organizations = list(
|
||||
Organization.objects.filter(id__in=active_org_ids).values(
|
||||
"mn_inn",
|
||||
"mn_ogrn",
|
||||
)
|
||||
)
|
||||
active_inns = {
|
||||
str(item["mn_inn"]) for item in active_organizations if item["mn_inn"]
|
||||
}
|
||||
active_ogrns = {
|
||||
str(item["mn_ogrn"]) for item in active_organizations if item["mn_ogrn"]
|
||||
}
|
||||
canonical_org_ids = list(
|
||||
CanonicalOrganization.objects.filter(
|
||||
Q(inn__in=active_inns) | Q(ogrn__in=active_ogrns)
|
||||
).values_list("uid", flat=True)
|
||||
)
|
||||
|
||||
organization_record_filter = (
|
||||
Q(registry_organization_id__in=canonical_org_ids)
|
||||
| Q(inn__in=active_inns)
|
||||
| Q(ogrn__in=active_ogrns)
|
||||
)
|
||||
procurement_record_filter = (
|
||||
Q(registry_organization_id__in=canonical_org_ids)
|
||||
| Q(customer_inn__in=active_inns)
|
||||
| Q(customer_ogrn__in=active_ogrns)
|
||||
)
|
||||
reports_qs = FinancialReport.objects.filter(
|
||||
registry_organization_id__in=active_org_ids
|
||||
Q(registry_organization_id__in=canonical_org_ids)
|
||||
| Q(ogrn__in=active_ogrns)
|
||||
)
|
||||
report_ids = list(reports_qs.values_list("id", flat=True))
|
||||
|
||||
@@ -174,16 +203,16 @@ class BackupExportService:
|
||||
"organization_id",
|
||||
),
|
||||
IndustrialCertificateRecord: IndustrialCertificateRecord.objects.filter(
|
||||
registry_organization_id__in=active_org_ids
|
||||
organization_record_filter
|
||||
).order_by("id"),
|
||||
ManufacturerRecord: ManufacturerRecord.objects.filter(
|
||||
registry_organization_id__in=active_org_ids
|
||||
organization_record_filter
|
||||
).order_by("id"),
|
||||
InspectionRecord: InspectionRecord.objects.filter(
|
||||
registry_organization_id__in=active_org_ids
|
||||
organization_record_filter
|
||||
).order_by("id"),
|
||||
ProcurementRecord: ProcurementRecord.objects.filter(
|
||||
registry_organization_id__in=active_org_ids
|
||||
procurement_record_filter
|
||||
).order_by("id"),
|
||||
FinancialReport: reports_qs.order_by("id"),
|
||||
FinancialReportLine: FinancialReportLine.objects.filter(
|
||||
|
||||
@@ -1905,9 +1905,7 @@ class FNSReportOrganizationResolutionSkipped(ValueError):
|
||||
self.external_id = external_id
|
||||
self.ogrn = ogrn
|
||||
self.ingestion_result = ingestion_result
|
||||
self.reason = (
|
||||
"ambiguous" if ingestion_result.skipped_ambiguous else "unmatched"
|
||||
)
|
||||
self.reason = "ambiguous" if ingestion_result.skipped_ambiguous else "unmatched"
|
||||
super().__init__(
|
||||
"FNS report skipped because organization resolution is "
|
||||
f"{self.reason}: external_id={external_id}, ogrn={ogrn}"
|
||||
|
||||
@@ -1578,9 +1578,7 @@ def _native_record_to_result(
|
||||
elif source == ParserLoadLog.Source.FNS_REPORTS:
|
||||
registry_organization = record.registry_organization
|
||||
external_id = record.external_id
|
||||
organisation_name = (
|
||||
registry_organization.name if registry_organization else ""
|
||||
)
|
||||
organisation_name = registry_organization.name if registry_organization else ""
|
||||
title = record.file_name
|
||||
record_date = ""
|
||||
status_value = record.status
|
||||
|
||||
Reference in New Issue
Block a user