feat: export registry memberships to state corp
This commit is contained in:
@@ -96,6 +96,10 @@ class StateCorpExchangeService:
|
||||
}
|
||||
data = {
|
||||
"organizations": cls._serialize_organizations(organizations),
|
||||
"registry_memberships": cls._serialize_registry_memberships(
|
||||
organizations=organizations,
|
||||
actual_date=snapshot_date,
|
||||
),
|
||||
"industrial_certificates": cls._serialize_industrial_certificates(
|
||||
allowed_inns
|
||||
),
|
||||
@@ -123,6 +127,7 @@ class StateCorpExchangeService:
|
||||
"package_id": package_id,
|
||||
"source_system": source_system,
|
||||
"produced_at": produced_at.isoformat(),
|
||||
"actual_date": snapshot_date.isoformat(),
|
||||
"schema_version": cls.SCHEMA_VERSION,
|
||||
"sections": [key for key, items in data.items() if items],
|
||||
},
|
||||
@@ -323,6 +328,47 @@ class StateCorpExchangeService:
|
||||
for item in organizations
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _serialize_registry_memberships(
|
||||
cls,
|
||||
*,
|
||||
organizations: list[Organization],
|
||||
actual_date: date,
|
||||
) -> list[dict[str, str | None]]:
|
||||
organization_ids = [organization.id for organization in organizations]
|
||||
if not organization_ids:
|
||||
return []
|
||||
|
||||
memberships = (
|
||||
RegistryMembershipPeriod.objects.select_related("registry", "organization")
|
||||
.filter(
|
||||
organization_id__in=organization_ids,
|
||||
registry__name__in=cls.ROSATOM_ROSCOSMOS_REGISTRY_NAMES,
|
||||
started_at__lte=actual_date,
|
||||
)
|
||||
.filter(Q(ended_at__isnull=True) | Q(ended_at__gt=actual_date))
|
||||
.order_by(
|
||||
"registry__name",
|
||||
"organization__mn_inn",
|
||||
"started_at",
|
||||
"id",
|
||||
)
|
||||
)
|
||||
|
||||
return [
|
||||
{
|
||||
"organization_inn": str(membership.organization.mn_inn),
|
||||
"registry_name": membership.registry.name,
|
||||
"started_at": membership.started_at.isoformat(),
|
||||
"ended_at": (
|
||||
membership.ended_at.isoformat()
|
||||
if membership.ended_at and membership.ended_at <= actual_date
|
||||
else None
|
||||
),
|
||||
}
|
||||
for membership in memberships
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _serialize_industrial_certificates(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user