feat: address QA feedback and limit Checko collection
This commit is contained in:
@@ -14,6 +14,7 @@ from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from organizations.cache import invalidate_organization_api_cache
|
||||
from organizations.models import Organization
|
||||
|
||||
DIRECTORY_SHEET = "Лист1"
|
||||
@@ -142,12 +143,14 @@ class OrganizationDirectoryImportService:
|
||||
else:
|
||||
updated += 1
|
||||
|
||||
return OrganizationDirectoryImportResult(
|
||||
result = OrganizationDirectoryImportResult(
|
||||
scanned=scanned,
|
||||
created=created,
|
||||
updated=updated,
|
||||
skipped=skipped,
|
||||
)
|
||||
transaction.on_commit(invalidate_organization_api_cache)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def _organization_defaults(
|
||||
|
||||
@@ -8,7 +8,16 @@ from decimal import Decimal
|
||||
from hashlib import sha256
|
||||
from uuid import UUID, uuid5
|
||||
|
||||
from apps.parsers.models import ParserLoadLog
|
||||
from apps.parsers.models import (
|
||||
FinancialReport,
|
||||
GenericParserRecord,
|
||||
IndustrialCertificateRecord,
|
||||
IndustrialProductRecord,
|
||||
InspectionRecord,
|
||||
ManufacturerRecord,
|
||||
ParserLoadLog,
|
||||
ProcurementRecord,
|
||||
)
|
||||
from django.db.models import Count, Max, Min
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -105,6 +114,21 @@ class TestCompanyDatasetService:
|
||||
**record_defaults,
|
||||
},
|
||||
)
|
||||
legacy_record = cls._sync_parser_result_record(
|
||||
source=source,
|
||||
external_id=external_id,
|
||||
organization=organization,
|
||||
defaults=record_defaults,
|
||||
index=index,
|
||||
)
|
||||
legacy_module = legacy_record.__class__.__module__.removesuffix(
|
||||
".models"
|
||||
)
|
||||
record.legacy_model = (
|
||||
f"{legacy_module}.{legacy_record.__class__.__name__}"
|
||||
)
|
||||
record.legacy_pk = str(legacy_record.pk)
|
||||
record.save(update_fields=["legacy_model", "legacy_pk", "updated_at"])
|
||||
if source == ParserLoadLog.Source.FNS_REPORTS:
|
||||
cls._refresh_financial_lines(record=record, index=index)
|
||||
|
||||
@@ -129,6 +153,7 @@ class TestCompanyDatasetService:
|
||||
company_uids = cls.company_uids()
|
||||
queryset = Organization.objects.filter(uid__in=company_uids)
|
||||
deleted_count = queryset.count()
|
||||
cls._delete_parser_result_records(company_uids)
|
||||
extension_models = {
|
||||
descriptor.extension_model
|
||||
for source, descriptor in SOURCE_GROUP_DESCRIPTORS.items()
|
||||
@@ -140,6 +165,172 @@ class TestCompanyDatasetService:
|
||||
cls._invalidate_caches()
|
||||
return TestCompanyDatasetResult(organizations_deleted=deleted_count)
|
||||
|
||||
@classmethod
|
||||
def _sync_parser_result_record(
|
||||
cls,
|
||||
*,
|
||||
source: str,
|
||||
external_id: str,
|
||||
organization: Organization,
|
||||
defaults: dict,
|
||||
index: int,
|
||||
):
|
||||
"""Mirror demo rows into the parser tables served by public source APIs."""
|
||||
payload = defaults.get("payload", {})
|
||||
load_batch = 9_000_000 + index
|
||||
common = {
|
||||
"load_batch": load_batch,
|
||||
"registry_organization": organization,
|
||||
}
|
||||
|
||||
if source == ParserLoadLog.Source.INDUSTRIAL:
|
||||
legacy_record, _ = IndustrialCertificateRecord.objects.update_or_create(
|
||||
certificate_number=payload["certificate_number"],
|
||||
defaults={
|
||||
**common,
|
||||
"issue_date": payload["issue_date"],
|
||||
"issue_date_normalized": date.fromisoformat(
|
||||
payload["issue_date_normalized"]
|
||||
),
|
||||
"expiry_date": payload["expiry_date"],
|
||||
"expiry_date_normalized": date.fromisoformat(
|
||||
payload["expiry_date_normalized"]
|
||||
),
|
||||
"certificate_file_url": payload["certificate_file_url"],
|
||||
"organisation_name": organization.name,
|
||||
"inn": organization.inn,
|
||||
"ogrn": organization.ogrn,
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
if source == ParserLoadLog.Source.INDUSTRIAL_PRODUCTS:
|
||||
legacy_record, _ = IndustrialProductRecord.objects.update_or_create(
|
||||
registry_number=payload["registry_number"],
|
||||
defaults={
|
||||
**common,
|
||||
"full_organisation_name": payload["full_organisation_name"],
|
||||
"ogrn": organization.ogrn,
|
||||
"inn": organization.inn,
|
||||
"product_name": payload["product_name"],
|
||||
"product_model": payload["product_model"],
|
||||
"okpd2_code": payload["okpd2_code"],
|
||||
"tnved_code": payload["tnved_code"],
|
||||
"regulatory_document": payload["regulatory_document"],
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
if source == ParserLoadLog.Source.MANUFACTURES:
|
||||
legacy_record, _ = ManufacturerRecord.objects.update_or_create(
|
||||
inn=organization.inn,
|
||||
defaults={
|
||||
**common,
|
||||
"full_legal_name": payload["full_legal_name"],
|
||||
"ogrn": organization.ogrn,
|
||||
"address": payload["address"],
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
if source == ParserLoadLog.Source.INSPECTIONS:
|
||||
legacy_record, _ = InspectionRecord.objects.update_or_create(
|
||||
registration_number=payload["registration_number"],
|
||||
defaults={
|
||||
**common,
|
||||
"inn": organization.inn,
|
||||
"ogrn": organization.ogrn,
|
||||
"organisation_name": organization.name,
|
||||
"control_authority": payload["control_authority"],
|
||||
"inspection_type": payload["inspection_type"],
|
||||
"inspection_form": payload["inspection_form"],
|
||||
"start_date": payload["start_date"],
|
||||
"start_date_normalized": date.fromisoformat(
|
||||
payload["start_date_normalized"]
|
||||
),
|
||||
"end_date": payload["end_date"],
|
||||
"end_date_normalized": date.fromisoformat(
|
||||
payload["end_date_normalized"]
|
||||
),
|
||||
"status": payload["status"],
|
||||
"legal_basis": payload["legal_basis"],
|
||||
"is_federal_law_248": True,
|
||||
"data_year": payload["data_year"],
|
||||
"data_month": payload["data_month"],
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
if source == ParserLoadLog.Source.PROCUREMENTS:
|
||||
legacy_record, _ = ProcurementRecord.objects.update_or_create(
|
||||
purchase_number=payload["purchase_number"],
|
||||
defaults={
|
||||
**common,
|
||||
"purchase_name": payload["subject"],
|
||||
"customer_inn": organization.inn,
|
||||
"customer_kpp": organization.kpp,
|
||||
"customer_ogrn": organization.ogrn,
|
||||
"customer_name": organization.name,
|
||||
"max_price": payload["price"],
|
||||
"max_price_amount": defaults["amount"],
|
||||
"publish_date": payload["published_at"],
|
||||
"publish_date_normalized": date(2026, 2, 1),
|
||||
"status": payload["status"],
|
||||
"law_type": payload["law"],
|
||||
"purchase_object_info": payload["subject"],
|
||||
"href": payload["url"],
|
||||
"region_code": payload["region_code"],
|
||||
"data_year": payload["data_year"],
|
||||
"data_month": payload["data_month"],
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
if source == ParserLoadLog.Source.FNS_REPORTS:
|
||||
legacy_record, _ = FinancialReport.objects.update_or_create(
|
||||
external_id=f"test-company-{index:02d}",
|
||||
defaults={
|
||||
**common,
|
||||
"ogrn": organization.ogrn,
|
||||
"file_name": payload["file_name"],
|
||||
"file_hash": payload["file_hash"],
|
||||
"status": FinancialReport.Status.SUCCESS,
|
||||
"source": FinancialReport.SourceType.API,
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
legacy_record, _ = GenericParserRecord.objects.update_or_create(
|
||||
source=source,
|
||||
external_id=external_id,
|
||||
defaults={
|
||||
**common,
|
||||
"inn": organization.inn,
|
||||
"ogrn": organization.ogrn,
|
||||
"organisation_name": organization.name,
|
||||
"title": defaults.get("title", ""),
|
||||
"record_date": defaults.get("record_date", ""),
|
||||
"amount": defaults.get("amount"),
|
||||
"status": defaults.get("status", ""),
|
||||
"url": defaults.get("url", ""),
|
||||
"payload": payload,
|
||||
},
|
||||
)
|
||||
return legacy_record
|
||||
|
||||
@staticmethod
|
||||
def _delete_parser_result_records(company_uids: list[UUID]) -> None:
|
||||
for model in (
|
||||
GenericParserRecord,
|
||||
IndustrialCertificateRecord,
|
||||
IndustrialProductRecord,
|
||||
ManufacturerRecord,
|
||||
InspectionRecord,
|
||||
ProcurementRecord,
|
||||
FinancialReport,
|
||||
):
|
||||
model.objects.filter(registry_organization_id__in=company_uids).delete()
|
||||
|
||||
@staticmethod
|
||||
def _descriptors_by_group():
|
||||
descriptors = {}
|
||||
|
||||
@@ -32,7 +32,6 @@ from organizations.cache import (
|
||||
ORGANIZATION_API_CACHE_CONTRACT_VERSION,
|
||||
ORGANIZATION_API_CACHE_PREFIX,
|
||||
get_organization_api_cache_version,
|
||||
invalidate_organization_api_cache,
|
||||
)
|
||||
from organizations.directory_import import (
|
||||
OrganizationDirectoryImportError,
|
||||
@@ -395,7 +394,6 @@ class OrganizationViewSet(CachedReadOnlyMixin, ReadOnlyModelViewSet):
|
||||
with suppress(FileNotFoundError):
|
||||
os.unlink(temp_path)
|
||||
|
||||
invalidate_organization_api_cache()
|
||||
return Response(
|
||||
{
|
||||
"success": True,
|
||||
|
||||
Reference in New Issue
Block a user