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
|
||||
|
||||
@@ -260,7 +260,9 @@ class OrganizationDirectoryImportService:
|
||||
if not row or row[0] is None:
|
||||
continue
|
||||
code = OrganizationDirectoryImportService._text(row[0])
|
||||
value = OrganizationDirectoryImportService._text(row[1] if len(row) > 1 else "")
|
||||
value = OrganizationDirectoryImportService._text(
|
||||
row[1] if len(row) > 1 else ""
|
||||
)
|
||||
if code:
|
||||
references[code] = value
|
||||
return references
|
||||
@@ -347,7 +349,9 @@ class OrganizationDirectoryImportService:
|
||||
strict=True,
|
||||
)
|
||||
)
|
||||
second_values = dict(zip(SOURCE_HEADERS, second_prefix + second_tail, strict=True))
|
||||
second_values = dict(
|
||||
zip(SOURCE_HEADERS, second_prefix + second_tail, strict=True)
|
||||
)
|
||||
if cls._text(second_values.get("is")) == cls._text(second_values.get("rn")):
|
||||
second_values["is"] = ""
|
||||
return [first_values, second_values]
|
||||
@@ -360,10 +364,7 @@ class OrganizationDirectoryImportService:
|
||||
rn: Any,
|
||||
expected_count: int,
|
||||
) -> list[Any]:
|
||||
if (
|
||||
len(values) == expected_count + 1
|
||||
and cls._text(values[-2]) == cls._text(rn)
|
||||
):
|
||||
if len(values) == expected_count + 1 and cls._text(values[-2]) == cls._text(rn):
|
||||
return [*values[:-2], values[-1]]
|
||||
return values
|
||||
|
||||
|
||||
@@ -46,13 +46,16 @@ class OrganizationDirectoryResolver:
|
||||
ogrn: object = None,
|
||||
ogrip: object = None,
|
||||
) -> OrganizationIdentity:
|
||||
normalized_inn, normalized_kpp, normalized_ogrn, normalized_ogrip = (
|
||||
normalize_identity_fields(
|
||||
inn=inn,
|
||||
kpp=kpp,
|
||||
ogrn=ogrn,
|
||||
ogrip=ogrip,
|
||||
)
|
||||
(
|
||||
normalized_inn,
|
||||
normalized_kpp,
|
||||
normalized_ogrn,
|
||||
normalized_ogrip,
|
||||
) = normalize_identity_fields(
|
||||
inn=inn,
|
||||
kpp=kpp,
|
||||
ogrn=ogrn,
|
||||
ogrip=ogrip,
|
||||
)
|
||||
return OrganizationIdentity(
|
||||
rn=cls._digits(rn, max_length=20),
|
||||
|
||||
@@ -292,9 +292,11 @@ class OrganizationSourceIngestionService:
|
||||
normalized_records: list[_NormalizedRecordInput],
|
||||
) -> tuple[dict[int, Organization], int]:
|
||||
"""Compatibility wrapper; parser ingestion must not create organizations."""
|
||||
organizations, _skipped_unmatched, _skipped_ambiguous = (
|
||||
cls._resolve_existing_organizations(normalized_records)
|
||||
)
|
||||
(
|
||||
organizations,
|
||||
_skipped_unmatched,
|
||||
_skipped_ambiguous,
|
||||
) = cls._resolve_existing_organizations(normalized_records)
|
||||
return organizations, 0
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user