fix(organizations): reconcile stale demo source links
All checks were successful
All checks were successful
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user