From 4637b02ddd0b308f8ff6747eb4d2c7868cbff28a Mon Sep 17 00:00:00 2001 From: Aleksandr Meshchryakov Date: Mon, 5 Oct 2026 16:45:13 +0200 Subject: [PATCH] feat: expose Checko section APIs and completion counters --- docs/sources/checko-sections.md | 15 +- .../0045_checko_disabled_schedules.py | 37 + src/apps/parsers/source_cards.py | 127 +- src/apps/parsers/source_registry.py | 36 + src/apps/parsers/tasks.py | 3 + src/apps/parsers/tasks_registry_snapshots.py | 94 +- src/apps/parsers/views.py | 3 + src/core/openapi.json | 1131 ++++++++++++++++- .../checko_section_payload_serializers.py | 41 + src/organizations/serializers.py | 6 + src/organizations/source_record_export.py | 15 +- src/organizations/source_record_query.py | 18 + src/organizations/test_companies.py | 3 + .../organizations/test_canonical_openapi.py | 2 +- .../test_checko_section_contract.py | 208 +++ .../test_openapi_runtime_fixtures.py | 35 +- .../test_source_export_snapshot_contract.py | 5 +- .../test_source_record_export.py | 12 +- tests/apps/organizations/test_tasks.py | 2 +- .../test_test_companies_commands.py | 5 +- .../apps/parsers/test_refresh_concurrency.py | 3 + .../apps/parsers/test_source_cards_service.py | 6 + tests/apps/parsers/test_source_registry.py | 3 +- tools/openapi/build.mjs | 6 + tools/openapi/check-runtime.mjs | 2 +- tools/openapi/source-record-extensions.json | 192 +++ 26 files changed, 1974 insertions(+), 36 deletions(-) create mode 100644 src/apps/parsers/migrations/0045_checko_disabled_schedules.py create mode 100644 src/organizations/checko_section_payload_serializers.py create mode 100644 tests/apps/organizations/test_checko_section_contract.py diff --git a/docs/sources/checko-sections.md b/docs/sources/checko-sections.md index 03e1a30..3dc72a5 100644 --- a/docs/sources/checko-sections.md +++ b/docs/sources/checko-sections.md @@ -20,6 +20,19 @@ HTTPS GET https://api.checko.ru/v2/company или /fedresurs через суще ## Fixtures и готовность -Fixtures синтетические, структура из официальной документации; реальные ответы аккаунта не снимались. Success/renewed/empty/denied/rate-limit/two pages доступны локально. Никаких вымышленных /leasing,/messages. Readiness: schema documented; implementation и фактическая dev-приёмка впереди. Месячные claims/полная популяция требуют отдельной проверки. Schedules disabled. +Fixtures синтетические, структура из официальной документации; реальные ответы аккаунта не снимались. Success/renewed/empty/denied/rate-limit/two pages доступны локально. Никаких вымышленных /leasing,/messages. Readiness: три адаптера, scoped snapshots, monthly claims, карточки/API/экспорт и типизированные OpenAPI variants реализованы. Фактическая приёмка выбранного аккаунта и полной dev-популяции остаётся отдельно. Schedules disabled. Публичный тариф: первые 100 запросов за день бесплатны, далее Standard 0.15 RUB / Maximum 0.10 RUB за HTTP 200. Конкретный тариф/остаток аккаунта не установлен; это не разрешение расходовать квоту. Для фактической пробы подготовить canonical scope и максимальное число страниц/calls, получить отдельное разрешение. + + +## Реализованная публикация и контракт + +Три источника `checko_leasing`, `checko_messages`, `checko_licenses` имеют независимые карточки `checko-leasing`, `checko-messages`, `checko-licenses`, группы `leasing`, `company_messages`, `company_licenses` и типы `leasing_contract`, `company_message`, `company_license`. Refresh/run доступны администраторам, пользовательские file URLs запрещены. Display copy сохраняет существующую нейтральную конвенцию; machine IDs и проверенный provenance в новом API/экспорте не заменяются. + +Eligibility совпадает с существующими платными сборщиками: ОПК / Росатом / Роскосмос и обязательный импорт в канонический справочник. Перед запросом проверяются ИНН (10 цифр/checksum), ОГРН (13), ОКПО (8), наличие имени и однозначная организация; записи филиалов/неоднозначные или неполные реквизиты сохраняются без запроса. Это не сбор полного каталога всех юрлиц страны. + +Claim берётся атомарно до первого запроса и сохраняется после ошибки. Каждый раздел обходит максимум 100 страниц / 10 000 сообщений на организацию; staging batches по 500. Ошибка пагинации удаляет staging этой организации, старые опубликованные записи сохраняются. Успешный пустой ответ удаляет прежние записи только своей организации. Нет завершённых организаций — rejected artifact и failure job, без fake snapshot. + +Artifact — приватный NDJSON с нормализованными наблюдениями и upstream-полями, SHA-256/size; credentials/meta balance не сохраняются. `completeness=full|partial`; непересекающиеся категории: `organizations_updated + organizations_empty + organizations_failed + quota_skipped = organizations_total`. `organizations_preserved = organizations_failed + quota_skipped`, это пересекающийся диагностический счётчик, его не суммируют второй раз. `updated_records_count` — записи завершённого scope, `retained_records_count` — сохранённые записи, published/snapshot counts — весь текущий опубликованный набор. Partial success не двигает `latest_success_load` полного прохода; последний job/load показывает partial metadata. API и экспорт читают все текущие записи, включая сохранённые из прежних batches. + +Локальная проверка 05.10.2026: adapters/старый клиент/local HTTP — 126 passed; PostgreSQL с настоящими миграциями/гонкой monthly claim и admission/export — 42 passed; generated OpenAPI/Orval/type-check и Zod round-trip — 19 фактических JSON-ответов без изменения/потери полей. Платные реальные вызовы не выполнялись. Ограниченная dev-проба и полный обход — отдельные критерии готовности. diff --git a/src/apps/parsers/migrations/0045_checko_disabled_schedules.py b/src/apps/parsers/migrations/0045_checko_disabled_schedules.py new file mode 100644 index 0000000..8b5c3c2 --- /dev/null +++ b/src/apps/parsers/migrations/0045_checko_disabled_schedules.py @@ -0,0 +1,37 @@ +"""Three independent monthly collections stay disabled until full dev acceptance.""" + +from django.db import migrations + +SOURCES = ("leasing", "messages", "licenses") + + +def seed(apps, schema_editor): + intervals = apps.get_model("django_celery_beat", "IntervalSchedule") + tasks = apps.get_model("django_celery_beat", "PeriodicTask") + interval, _ = intervals.objects.get_or_create(every=30, period="days") + for source in SOURCES: + tasks.objects.update_or_create( + name=f"parser:checko-{source}:monthly", + defaults={ + "task": f"parsers.checko_{source}.refresh", + "interval": interval, + "enabled": False, + "args": "[]", + "kwargs": "{}", + "description": "Enable only after approved quota/account and full dev acceptance.", + }, + ) + + +def unseed(apps, schema_editor): + apps.get_model("django_celery_beat", "PeriodicTask").objects.filter( + name__in=[f"parser:checko-{source}:monthly" for source in SOURCES] + ).delete() + + +class Migration(migrations.Migration): + dependencies = [ + ("parsers", "0044_checko_sections"), + ("django_celery_beat", "0018_improve_crontab_helptext"), + ] + operations = [migrations.RunPython(seed, unseed)] diff --git a/src/apps/parsers/source_cards.py b/src/apps/parsers/source_cards.py index d8cc1db..31c0627 100644 --- a/src/apps/parsers/source_cards.py +++ b/src/apps/parsers/source_cards.py @@ -46,6 +46,9 @@ STALE_PENDING_MAX_AGE_MINUTES = 24 * 60 SOURCE_CARD_STATS_CACHE_TIMEOUT_SECONDS = 7 * 24 * 60 * 60 SOURCE_CARD_STATS_CACHE_SCHEMA_VERSION = 4 SNAPSHOT_CARD_SLUGS = { + "checko_licenses": "checko-licenses", + "checko_messages": "checko-messages", + "checko_leasing": "checko-leasing", "fssp_enforcement_proceedings": "fssp-enforcement-proceedings", "budget_ubpandnubp": "budget-process-registry", "fns_sme_support_recipients": "sme-support-recipients-registry", @@ -53,6 +56,9 @@ SNAPSHOT_CARD_SLUGS = { "fedresurs_company_profile": "fedresurs-company-profile", } SNAPSHOT_SOURCE_GROUPS = ( + "company_licenses", + "company_messages", + "leasing", "enforcement_proceedings", "budget_process_registry", "government_support", @@ -505,6 +511,57 @@ SOURCE_CARD_DEFINITIONS: tuple[SourceCardDefinition, ...] = ( ), refresh_interval=timedelta(days=1), ), + SourceCardDefinition( + slug="checko-leasing", + title="Лизинг", + description="Лизинг канонических организаций.", + order=170, + task_names=("parsers.checko_leasing.refresh",), + source_items=( + SourceItemDefinition( + code="checko_leasing", + title="Лизинг", + description="Проверенные сведения организаций.", + parser_source=ParserLoadLog.Source.CHECKO_LEASING, + refresh_key="checko_leasing", + ), + ), + refresh_interval=timedelta(days=30), + ), + SourceCardDefinition( + slug="checko-messages", + title="Сообщения организаций", + description="Сообщения канонических организаций.", + order=180, + task_names=("parsers.checko_messages.refresh",), + source_items=( + SourceItemDefinition( + code="checko_messages", + title="Сообщения организаций", + description="Проверенные сведения организаций.", + parser_source=ParserLoadLog.Source.CHECKO_MESSAGES, + refresh_key="checko_messages", + ), + ), + refresh_interval=timedelta(days=30), + ), + SourceCardDefinition( + slug="checko-licenses", + title="Лицензии организаций", + description="Лицензии канонических организаций.", + order=190, + task_names=("parsers.checko_licenses.refresh",), + source_items=( + SourceItemDefinition( + code="checko_licenses", + title="Лицензии организаций", + description="Проверенные сведения организаций.", + parser_source=ParserLoadLog.Source.CHECKO_LICENSES, + refresh_key="checko_licenses", + ), + ), + refresh_interval=timedelta(days=30), + ), SourceCardDefinition( slug="fssp-enforcement-proceedings", title="ФССП: Банк данных исполнительных производств", @@ -532,6 +589,9 @@ SOURCE_CARD_BY_PARSER_SOURCE = { if source_item.parser_source } GENERIC_RECORD_SOURCES_BY_ITEM_CODE = { + "checko_licenses": ParserLoadLog.Source.CHECKO_LICENSES, + "checko_messages": ParserLoadLog.Source.CHECKO_MESSAGES, + "checko_leasing": ParserLoadLog.Source.CHECKO_LEASING, "procurements_44fz": ParserLoadLog.Source.PROCUREMENTS_44FZ, "procurements_223fz": ParserLoadLog.Source.PROCUREMENTS_223FZ, "contracts": ParserLoadLog.Source.CONTRACTS, @@ -1030,14 +1090,18 @@ class SourceCardService: "-updated_at", "-created_at", ) - for load in queryset: + loads = list(queryset) + attach_snapshot_artifacts(loads) + for load in loads: latest_load_by_source.setdefault(load.source, load) - if load.status in SUCCESSFUL_LOAD_STATUSES: + artifact = get_snapshot_artifact(load) + partial = ( + artifact is not None + and artifact.metadata.get("completeness") == "partial" + ) + if load.status in SUCCESSFUL_LOAD_STATUSES and not partial: latest_success_load_by_source.setdefault(load.source, load) - attach_snapshot_artifacts( - [*latest_load_by_source.values(), *latest_success_load_by_source.values()] - ) return latest_load_by_source, latest_success_load_by_source @classmethod @@ -1346,13 +1410,40 @@ class SourceCardService: elif definition.slug in SNAPSHOT_CARD_SLUGS.values(): from apps.parsers.tasks_registry_snapshots import ( parse_budget_registry, + parse_checko_leasing, + parse_checko_licenses, + parse_checko_messages, parse_fedresurs_company_profiles, parse_fssp_enforcement_proceedings, parse_sme_support_recipients, parse_sro_membership, ) - if definition.slug == "fssp-enforcement-proceedings": + if definition.slug == "checko-leasing": + task_specs = ( + ( + parse_checko_leasing, + "parsers.checko_leasing.refresh", + "checko_leasing", + ), + ) + elif definition.slug == "checko-messages": + task_specs = ( + ( + parse_checko_messages, + "parsers.checko_messages.refresh", + "checko_messages", + ), + ) + elif definition.slug == "checko-licenses": + task_specs = ( + ( + parse_checko_licenses, + "parsers.checko_licenses.refresh", + "checko_licenses", + ), + ) + elif definition.slug == "fssp-enforcement-proceedings": task_specs = ( ( parse_fssp_enforcement_proceedings, @@ -1736,7 +1827,17 @@ class SourceCardService: queryset = ParserLoadLog.objects.filter(source__in=parser_sources) if statuses: queryset = queryset.filter(status__in=statuses) - return queryset.order_by("-updated_at", "-created_at").first() + loads = list(queryset.order_by("-updated_at", "-created_at")) + attach_snapshot_artifacts(loads) + for load in loads: + artifact = get_snapshot_artifact(load) + if ( + not statuses + or artifact is None + or artifact.metadata.get("completeness") != "partial" + ): + return load + return None @classmethod def _get_latest_load_by_source( @@ -1750,7 +1851,17 @@ class SourceCardService: queryset = ParserLoadLog.objects.filter(source=parser_source) if statuses: queryset = queryset.filter(status__in=statuses) - return queryset.order_by("-updated_at", "-created_at").first() + loads = list(queryset.order_by("-updated_at", "-created_at")) + attach_snapshot_artifacts(loads) + for load in loads: + artifact = get_snapshot_artifact(load) + if ( + not statuses + or artifact is None + or artifact.metadata.get("completeness") != "partial" + ): + return load + return None @classmethod def _get_active_tasks( diff --git a/src/apps/parsers/source_registry.py b/src/apps/parsers/source_registry.py index 2044cee..d6c9b04 100644 --- a/src/apps/parsers/source_registry.py +++ b/src/apps/parsers/source_registry.py @@ -56,6 +56,42 @@ class ParserSourceDescriptor: PARSER_SOURCES: dict[str, ParserSourceDescriptor] = { + "checko_licenses": ParserSourceDescriptor( + key="checko_licenses", + source=ParserLoadLog.Source.CHECKO_LICENSES, + title="Лицензии организаций", + agency="Внешний реестр", + data_scope="Лицензии организаций канонических организаций", + task_name="parsers.checko_licenses.refresh", + mode="organization_api", + access_method="monthly_claim_api", + parser_strategy="scoped_organization_snapshot", + admin_only=True, + ), + "checko_messages": ParserSourceDescriptor( + key="checko_messages", + source=ParserLoadLog.Source.CHECKO_MESSAGES, + title="Сообщения организаций", + agency="Внешний реестр", + data_scope="Сообщения организаций канонических организаций", + task_name="parsers.checko_messages.refresh", + mode="organization_api", + access_method="monthly_claim_api", + parser_strategy="scoped_organization_snapshot", + admin_only=True, + ), + "checko_leasing": ParserSourceDescriptor( + key="checko_leasing", + source=ParserLoadLog.Source.CHECKO_LEASING, + title="Лизинг", + agency="Внешний реестр", + data_scope="Лизинг канонических организаций", + task_name="parsers.checko_leasing.refresh", + mode="organization_api", + access_method="monthly_claim_api", + parser_strategy="scoped_organization_snapshot", + admin_only=True, + ), "fssp_enforcement_proceedings": ParserSourceDescriptor( key="fssp_enforcement_proceedings", source=ParserLoadLog.Source.FSSP_ENFORCEMENT_PROCEEDINGS, diff --git a/src/apps/parsers/tasks.py b/src/apps/parsers/tasks.py index bf7e13d..70ffa91 100644 --- a/src/apps/parsers/tasks.py +++ b/src/apps/parsers/tasks.py @@ -74,6 +74,9 @@ from apps.parsers.source_artifacts import cleanup_parser_source_artifacts from apps.parsers.source_registry import PARSER_SOURCES from apps.parsers.tasks_registry_snapshots import ( # noqa: F401 parse_budget_registry, + parse_checko_leasing, + parse_checko_licenses, + parse_checko_messages, parse_fedresurs_company_profiles, parse_fssp_enforcement_proceedings, parse_sme_support_recipients, diff --git a/src/apps/parsers/tasks_registry_snapshots.py b/src/apps/parsers/tasks_registry_snapshots.py index b2af88d..c6a8232 100644 --- a/src/apps/parsers/tasks_registry_snapshots.py +++ b/src/apps/parsers/tasks_registry_snapshots.py @@ -10,7 +10,7 @@ from functools import partial from apps.core.exceptions import ConflictError from apps.core.models import BackgroundJob, JobStatus from apps.parsers.budget_registry import BUDGET_SOURCE, refresh_budget_registry -from apps.parsers.models import ParserBatchSequence, ParserLoadLog +from apps.parsers.models import ParserBatchSequence, ParserLoadLog, ParserSourceArtifact from apps.parsers.registry_snapshots import SnapshotValidationError from apps.parsers.services import ParserLoadLogService from apps.parsers.sme_support import SME_SOURCE, refresh_sme_support @@ -62,7 +62,13 @@ def _complete_snapshot_job(job, load_log, artifact, result) -> dict: "version": artifact.version or None, "checksum_sha256": artifact.sha256 or None, } - if artifact.source in ("sro_membership_check", "fssp_enforcement_proceedings"): + if artifact.source in ( + "sro_membership_check", + "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses", + ): payload.update(artifact.metadata) job.meta = { **job.meta, @@ -83,6 +89,9 @@ def _claim_snapshot_job(job, source, task_name): "sro_membership_check", "fedresurs_company_profile", "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses", ): sequence, _ = ParserBatchSequence.objects.get_or_create(source=source) ParserBatchSequence.objects.select_for_update().get(pk=sequence.pk) @@ -150,6 +159,32 @@ def _snapshot_error_message(exc: Exception) -> str: return message +def _attach_rejected_section(job, source, load_log): + if ( + source in ("checko_leasing", "checko_messages", "checko_licenses") + and load_log is not None + ): + rejected = ( + ParserSourceArtifact.objects.filter( + source=source, + load_batch=load_log.batch_id, + status=ParserSourceArtifact.Status.REJECTED, + ) + .order_by("-created_at") + .first() + ) + if rejected is not None: + job.result = { + **rejected.metadata, + "source": source, + "artifact_id": str(rejected.uid), + "batch_id": load_log.batch_id, + "status": "failure", + } + job.meta = {**job.meta, **rejected.metadata} + job.save(update_fields=["result", "meta", "updated_at"]) + + def _run_snapshot( task, *, @@ -221,6 +256,7 @@ def _run_snapshot( if load_log is not None: ParserLoadLogService.mark_failed(load_log, message) if job is not None: + _attach_rejected_section(job, source, load_log) job.fail(error=message) raise @@ -326,3 +362,57 @@ def parse_fssp_enforcement_proceedings( requested_by_id=requested_by_id, track_progress=True, ) + + +@shared_task( + bind=True, + name="parsers.checko_leasing.refresh", + soft_time_limit=8 * 3600, + time_limit=8 * 3600 + 300, +) +def parse_checko_leasing(self, *, requested_by_id: int | None = None) -> dict: + from apps.parsers.checko_section_snapshots import refresh_checko_section + + return _run_snapshot( + self, + source="checko_leasing", + refresh=partial(refresh_checko_section, source="checko_leasing"), + requested_by_id=requested_by_id, + track_progress=True, + ) + + +@shared_task( + bind=True, + name="parsers.checko_messages.refresh", + soft_time_limit=8 * 3600, + time_limit=8 * 3600 + 300, +) +def parse_checko_messages(self, *, requested_by_id: int | None = None) -> dict: + from apps.parsers.checko_section_snapshots import refresh_checko_section + + return _run_snapshot( + self, + source="checko_messages", + refresh=partial(refresh_checko_section, source="checko_messages"), + requested_by_id=requested_by_id, + track_progress=True, + ) + + +@shared_task( + bind=True, + name="parsers.checko_licenses.refresh", + soft_time_limit=8 * 3600, + time_limit=8 * 3600 + 300, +) +def parse_checko_licenses(self, *, requested_by_id: int | None = None) -> dict: + from apps.parsers.checko_section_snapshots import refresh_checko_section + + return _run_snapshot( + self, + source="checko_licenses", + refresh=partial(refresh_checko_section, source="checko_licenses"), + requested_by_id=requested_by_id, + track_progress=True, + ) diff --git a/src/apps/parsers/views.py b/src/apps/parsers/views.py index afe3838..52a9664 100644 --- a/src/apps/parsers/views.py +++ b/src/apps/parsers/views.py @@ -146,6 +146,9 @@ SOURCE_RESULT_TAGS = { } TASKS_BY_NAME = { + "parsers.checko_licenses.refresh": tasks.parse_checko_licenses, + "parsers.checko_messages.refresh": tasks.parse_checko_messages, + "parsers.checko_leasing.refresh": tasks.parse_checko_leasing, "parsers.fssp_enforcement_proceedings.refresh": tasks.parse_fssp_enforcement_proceedings, "parsers.fedresurs_company_profile.refresh": tasks.parse_fedresurs_company_profiles, "apps.parsers.tasks.parse_industrial_production": tasks.parse_industrial_production, diff --git a/src/core/openapi.json b/src/core/openapi.json index 0aecd63..744a1b9 100644 --- a/src/core/openapi.json +++ b/src/core/openapi.json @@ -9356,6 +9356,64 @@ "type": "boolean" } }, + { + "name": "license_authority", + "in": "query", + "description": "Фильтр записей источника: license_authority.", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "license_issued_from", + "in": "query", + "description": "Фильтр записей источника: license_issued_from.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, + { + "name": "license_issued_to", + "in": "query", + "description": "Фильтр записей источника: license_issued_to.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, + { + "name": "license_number", + "in": "query", + "description": "Фильтр записей источника: license_number.", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "license_valid_until_from", + "in": "query", + "description": "Фильтр записей источника: license_valid_until_from.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, + { + "name": "license_valid_until_to", + "in": "query", + "description": "Фильтр записей источника: license_valid_until_to.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, { "name": "membership_status", "in": "query", @@ -9369,6 +9427,15 @@ ] } }, + { + "name": "message_type", + "in": "query", + "description": "Фильтр записей источника: message_type.", + "required": false, + "schema": { + "type": "string" + } + }, { "name": "organization_type", "in": "query", @@ -9387,6 +9454,26 @@ "type": "string" } }, + { + "name": "publication_date_from", + "in": "query", + "description": "Фильтр записей источника: publication_date_from.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, + { + "name": "publication_date_to", + "in": "query", + "description": "Фильтр записей источника: publication_date_to.", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + }, { "name": "region", "in": "query", @@ -9598,7 +9685,10 @@ "budget_process_registry", "integrated_structure_documents", "fedresurs_company_profile", - "enforcement_proceedings" + "enforcement_proceedings", + "leasing", + "company_messages", + "company_licenses" ] } }, @@ -9671,7 +9761,7 @@ { "name": "ordering", "in": "query", - "description": "Сортировка по полям: record_date, record_type, external_id, organization__name, extension__organization__name, extension__organization__full_name, created_at, updated_at, title, uid, extension__organization__inn, extension__organization__ogrn, extension__organization__okpo, status, payload__attestation_status, payload__full_name, payload__medo_address, payload__registration_number, payload__uk_hm_treasury, payload__european_union, payload__united_states, payload__switzerland, payload__united_states_sectoral, payload__uk_uksl, payload__ukraine, payload__sentiment, payload__news_source, events_count, documents_count, first_event_date, payload__document_raw, payload__terminated_on, payload__service_text, organization__full_name, organization__inn, organization__ogrn, organization__okpo, payload__classification__organization_type__name, payload__classification__establishment_kind__name, payload__budget__level__name, payload__address__region__name, payload__is_separate_division, payload__support_form__name, payload__support_kind__name, payload__support_until, payload__provider__name, payload__sme_category__name, payload__has_violation, amount, payload__membership_status, payload__region, payload__sro_name, payload__admission_date, payload__status__name, payload__executive_body_name, payload__registration_date, payload__publication_count, payload__reorganization_count, payload__captured_at. Для обратной сортировки используйте префикс -. Несколько полей перечисляются через запятую без пробелов, например -record_date,-external_id. Значения record_date с null сортируются последними.", + "description": "Сортировка по полям: record_date, record_type, external_id, organization__name, extension__organization__name, extension__organization__full_name, created_at, updated_at, title, uid, extension__organization__inn, extension__organization__ogrn, extension__organization__okpo, status, payload__attestation_status, payload__full_name, payload__medo_address, payload__registration_number, payload__uk_hm_treasury, payload__european_union, payload__united_states, payload__switzerland, payload__united_states_sectoral, payload__uk_uksl, payload__ukraine, payload__sentiment, payload__news_source, events_count, documents_count, first_event_date, payload__publication_date, payload__message_type, payload__license_number, payload__issued_on, payload__valid_until, payload__authority, payload__document_raw, payload__terminated_on, payload__service_text, organization__full_name, organization__inn, organization__ogrn, organization__okpo, payload__classification__organization_type__name, payload__classification__establishment_kind__name, payload__budget__level__name, payload__address__region__name, payload__is_separate_division, payload__support_form__name, payload__support_kind__name, payload__support_until, payload__provider__name, payload__sme_category__name, payload__has_violation, amount, payload__membership_status, payload__region, payload__sro_name, payload__admission_date, payload__status__name, payload__executive_body_name, payload__registration_date, payload__publication_count, payload__reorganization_count, payload__captured_at. Для обратной сортировки используйте префикс -. Несколько полей перечисляются через запятую без пробелов, например -record_date,-external_id. Значения record_date с null сортируются последними.", "required": false, "schema": { "anyOf": [ @@ -10271,7 +10361,10 @@ "budget_process_registry", "integrated_structure_documents", "fedresurs_company_profile", - "enforcement_proceedings" + "enforcement_proceedings", + "leasing", + "company_messages", + "company_licenses" ] } }, @@ -10600,6 +10693,33 @@ "schema": { "type": "boolean" } + }, + { + "name": "has_leasing", + "in": "query", + "description": "Фильтр наличия группы источников leasing.", + "required": false, + "schema": { + "type": "boolean" + } + }, + { + "name": "has_company_messages", + "in": "query", + "description": "Фильтр наличия группы источников company_messages.", + "required": false, + "schema": { + "type": "boolean" + } + }, + { + "name": "has_company_licenses", + "in": "query", + "description": "Фильтр наличия группы источников company_licenses.", + "required": false, + "schema": { + "type": "boolean" + } } ], "responses": { @@ -12670,7 +12790,10 @@ "sro_membership_check", "integrated_structure_documents", "fedresurs_company_profile", - "fssp_enforcement_proceedings" + "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses" ] }, "title": { @@ -12952,7 +13075,10 @@ "sro_membership_check", "integrated_structure_documents", "fedresurs_company_profile", - "fssp_enforcement_proceedings" + "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses" ], "readOnly": true }, @@ -13793,7 +13919,10 @@ "sro_membership_check", "integrated_structure_documents", "fedresurs_company_profile", - "fssp_enforcement_proceedings" + "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses" ], "readOnly": true }, @@ -14425,6 +14554,9 @@ "integrated_structure_documents", "fedresurs_company_profile", "fssp_enforcement_proceedings", + "checko_leasing", + "checko_messages", + "checko_licenses", "financial-indicators", "public-procurements", "manufacturers-and-products", @@ -14442,6 +14574,9 @@ "sro-membership-check", "integrated-structure-documents", "fedresurs-company-profile", + "checko-leasing", + "checko-messages", + "checko-licenses", "fssp-enforcement-proceedings" ], "readOnly": true @@ -18152,6 +18287,15 @@ { "$ref": "#/components/schemas/SroMembershipRecordList" }, + { + "$ref": "#/components/schemas/CheckoLeasingRecordList" + }, + { + "$ref": "#/components/schemas/CheckoMessageRecordList" + }, + { + "$ref": "#/components/schemas/CheckoLicenseRecordList" + }, { "$ref": "#/components/schemas/FsspEnforcementProceedingRecordList" }, @@ -18180,6 +18324,9 @@ "budget_process_registry": "#/components/schemas/BudgetRegistryRecordList", "government_support": "#/components/schemas/SmeSupportRecordList", "sro_membership": "#/components/schemas/SroMembershipRecordList", + "leasing": "#/components/schemas/CheckoLeasingRecordList", + "company_messages": "#/components/schemas/CheckoMessageRecordList", + "company_licenses": "#/components/schemas/CheckoLicenseRecordList", "enforcement_proceedings": "#/components/schemas/FsspEnforcementProceedingRecordList", "integrated_structure_documents": "#/components/schemas/IntegratedStructureRecordList", "fedresurs_company_profile": "#/components/schemas/FedresursCompanyProfileRecordList" @@ -18415,7 +18562,10 @@ "budget_process_registry", "integrated_structure_documents", "fedresurs_company_profile", - "enforcement_proceedings" + "enforcement_proceedings", + "leasing", + "company_messages", + "company_licenses" ] } }, @@ -18895,6 +19045,15 @@ { "$ref": "#/components/schemas/SroMembershipRecordDetail" }, + { + "$ref": "#/components/schemas/CheckoLeasingRecordDetail" + }, + { + "$ref": "#/components/schemas/CheckoMessageRecordDetail" + }, + { + "$ref": "#/components/schemas/CheckoLicenseRecordDetail" + }, { "$ref": "#/components/schemas/FsspEnforcementProceedingRecordDetail" }, @@ -18923,6 +19082,9 @@ "budget_process_registry": "#/components/schemas/BudgetRegistryRecordDetail", "government_support": "#/components/schemas/SmeSupportRecordDetail", "sro_membership": "#/components/schemas/SroMembershipRecordDetail", + "leasing": "#/components/schemas/CheckoLeasingRecordDetail", + "company_messages": "#/components/schemas/CheckoMessageRecordDetail", + "company_licenses": "#/components/schemas/CheckoLicenseRecordDetail", "enforcement_proceedings": "#/components/schemas/FsspEnforcementProceedingRecordDetail", "integrated_structure_documents": "#/components/schemas/IntegratedStructureRecordDetail", "fedresurs_company_profile": "#/components/schemas/FedresursCompanyProfileRecordDetail" @@ -18960,7 +19122,10 @@ "budget_process_registry", "integrated_structure_documents", "fedresurs_company_profile", - "enforcement_proceedings" + "enforcement_proceedings", + "leasing", + "company_messages", + "company_licenses" ], "readOnly": true }, @@ -20896,6 +21061,18 @@ "-documents_count", "first_event_date", "-first_event_date", + "payload__publication_date", + "-payload__publication_date", + "payload__message_type", + "-payload__message_type", + "payload__license_number", + "-payload__license_number", + "payload__issued_on", + "-payload__issued_on", + "payload__valid_until", + "-payload__valid_until", + "payload__authority", + "-payload__authority", "payload__document_raw", "-payload__document_raw", "payload__terminated_on", @@ -20958,7 +21135,7 @@ }, "SourceRecordOrderingSequence": { "type": "string", - "pattern": "^(?:record_date|-record_date|record_type|-record_type|external_id|-external_id|organization__name|-organization__name|extension__organization__name|-extension__organization__name|extension__organization__full_name|-extension__organization__full_name|created_at|-created_at|updated_at|-updated_at|title|-title|uid|-uid|extension__organization__inn|-extension__organization__inn|extension__organization__ogrn|-extension__organization__ogrn|extension__organization__okpo|-extension__organization__okpo|status|-status|payload__attestation_status|-payload__attestation_status|payload__full_name|-payload__full_name|payload__medo_address|-payload__medo_address|payload__registration_number|-payload__registration_number|payload__uk_hm_treasury|-payload__uk_hm_treasury|payload__european_union|-payload__european_union|payload__united_states|-payload__united_states|payload__switzerland|-payload__switzerland|payload__united_states_sectoral|-payload__united_states_sectoral|payload__uk_uksl|-payload__uk_uksl|payload__ukraine|-payload__ukraine|payload__sentiment|-payload__sentiment|payload__news_source|-payload__news_source|events_count|-events_count|documents_count|-documents_count|first_event_date|-first_event_date|payload__document_raw|-payload__document_raw|payload__terminated_on|-payload__terminated_on|payload__service_text|-payload__service_text|organization__full_name|-organization__full_name|organization__inn|-organization__inn|organization__ogrn|-organization__ogrn|organization__okpo|-organization__okpo|payload__classification__organization_type__name|-payload__classification__organization_type__name|payload__classification__establishment_kind__name|-payload__classification__establishment_kind__name|payload__budget__level__name|-payload__budget__level__name|payload__address__region__name|-payload__address__region__name|payload__is_separate_division|-payload__is_separate_division|payload__support_form__name|-payload__support_form__name|payload__support_kind__name|-payload__support_kind__name|payload__support_until|-payload__support_until|payload__provider__name|-payload__provider__name|payload__sme_category__name|-payload__sme_category__name|payload__has_violation|-payload__has_violation|amount|-amount|payload__membership_status|-payload__membership_status|payload__region|-payload__region|payload__sro_name|-payload__sro_name|payload__admission_date|-payload__admission_date|payload__status__name|-payload__status__name|payload__executive_body_name|-payload__executive_body_name|payload__registration_date|-payload__registration_date|payload__publication_count|-payload__publication_count|payload__reorganization_count|-payload__reorganization_count|payload__captured_at|-payload__captured_at)(?:,(?:record_date|-record_date|record_type|-record_type|external_id|-external_id|organization__name|-organization__name|extension__organization__name|-extension__organization__name|extension__organization__full_name|-extension__organization__full_name|created_at|-created_at|updated_at|-updated_at|title|-title|uid|-uid|extension__organization__inn|-extension__organization__inn|extension__organization__ogrn|-extension__organization__ogrn|extension__organization__okpo|-extension__organization__okpo|status|-status|payload__attestation_status|-payload__attestation_status|payload__full_name|-payload__full_name|payload__medo_address|-payload__medo_address|payload__registration_number|-payload__registration_number|payload__uk_hm_treasury|-payload__uk_hm_treasury|payload__european_union|-payload__european_union|payload__united_states|-payload__united_states|payload__switzerland|-payload__switzerland|payload__united_states_sectoral|-payload__united_states_sectoral|payload__uk_uksl|-payload__uk_uksl|payload__ukraine|-payload__ukraine|payload__sentiment|-payload__sentiment|payload__news_source|-payload__news_source|events_count|-events_count|documents_count|-documents_count|first_event_date|-first_event_date|payload__document_raw|-payload__document_raw|payload__terminated_on|-payload__terminated_on|payload__service_text|-payload__service_text|organization__full_name|-organization__full_name|organization__inn|-organization__inn|organization__ogrn|-organization__ogrn|organization__okpo|-organization__okpo|payload__classification__organization_type__name|-payload__classification__organization_type__name|payload__classification__establishment_kind__name|-payload__classification__establishment_kind__name|payload__budget__level__name|-payload__budget__level__name|payload__address__region__name|-payload__address__region__name|payload__is_separate_division|-payload__is_separate_division|payload__support_form__name|-payload__support_form__name|payload__support_kind__name|-payload__support_kind__name|payload__support_until|-payload__support_until|payload__provider__name|-payload__provider__name|payload__sme_category__name|-payload__sme_category__name|payload__has_violation|-payload__has_violation|amount|-amount|payload__membership_status|-payload__membership_status|payload__region|-payload__region|payload__sro_name|-payload__sro_name|payload__admission_date|-payload__admission_date|payload__status__name|-payload__status__name|payload__executive_body_name|-payload__executive_body_name|payload__registration_date|-payload__registration_date|payload__publication_count|-payload__publication_count|payload__reorganization_count|-payload__reorganization_count|payload__captured_at|-payload__captured_at))+$", + "pattern": "^(?:record_date|-record_date|record_type|-record_type|external_id|-external_id|organization__name|-organization__name|extension__organization__name|-extension__organization__name|extension__organization__full_name|-extension__organization__full_name|created_at|-created_at|updated_at|-updated_at|title|-title|uid|-uid|extension__organization__inn|-extension__organization__inn|extension__organization__ogrn|-extension__organization__ogrn|extension__organization__okpo|-extension__organization__okpo|status|-status|payload__attestation_status|-payload__attestation_status|payload__full_name|-payload__full_name|payload__medo_address|-payload__medo_address|payload__registration_number|-payload__registration_number|payload__uk_hm_treasury|-payload__uk_hm_treasury|payload__european_union|-payload__european_union|payload__united_states|-payload__united_states|payload__switzerland|-payload__switzerland|payload__united_states_sectoral|-payload__united_states_sectoral|payload__uk_uksl|-payload__uk_uksl|payload__ukraine|-payload__ukraine|payload__sentiment|-payload__sentiment|payload__news_source|-payload__news_source|events_count|-events_count|documents_count|-documents_count|first_event_date|-first_event_date|payload__publication_date|-payload__publication_date|payload__message_type|-payload__message_type|payload__license_number|-payload__license_number|payload__issued_on|-payload__issued_on|payload__valid_until|-payload__valid_until|payload__authority|-payload__authority|payload__document_raw|-payload__document_raw|payload__terminated_on|-payload__terminated_on|payload__service_text|-payload__service_text|organization__full_name|-organization__full_name|organization__inn|-organization__inn|organization__ogrn|-organization__ogrn|organization__okpo|-organization__okpo|payload__classification__organization_type__name|-payload__classification__organization_type__name|payload__classification__establishment_kind__name|-payload__classification__establishment_kind__name|payload__budget__level__name|-payload__budget__level__name|payload__address__region__name|-payload__address__region__name|payload__is_separate_division|-payload__is_separate_division|payload__support_form__name|-payload__support_form__name|payload__support_kind__name|-payload__support_kind__name|payload__support_until|-payload__support_until|payload__provider__name|-payload__provider__name|payload__sme_category__name|-payload__sme_category__name|payload__has_violation|-payload__has_violation|amount|-amount|payload__membership_status|-payload__membership_status|payload__region|-payload__region|payload__sro_name|-payload__sro_name|payload__admission_date|-payload__admission_date|payload__status__name|-payload__status__name|payload__executive_body_name|-payload__executive_body_name|payload__registration_date|-payload__registration_date|payload__publication_count|-payload__publication_count|payload__reorganization_count|-payload__reorganization_count|payload__captured_at|-payload__captured_at)(?:,(?:record_date|-record_date|record_type|-record_type|external_id|-external_id|organization__name|-organization__name|extension__organization__name|-extension__organization__name|extension__organization__full_name|-extension__organization__full_name|created_at|-created_at|updated_at|-updated_at|title|-title|uid|-uid|extension__organization__inn|-extension__organization__inn|extension__organization__ogrn|-extension__organization__ogrn|extension__organization__okpo|-extension__organization__okpo|status|-status|payload__attestation_status|-payload__attestation_status|payload__full_name|-payload__full_name|payload__medo_address|-payload__medo_address|payload__registration_number|-payload__registration_number|payload__uk_hm_treasury|-payload__uk_hm_treasury|payload__european_union|-payload__european_union|payload__united_states|-payload__united_states|payload__switzerland|-payload__switzerland|payload__united_states_sectoral|-payload__united_states_sectoral|payload__uk_uksl|-payload__uk_uksl|payload__ukraine|-payload__ukraine|payload__sentiment|-payload__sentiment|payload__news_source|-payload__news_source|events_count|-events_count|documents_count|-documents_count|first_event_date|-first_event_date|payload__publication_date|-payload__publication_date|payload__message_type|-payload__message_type|payload__license_number|-payload__license_number|payload__issued_on|-payload__issued_on|payload__valid_until|-payload__valid_until|payload__authority|-payload__authority|payload__document_raw|-payload__document_raw|payload__terminated_on|-payload__terminated_on|payload__service_text|-payload__service_text|organization__full_name|-organization__full_name|organization__inn|-organization__inn|organization__ogrn|-organization__ogrn|organization__okpo|-organization__okpo|payload__classification__organization_type__name|-payload__classification__organization_type__name|payload__classification__establishment_kind__name|-payload__classification__establishment_kind__name|payload__budget__level__name|-payload__budget__level__name|payload__address__region__name|-payload__address__region__name|payload__is_separate_division|-payload__is_separate_division|payload__support_form__name|-payload__support_form__name|payload__support_kind__name|-payload__support_kind__name|payload__support_until|-payload__support_until|payload__provider__name|-payload__provider__name|payload__sme_category__name|-payload__sme_category__name|payload__has_violation|-payload__has_violation|amount|-amount|payload__membership_status|-payload__membership_status|payload__region|-payload__region|payload__sro_name|-payload__sro_name|payload__admission_date|-payload__admission_date|payload__status__name|-payload__status__name|payload__executive_body_name|-payload__executive_body_name|payload__registration_date|-payload__registration_date|payload__publication_count|-payload__publication_count|payload__reorganization_count|-payload__reorganization_count|payload__captured_at|-payload__captured_at))+$", "description": "Two or more allowlisted ordering fields, separated by commas without spaces." }, "AttachmentUnavailableError": { @@ -21934,6 +22111,942 @@ "source_row_number" ] }, + "CheckoMessageListPayload": { + "type": "object", + "properties": { + "message_guid": { + "type": "string" + }, + "publication_raw": { + "type": "string", + "nullable": true + }, + "publication_date": { + "type": "string", + "format": "date", + "nullable": true + }, + "message_type": { + "type": "string" + }, + "message_type_name": { + "type": "string", + "nullable": true + }, + "publisher_identifier": { + "type": "string" + }, + "participant_identifiers": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string", + "nullable": true + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + } + }, + "required": [ + "message_guid", + "publication_raw", + "publication_date", + "message_type", + "message_type_name", + "publisher_identifier", + "participant_identifiers", + "source_url", + "fetched_at", + "upstream" + ] + }, + "CheckoMessageDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoMessageListPayload" + } + ] + }, + "CheckoLeasingListPayload": { + "type": "object", + "properties": { + "message_guid": { + "type": "string" + }, + "publication_raw": { + "type": "string", + "nullable": true + }, + "publication_date": { + "type": "string", + "format": "date", + "nullable": true + }, + "message_type": { + "type": "string" + }, + "message_type_name": { + "type": "string", + "nullable": true + }, + "publisher_identifier": { + "type": "string" + }, + "participant_identifiers": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string", + "nullable": true + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + }, + "lease_event_type": { + "type": "string" + } + }, + "required": [ + "message_guid", + "publication_raw", + "publication_date", + "message_type", + "message_type_name", + "publisher_identifier", + "participant_identifiers", + "source_url", + "fetched_at", + "upstream", + "lease_event_type" + ] + }, + "CheckoLeasingDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoLeasingListPayload" + } + ] + }, + "CheckoLicenseListPayload": { + "type": "object", + "properties": { + "license_number": { + "type": "string" + }, + "issued_on": { + "type": "string", + "format": "date" + }, + "valid_from": { + "type": "string", + "format": "date", + "nullable": true + }, + "valid_until": { + "type": "string", + "format": "date", + "nullable": true + }, + "authority": { + "type": "string" + }, + "activities": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string" + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + } + }, + "required": [ + "license_number", + "issued_on", + "valid_from", + "valid_until", + "authority", + "activities", + "source_url", + "fetched_at", + "upstream" + ] + }, + "CheckoLicenseDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoLicenseListPayload" + } + ] + }, + "CheckoLeasingRecordList": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "leasing" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "leasing_contract" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_leasing" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoLeasingListPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, + "CheckoLeasingRecordDetail": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "leasing" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "leasing_contract" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_leasing" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoLeasingDetailPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, + "CheckoMessageRecordList": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "company_messages" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "company_message" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_messages" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoMessageListPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, + "CheckoMessageRecordDetail": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "company_messages" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "company_message" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_messages" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoMessageDetailPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, + "CheckoLicenseRecordList": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "company_licenses" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "company_license" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_licenses" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoLicenseListPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, + "CheckoLicenseRecordDetail": { + "type": "object", + "properties": { + "uid": { + "title": "UID", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "extension_uid": { + "title": "Extension uid", + "type": "string", + "format": "uuid", + "readOnly": true + }, + "source_group": { + "type": "string", + "enum": [ + "company_licenses" + ] + }, + "record_type": { + "type": "string", + "enum": [ + "company_license" + ] + }, + "source": { + "type": "string", + "enum": [ + "checko_licenses" + ] + }, + "external_id": { + "title": "Внешний ID", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "title": { + "title": "Заголовок", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "record_date": { + "title": "Record date", + "type": "string", + "format": "date", + "readOnly": true, + "nullable": true + }, + "amount": { + "title": "Сумма", + "type": "string", + "format": "decimal", + "readOnly": true, + "nullable": true + }, + "status": { + "type": "string" + }, + "url": { + "title": "URL", + "type": "string", + "readOnly": true, + "minLength": 1 + }, + "payload": { + "$ref": "#/components/schemas/CheckoLicenseDetailPayload" + }, + "legacy_model": { + "title": "Legacy model", + "type": "string", + "readOnly": true + }, + "legacy_pk": { + "title": "Legacy pk", + "type": "string", + "readOnly": true + }, + "load_batch": { + "title": "ID пакета загрузки", + "type": "integer", + "readOnly": true, + "nullable": true + }, + "created_at": { + "title": "Дата создания", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "title": "Дата обновления", + "type": "string", + "format": "date-time", + "readOnly": true + }, + "financial_lines": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrganizationSourceFinancialLine" + }, + "readOnly": true + }, + "organization": { + "$ref": "#/components/schemas/FsspSourceRecordOrganization" + } + }, + "required": [ + "source_group", + "uid", + "source", + "record_type", + "external_id", + "title", + "status", + "created_at", + "updated_at", + "organization", + "payload" + ] + }, "FsspEnforcementProceedingRecordList": { "type": "object", "properties": { diff --git a/src/organizations/checko_section_payload_serializers.py b/src/organizations/checko_section_payload_serializers.py new file mode 100644 index 0000000..8d613f3 --- /dev/null +++ b/src/organizations/checko_section_payload_serializers.py @@ -0,0 +1,41 @@ +"""Verified section payloads shared by public list and detail contracts.""" + +from rest_framework import serializers + +from organizations.registry_payload_serializers import RegistryUTCDateTimeField + + +class CheckoMessagePayloadSerializer(serializers.Serializer): + message_guid = serializers.CharField() + publication_raw = serializers.CharField(allow_null=True) + publication_date = serializers.DateField(allow_null=True) + message_type = serializers.CharField() + message_type_name = serializers.CharField(allow_null=True) + publisher_identifier = serializers.CharField() + participant_identifiers = serializers.ListField(child=serializers.CharField()) + source_url = serializers.CharField(allow_null=True) + fetched_at = RegistryUTCDateTimeField() + upstream = serializers.JSONField() + + +class CheckoLeasingPayloadSerializer(CheckoMessagePayloadSerializer): + lease_event_type = serializers.CharField() + + +class CheckoLicensePayloadSerializer(serializers.Serializer): + license_number = serializers.CharField() + issued_on = serializers.DateField() + valid_from = serializers.DateField(allow_null=True) + valid_until = serializers.DateField(allow_null=True) + authority = serializers.CharField() + activities = serializers.ListField(child=serializers.CharField()) + source_url = serializers.CharField() + fetched_at = RegistryUTCDateTimeField() + upstream = serializers.JSONField() + + +CHECKO_PAYLOAD_SERIALIZERS = { + "checko_leasing": CheckoLeasingPayloadSerializer, + "checko_messages": CheckoMessagePayloadSerializer, + "checko_licenses": CheckoLicensePayloadSerializer, +} diff --git a/src/organizations/serializers.py b/src/organizations/serializers.py index 1bd39e3..06b4511 100644 --- a/src/organizations/serializers.py +++ b/src/organizations/serializers.py @@ -322,6 +322,12 @@ class OrganizationSourceRecordSerializer(serializers.ModelSerializer): ) def get_payload(self, obj) -> dict | list | str | int | float | bool | None: # noqa: C901 payload = obj.payload + from organizations.checko_section_payload_serializers import ( + CHECKO_PAYLOAD_SERIALIZERS, + ) + + if obj.source in CHECKO_PAYLOAD_SERIALIZERS: + return CHECKO_PAYLOAD_SERIALIZERS[obj.source](payload).data if obj.source == "fssp_enforcement_proceedings": from organizations.fssp_payload_serializers import ( FsspEnforcementProceedingPayloadSerializer, diff --git a/src/organizations/source_record_export.py b/src/organizations/source_record_export.py index 9deac93..ea7198f 100644 --- a/src/organizations/source_record_export.py +++ b/src/organizations/source_record_export.py @@ -49,6 +49,9 @@ EXPORT_FORMAT_JSON = "json" EXPORT_FORMATS = (EXPORT_FORMAT_CSV, EXPORT_FORMAT_XLSX, EXPORT_FORMAT_JSON) FINANCIAL_SOURCE_GROUP = SourceGroup.FINANCIAL_INDICATORS.value ALL_HISTORY_SOURCE_GROUPS = { + "leasing", + "company_messages", + "company_licenses", SourceGroup.SRO_MEMBERSHIP.value, SourceGroup.GOVERNMENT_SUPPORT.value, SourceGroup.BUDGET_PROCESS_REGISTRY.value, @@ -80,6 +83,9 @@ EXPORT_PROVIDER_NAME_PATTERN = re.compile( ) SNAPSHOT_EXPORT_SOURCES = { + "company_licenses": "checko_licenses", + "company_messages": "checko_messages", + "leasing": "checko_leasing", "enforcement_proceedings": "fssp_enforcement_proceedings", "budget_process_registry": "budget_ubpandnubp", "government_support": "fns_sme_support_recipients", @@ -90,6 +96,9 @@ SNAPSHOT_EXPORT_SOURCES = { GENERATION_ID_PATTERN = re.compile(r"[0-9]{8}T[0-9]{6}Z-[a-f0-9]{8}") SOURCE_GROUP_EXPORT_FILE_STEMS: dict[str, str] = { + "company_licenses": "checko-licenses", + "company_messages": "checko-messages", + "leasing": "checko-leasing", SourceGroup.ENFORCEMENT_PROCEEDINGS.value: "fssp-enforcement-proceedings", SourceGroup.SRO_MEMBERSHIP.value: "sro-membership-check", SourceGroup.INTEGRATED_STRUCTURE_DOCUMENTS.value: "integrated-structure-documents", @@ -1289,7 +1298,11 @@ def _build_record_row( "updated_at": record.updated_at, **_flatten_payload(record.payload), } - public_row = _sanitize_export_provider_value(row) + public_row = ( + row + if record.source in ("checko_leasing", "checko_messages", "checko_licenses") + else _sanitize_export_provider_value(row) + ) serialized_row = { key: _serialize_json_value(value) for key, value in public_row.items() } diff --git a/src/organizations/source_record_query.py b/src/organizations/source_record_query.py index 480e2f2..b9ca647 100644 --- a/src/organizations/source_record_query.py +++ b/src/organizations/source_record_query.py @@ -27,6 +27,9 @@ from drf_yasg import openapi from rest_framework.exceptions import NotFound REGISTRY_GROUPS = ( + "company_licenses", + "company_messages", + "leasing", "enforcement_proceedings", "budget_process_registry", "government_support", @@ -35,6 +38,9 @@ REGISTRY_GROUPS = ( "fedresurs_company_profile", ) REGISTRY_SOURCE_GROUPS = { + "checko_licenses": "company_licenses", + "checko_messages": "company_messages", + "checko_leasing": "leasing", "fssp_enforcement_proceedings": "enforcement_proceedings", "budget_ubpandnubp": "budget_process_registry", "fns_sme_support_recipients": "government_support", @@ -44,6 +50,12 @@ REGISTRY_SOURCE_GROUPS = { } REGISTRY_ORDERING_FIELDS = ( + "payload__publication_date", + "payload__message_type", + "payload__license_number", + "payload__issued_on", + "payload__valid_until", + "payload__authority", "payload__document_raw", "payload__terminated_on", "payload__service_text", @@ -75,6 +87,9 @@ REGISTRY_ORDERING_FIELDS = ( "payload__captured_at", ) EXACT_FILTERS = { + "message_type": "payload__message_type", + "license_number": "payload__license_number", + "license_authority": "payload__authority", "organization_type": "payload__classification__organization_type__code", "establishment_kind": "payload__classification__establishment_kind__code", "budget_level": "payload__budget__level__code", @@ -101,6 +116,9 @@ FEDRESURS_SECTION_STATES = ( "schema_unverified", ) DATE_RANGES = { + "publication_date": "payload__publication_date", + "license_issued": "payload__issued_on", + "license_valid_until": "payload__valid_until", "date": "canonical_record_date", "registry_entry": "payload__registry_entry_date", "support_until": "payload__support_until", diff --git a/src/organizations/test_companies.py b/src/organizations/test_companies.py index 0723f15..998bf6e 100644 --- a/src/organizations/test_companies.py +++ b/src/organizations/test_companies.py @@ -44,6 +44,9 @@ CANONICAL_ONLY_TEST_SOURCES = { ParserLoadLog.Source.SRO_MEMBERSHIP_CHECK, } FILE_UPLOAD_ONLY_TEST_SOURCES = { + "checko_leasing", + "checko_messages", + "checko_licenses", # Real FSSP snapshots must not be fabricated by the demo command. ParserLoadLog.Source.FSSP_ENFORCEMENT_PROCEEDINGS, ParserLoadLog.Source.ROPK_SANCTIONS, diff --git a/tests/apps/organizations/test_canonical_openapi.py b/tests/apps/organizations/test_canonical_openapi.py index 4de7eeb..61a9167 100644 --- a/tests/apps/organizations/test_canonical_openapi.py +++ b/tests/apps/organizations/test_canonical_openapi.py @@ -36,7 +36,7 @@ def test_discriminated_records_keep_named_ordering_and_old_operations(contract): schemas = contract["components"]["schemas"] for name in ("OrganizationSourceRecord", "OrganizationSourceRecordList"): record = schemas[name] - assert len(record["oneOf"]) == 7 + assert len(record["oneOf"]) == 10 assert record["discriminator"]["propertyName"] == "source_group" for group, record_type in ( ("budget_process_registry", "budget_registry_organization"), diff --git a/tests/apps/organizations/test_checko_section_contract.py b/tests/apps/organizations/test_checko_section_contract.py new file mode 100644 index 0000000..95ad32d --- /dev/null +++ b/tests/apps/organizations/test_checko_section_contract.py @@ -0,0 +1,208 @@ +"""Three independent source APIs and full/partial task semantics.""" + +from importlib import import_module +from tempfile import TemporaryDirectory +from unittest.mock import patch + +import pytest +from apps.core.models import BackgroundJob +from apps.parsers import checko_section_snapshots as snapshots +from apps.parsers.checko_collection import claim_monthly_collection +from apps.parsers.models import ParserSourceArtifact +from apps.parsers.registry_snapshots import SnapshotValidationError +from apps.parsers.source_cards import SourceCardService +from core.celery import app as celery_app +from django.core.cache import cache +from django.test import TestCase, override_settings +from django.utils import timezone +from organizations.models import Organization +from organizations.source_groups import get_source_group_descriptor +from organizations.source_record_export import _build_record_row, _source_group_queryset +from rest_framework.test import APIClient + +from tests.apps.parsers.test_checko_sections import client_with, fixture +from tests.apps.user.factories import UserFactory + +SOURCES = { + "checko_leasing": ("leasing", "leasing_contract"), + "checko_messages": ("company_messages", "company_message"), + "checko_licenses": ("company_licenses", "company_license"), +} + + +class CheckoSectionContractTests(TestCase): + def setUp(self): + tmp = TemporaryDirectory() + self.addCleanup(tmp.cleanup) + settings = override_settings( + MEDIA_ROOT=tmp.name + "/media", + PARSER_PRIVATE_ARTIFACT_ROOT=tmp.name + "/private", + ) + settings.enable() + self.addCleanup(settings.disable) + cache.clear() + self.org = Organization.objects.create( + name="АО Проверка", + inn="7707083893", + ogrn="1027700132195", + okpo="12345678", + directory_imported_at=timezone.now(), + gk_code="rosatom", + ) + self.client = APIClient() + self.client.force_authenticate(UserFactory.create_user()) + self.url = "/api/v2/organization-source-records/" + + def transport(self, source): + return ( + client_with(fixture("license.json")) + if source == "checko_licenses" + else client_with( + fixture("messages-page-1.json"), fixture("messages-page-2.json") + ) + ) + + def run_task(self, source): + import_module("apps.parsers.tasks") + task = celery_app.tasks[f"parsers.{source}.refresh"] + with patch.object(snapshots, "_client", return_value=self.transport(source)): + return task.apply(throw=True).result + + def test_three_independent_groups_and_typed_list_detail_exports(self): + for source, (group, kind) in SOURCES.items(): + descriptor = get_source_group_descriptor(source) + assert (descriptor.source_group, descriptor.record_type) == (group, kind) + with patch.object( + snapshots, "_client", return_value=self.transport(source) + ): + snapshots.refresh_checko_section(source=source, load_batch=1) + response = self.client.get(self.url, {"source_group": group}) + assert response.status_code == 200, response.data + assert response.data["data"], response.data + for row in response.data["data"]: + assert row["source"] == source + assert row["record_type"] == kind + assert row["amount"] is None + assert row["payload"]["fetched_at"].endswith("Z") + assert row["organization"]["inn"] == self.org.inn + detail = self.client.get(self.url + row["uid"] + "/") + assert detail.status_code == 200, detail.data + assert detail.data["payload"] == row["payload"] + record = _source_group_queryset(group, export_year=2026).get( + uid=row["uid"] + ) + exported = _build_record_row(record, include_financial_lines=False) + assert exported["source"] == source + assert exported["payload.source_url"] == row["payload"]["source_url"] + if source == "checko_licenses": + assert response.data["data"][0]["payload"]["valid_until"] is None + + def test_partial_does_not_move_full_last_success_and_keeps_mixed_batches_visible( + self, + ): + source = "checko_messages" + full = self.run_task(source) + assert full["completeness"] == "full" + before = SourceCardService.get_card("checko-messages")["latest_success_load"][ + "batch_id" + ] + org2 = Organization.objects.create( + name="АО Второй", + inn="7702070139", + ogrn="1027700070518", + okpo="87654321", + directory_imported_at=timezone.now(), + opk_registry_membership=True, + ) + original_collect = snapshots.collect_checko_section + + def collected(client, *, organization, source): + # Real adapter, identical structure for the second canonical identity. + responses = [ + fixture("messages-page-1.json"), + fixture("messages-page-2.json"), + ] + for page in responses: + page["company"] = {"ИНН": org2.inn, "ОГРН": org2.ogrn} + for row in page["data"]["Записи"]: + row["Публикатор"] = org2.ogrn + row["Участники"] = [org2.inn] + yield from original_collect( + client_with(*responses), organization=organization, source=source + ) + + with patch.object(snapshots, "collect_checko_section", collected): + partial = self.run_task(source) + assert partial["completeness"] == "partial" + assert partial["quota_skipped"] == partial["organizations_preserved"] == 1 + assert partial["organizations_updated"] == 1 + card = SourceCardService.get_card("checko-messages") + assert card["latest_success_load"]["batch_id"] == before + assert card["latest_load"]["meta"]["completeness"] == "partial" + response = self.client.get(self.url, {"source_group": "company_messages"}) + assert response.status_code == 200, response.data + assert {row["load_batch"] for row in response.data["data"]} == { + full["batch_id"], + partial["batch_id"], + } + assert len(response.data["data"]) == 4 + assert ( + BackgroundJob.objects.order_by("-created_at").first().result["completeness"] + == "partial" + ) + + def test_no_completed_failure_exposes_rejected_counters(self): + source = "checko_messages" + claim_monthly_collection(organization_id=str(self.org.uid), source=source) + with pytest.raises(SnapshotValidationError, match="no_completed_organizations"): + self.run_task(source) + job = BackgroundJob.objects.get() + assert job.status == "failure" + assert job.result["quota_skipped"] == 1 + assert job.result["organizations_preserved"] == 1 + assert job.result["completeness"] == "partial" + assert job.result["artifact_id"] == str(ParserSourceArtifact.objects.get().uid) + assert ( + SourceCardService.get_card("checko-messages")["latest_success_load"] is None + ) + + +@pytest.mark.django_db +@pytest.mark.parametrize("source", SOURCES) +def test_refresh_and_run_share_guard_permissions_and_no_file_url(source): + import_module("apps.parsers.tasks") + task = celery_app.tasks[f"parsers.{source}.refresh"] + client = APIClient() + client.force_authenticate(UserFactory.create_user()) + slug = source.replace("_", "-") + urls = [f"/api/v1/sources/{slug}/refresh/", f"/api/v1/parsers/run/{source}/"] + for url in urls: + assert client.post(url, {}, format="json").status_code == 403 + client.force_authenticate(UserFactory.create_user(is_staff=True)) + for url in urls: + assert ( + client.post( + url, {"params": {"file_url": "https://foreign.invalid"}}, format="json" + ).status_code + == 400 + ) + with patch.object(task, "apply_async"): + assert client.post(urls[0], {}, format="json").status_code == 202 + assert client.post(urls[1], {}, format="json").status_code == 409 + assert BackgroundJob.objects.count() == 1 + + +def test_checko_discriminated_variants_in_canonical_document(): + import json + from pathlib import Path + + document = json.loads( + (Path(__file__).parents[3] / "src/core/openapi.json").read_text() + ) + schemas = document["components"]["schemas"] + for name in ("OrganizationSourceRecordList", "OrganizationSourceRecord"): + mapping = schemas[name]["discriminator"]["mapping"] + for source, (group, kind) in SOURCES.items(): + variant = schemas[mapping[group].rsplit("/", 1)[1]] + assert variant["properties"]["source"]["enum"] == [source] + assert variant["properties"]["record_type"]["enum"] == [kind] diff --git a/tests/apps/organizations/test_openapi_runtime_fixtures.py b/tests/apps/organizations/test_openapi_runtime_fixtures.py index bb25ba3..91b8684 100644 --- a/tests/apps/organizations/test_openapi_runtime_fixtures.py +++ b/tests/apps/organizations/test_openapi_runtime_fixtures.py @@ -8,6 +8,7 @@ from uuid import uuid4 import pytest from apps.parsers.budget_registry import normalize_budget_record +from apps.parsers.checko_sections import collect_checko_section from apps.parsers.fssp_csv import FSSP_SOURCE, GENERAL_DATASET, iter_fssp_records from apps.parsers.models import ParserSourceArtifact from apps.parsers.sme_support import support_payload @@ -19,6 +20,7 @@ from organizations.models import Organization, OrganizationSourceRecord from organizations.source_groups import get_source_group_descriptor from rest_framework.test import APIClient +from tests.apps.parsers.test_checko_sections import client_with, fixture from tests.apps.parsers.test_registry_payload_contract import full_budget_fixture from tests.apps.parsers.test_registry_snapshots import _xml from tests.apps.user.factories import UserFactory @@ -134,7 +136,34 @@ def _canonical_records(): "payload": row.payload, }, ) - return [budget, sme, sro, fssp], raw_budget + sections = [] + for source in ("checko_leasing", "checko_messages", "checko_licenses"): + client = ( + client_with(fixture("license.json")) + if source == "checko_licenses" + else client_with( + fixture("messages-page-1.json"), fixture("messages-page-2.json") + ) + ) + row = next(collect_checko_section(client, organization=fssp_org, source=source)) + row.payload["upstream"]["future_nested"] = { + "keep": [None, False, 0, {"unknown": "0007"}] + } + sections.append( + _create_record( + fssp_org, + source, + { + "title": row.title, + "record_date": row.record_date, + "amount": None, + "status": row.status, + "url": row.url, + "payload": row.payload, + }, + ) + ) + return [budget, sme, sro, fssp, *sections], raw_budget @pytest.mark.django_db @@ -155,8 +184,8 @@ def test_source_record_runtime_fixtures(): return body mixed = capture("mixed-list", "list", client.get(list_url)) - assert len(mixed["data"]) == 4 - assert mixed["meta"]["pagination"]["total_count"] == 4 + assert len(mixed["data"]) == 7 + assert mixed["meta"]["pagination"]["total_count"] == 7 details = {} for record in records: listing = capture( diff --git a/tests/apps/organizations/test_source_export_snapshot_contract.py b/tests/apps/organizations/test_source_export_snapshot_contract.py index 33278e6..46c179a 100644 --- a/tests/apps/organizations/test_source_export_snapshot_contract.py +++ b/tests/apps/organizations/test_source_export_snapshot_contract.py @@ -69,6 +69,9 @@ def issue(client, group="budget_process_registry", file_format="json"): @pytest.mark.parametrize( "source,group", [ + ("checko_leasing", "leasing"), + ("checko_messages", "company_messages"), + ("checko_licenses", "company_licenses"), ("budget_ubpandnubp", "budget_process_registry"), ("fssp_enforcement_proceedings", "enforcement_proceedings"), ], @@ -217,7 +220,7 @@ def test_sro_export_keeps_all_years_and_identifier_strings(export_client, file_f record_date="2001-01-01", ) generation = exports.build_source_record_export_artifacts() - assert generation.artifacts_count == 52 + assert generation.artifacts_count == 61 response = issue(export_client, "sro_membership", file_format) assert response.status_code == 201 package = exports.consume_source_record_export_download_ticket( diff --git a/tests/apps/organizations/test_source_record_export.py b/tests/apps/organizations/test_source_record_export.py index b6f9031..a37fff2 100644 --- a/tests/apps/organizations/test_source_record_export.py +++ b/tests/apps/organizations/test_source_record_export.py @@ -128,9 +128,9 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase): call_command("build_source_record_exports", stdout=command_output) generation = load_current_source_record_export_generation() - self.assertEqual(generation.artifacts_count, 52) + self.assertEqual(generation.artifacts_count, 61) self.assertEqual(generation.export_year, timezone.localdate().year) - self.assertIn('"artifacts_count": 52', command_output.getvalue()) + self.assertIn('"artifacts_count": 61', command_output.getvalue()) def test_sanctions_xlsx_export_uses_source_contract_columns_and_boolean_flags(self): organization = Organization.objects.create( @@ -641,7 +641,7 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase): self.assertEqual( response["X-Source-Export-Generated-At"], generation.generated_at ) - self.assertEqual(generation.artifacts_count, 52) + self.assertEqual(generation.artifacts_count, 61) self.assertIn( 'filename="planned-inspections__financial-indicators_', response["Content-Disposition"], @@ -840,8 +840,8 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase): key=lambda item: item.file_name, ) - self.assertEqual(generation.artifacts_count, 52) - self.assertEqual(generation.files_count, 53) + self.assertEqual(generation.artifacts_count, 61) + self.assertEqual(generation.files_count, 62) self.assertEqual( [item.file_name for item in artifacts], [ @@ -1065,7 +1065,7 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase): first_generation = build_source_record_export_artifacts() current_generation = load_current_source_record_export_generation() - self.assertEqual(first_generation.artifacts_count, 52) + self.assertEqual(first_generation.artifacts_count, 61) self.assertEqual( current_generation.generation_id, first_generation.generation_id ) diff --git a/tests/apps/organizations/test_tasks.py b/tests/apps/organizations/test_tasks.py index acca47e..708a829 100644 --- a/tests/apps/organizations/test_tasks.py +++ b/tests/apps/organizations/test_tasks.py @@ -147,7 +147,7 @@ class SourceRecordExportArtifactsTaskTest(TestCase): result = refresh_source_record_export_artifacts() self.assertEqual(result["status"], "success") - self.assertEqual(result["artifacts_count"], 52) + self.assertEqual(result["artifacts_count"], 61) self.assertEqual(result["export_year"], timezone.localdate().year) self.assertIsNone(cache.get(settings.SOURCE_RECORD_EXPORT_LOCK_KEY)) diff --git a/tests/apps/organizations/test_test_companies_commands.py b/tests/apps/organizations/test_test_companies_commands.py index 1d4e913..72aa458 100644 --- a/tests/apps/organizations/test_test_companies_commands.py +++ b/tests/apps/organizations/test_test_companies_commands.py @@ -80,6 +80,9 @@ class TestCompaniesCommandsTest(TestCase): ParserLoadLog.Source.INTEGRATED_STRUCTURE_DOCUMENTS, ParserLoadLog.Source.FEDRESURS_COMPANY_PROFILE, ParserLoadLog.Source.FSSP_ENFORCEMENT_PROCEEDINGS, + ParserLoadLog.Source.CHECKO_LEASING, + ParserLoadLog.Source.CHECKO_MESSAGES, + ParserLoadLog.Source.CHECKO_LICENSES, } } for company in companies: @@ -274,7 +277,7 @@ class TestCompaniesCommandsTest(TestCase): ) self.assertEqual( OrganizationSourceRecord.objects.count(), - 20 * (len(ParserLoadLog.Source) - 4), + 20 * (len(ParserLoadLog.Source) - 7), ) def test_create_replaces_stale_source_record_for_same_legacy_row(self): diff --git a/tests/apps/parsers/test_refresh_concurrency.py b/tests/apps/parsers/test_refresh_concurrency.py index 7826c5d..ccba743 100644 --- a/tests/apps/parsers/test_refresh_concurrency.py +++ b/tests/apps/parsers/test_refresh_concurrency.py @@ -31,6 +31,9 @@ def _parallel(actions): @pytest.mark.parametrize( "slug,source", [ + ("checko-leasing", "checko_leasing"), + ("checko-messages", "checko_messages"), + ("checko-licenses", "checko_licenses"), ("sme-support-recipients-registry", "fns_sme_support_recipients"), ("budget-process-registry", "budget_ubpandnubp"), ("sro-membership-check", "sro_membership_check"), diff --git a/tests/apps/parsers/test_source_cards_service.py b/tests/apps/parsers/test_source_cards_service.py index 586155a..de83e99 100644 --- a/tests/apps/parsers/test_source_cards_service.py +++ b/tests/apps/parsers/test_source_cards_service.py @@ -97,6 +97,9 @@ class SourceCardServiceUnitTest(TestCase): "sro-membership-check", "integrated-structure-documents", "fedresurs-company-profile", + "checko-leasing", + "checko-messages", + "checko-licenses", "fssp-enforcement-proceedings", ], ) @@ -120,6 +123,9 @@ class SourceCardServiceUnitTest(TestCase): "Проверка членства в СРО", "Документы интегрированных структур", "Федресурс: сведения о юридических лицах", + "Лизинг", + "Сообщения организаций", + "Лицензии организаций", "ФССП: Банк данных исполнительных производств", ], ) diff --git a/tests/apps/parsers/test_source_registry.py b/tests/apps/parsers/test_source_registry.py index b038a85..d04cf31 100644 --- a/tests/apps/parsers/test_source_registry.py +++ b/tests/apps/parsers/test_source_registry.py @@ -50,7 +50,8 @@ class ParserSourceRegistryPresentationTest(SimpleTestCase): public_metadata = " ".join( str(value) for descriptor in PARSER_SOURCES.values() - for value in asdict(descriptor).values() + for field, value in asdict(descriptor).items() + if field not in {"key", "source", "task_name"} ) self.assertNotIn("checko", public_metadata.lower()) diff --git a/tools/openapi/build.mjs b/tools/openapi/build.mjs index 0d28c0e..191b399 100644 --- a/tools/openapi/build.mjs +++ b/tools/openapi/build.mjs @@ -26,6 +26,9 @@ const variants = [ ['SroMembership', 'sro_membership', 'sro_membership_check', 'sro_membership', 'SroMembership'], ]; const extendedVariants = [ + ['CheckoLeasing', 'leasing', 'checko_leasing', 'leasing_contract', 'CheckoLeasing'], + ['CheckoMessage', 'company_messages', 'checko_messages', 'company_message', 'CheckoMessage'], + ['CheckoLicense', 'company_licenses', 'checko_licenses', 'company_license', 'CheckoLicense'], ['FsspEnforcementProceeding', 'enforcement_proceedings', 'fssp_enforcement_proceedings', 'enforcement_proceeding', 'FsspEnforcementProceeding'], ['IntegratedStructure', 'integrated_structure_documents', 'integrated_structures', 'integrated_structure', 'IntegratedStructure'], ['FedresursCompanyProfile', 'fedresurs_company_profile', 'fedresurs_company_profile', 'company_profile', 'FedresursCompanyProfile'], @@ -144,6 +147,9 @@ for (const [prefix, group, source, recordType, payloadPrefix] of extendedVariant schema.properties.status = { type: 'string' }; schema.properties.payload = ref(payloadName); schema.properties.organization = ref('SroSourceRecordOrganization'); + if (['leasing', 'company_messages', 'company_licenses'].includes(group)) { + schema.properties.organization = ref('FsspSourceRecordOrganization'); + } if (group === 'enforcement_proceedings') { schema.required = [...new Set([...schema.required, 'extension_uid', 'record_date', 'amount', 'url', 'legacy_model', 'legacy_pk', 'load_batch', 'financial_lines'])]; schema.properties.status = { type: 'string', enum: ['unknown', 'ended', 'terminated'] }; diff --git a/tools/openapi/check-runtime.mjs b/tools/openapi/check-runtime.mjs index b5a5e6e..76b3724 100644 --- a/tools/openapi/check-runtime.mjs +++ b/tools/openapi/check-runtime.mjs @@ -17,7 +17,7 @@ const schemas = new Map([ ]); const requiredCases = new Set([ 'mixed-list', 'empty-list', 'invalid-list', 'invalid-detail', 'missing-detail', - ...['budget_ubpandnubp', 'fns_sme_support_recipients', 'sro_membership_check', 'fssp_enforcement_proceedings'] + ...['budget_ubpandnubp', 'fns_sme_support_recipients', 'sro_membership_check', 'fssp_enforcement_proceedings', 'checko_leasing', 'checko_messages', 'checko_licenses'] .flatMap(source => [`${source}-list`, `${source}-detail`]), ]); diff --git a/tools/openapi/source-record-extensions.json b/tools/openapi/source-record-extensions.json index 34331ff..ce9769d 100644 --- a/tools/openapi/source-record-extensions.json +++ b/tools/openapi/source-record-extensions.json @@ -971,5 +971,197 @@ "raw_columns", "source_row_number" ] + }, + "CheckoMessageListPayload": { + "type": "object", + "properties": { + "message_guid": { + "type": "string" + }, + "publication_raw": { + "type": "string", + "nullable": true + }, + "publication_date": { + "type": "string", + "format": "date", + "nullable": true + }, + "message_type": { + "type": "string" + }, + "message_type_name": { + "type": "string", + "nullable": true + }, + "publisher_identifier": { + "type": "string" + }, + "participant_identifiers": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string", + "nullable": true + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + } + }, + "required": [ + "message_guid", + "publication_raw", + "publication_date", + "message_type", + "message_type_name", + "publisher_identifier", + "participant_identifiers", + "source_url", + "fetched_at", + "upstream" + ] + }, + "CheckoMessageDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoMessageListPayload" + } + ] + }, + "CheckoLeasingListPayload": { + "type": "object", + "properties": { + "message_guid": { + "type": "string" + }, + "publication_raw": { + "type": "string", + "nullable": true + }, + "publication_date": { + "type": "string", + "format": "date", + "nullable": true + }, + "message_type": { + "type": "string" + }, + "message_type_name": { + "type": "string", + "nullable": true + }, + "publisher_identifier": { + "type": "string" + }, + "participant_identifiers": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string", + "nullable": true + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + }, + "lease_event_type": { + "type": "string" + } + }, + "required": [ + "message_guid", + "publication_raw", + "publication_date", + "message_type", + "message_type_name", + "publisher_identifier", + "participant_identifiers", + "source_url", + "fetched_at", + "upstream", + "lease_event_type" + ] + }, + "CheckoLeasingDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoLeasingListPayload" + } + ] + }, + "CheckoLicenseListPayload": { + "type": "object", + "properties": { + "license_number": { + "type": "string" + }, + "issued_on": { + "type": "string", + "format": "date" + }, + "valid_from": { + "type": "string", + "format": "date", + "nullable": true + }, + "valid_until": { + "type": "string", + "format": "date", + "nullable": true + }, + "authority": { + "type": "string" + }, + "activities": { + "type": "array", + "items": { + "type": "string" + } + }, + "source_url": { + "type": "string" + }, + "fetched_at": { + "type": "string", + "format": "date-time" + }, + "upstream": { + "type": "object", + "additionalProperties": true + } + }, + "required": [ + "license_number", + "issued_on", + "valid_from", + "valid_until", + "authority", + "activities", + "source_url", + "fetched_at", + "upstream" + ] + }, + "CheckoLicenseDetailPayload": { + "allOf": [ + { + "$ref": "#/components/schemas/CheckoLicenseListPayload" + } + ] } }