fix(organizations): reconcile stale demo source links
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 1m8s
CI/CD Pipeline / Build and Push Images (push) Successful in 31s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 32s

This commit is contained in:
2026-08-10 14:32:04 +02:00
parent d079c74ecf
commit d03f38414a
2 changed files with 47 additions and 0 deletions

View File

@@ -200,6 +200,25 @@ class TestCompanyDatasetService:
f"{legacy_module}.{legacy_record.__class__.__name__}"
)
record.legacy_pk = str(legacy_record.pk)
legacy_owner = (
OrganizationSourceRecord.objects.filter(
legacy_model=record.legacy_model,
legacy_pk=record.legacy_pk,
)
.exclude(pk=record.pk)
.select_related("extension")
.first()
)
if legacy_owner is not None:
if (
legacy_owner.source != source
or legacy_owner.extension.organization_id != organization.pk
):
raise RuntimeError(
"Legacy parser record is already linked to another "
"organization source record"
)
legacy_owner.delete()
record.save(update_fields=["legacy_model", "legacy_pk", "updated_at"])
if source == ParserLoadLog.Source.FNS_REPORTS:
cls._refresh_financial_lines(