feat(organizations): migrate source storage to polymorphic records
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Backfill polymorphic organization source extensions."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from apps.core.management.commands.base import BaseAppCommand
|
||||
|
||||
from organizations.source_backfill import OrganizationSourceBackfillService
|
||||
|
||||
|
||||
class Command(BaseAppCommand):
|
||||
"""Backfill organization source extensions from legacy parser tables."""
|
||||
|
||||
help = "Переносит legacy parser records в polymorphic source extensions"
|
||||
use_transaction = False
|
||||
|
||||
def add_arguments(self, parser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument(
|
||||
"--source",
|
||||
dest="source",
|
||||
default=None,
|
||||
help="Источник ParserLoadLog.Source. Если не задан, обрабатываются все.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--batch-id",
|
||||
dest="batch_id",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Ограничить перенос одним load_batch.",
|
||||
)
|
||||
|
||||
def execute_command(self, *args, **options) -> str:
|
||||
result = OrganizationSourceBackfillService.backfill(
|
||||
source=options.get("source"),
|
||||
batch_id=options.get("batch_id"),
|
||||
)
|
||||
rendered = json.dumps(
|
||||
{
|
||||
"scanned": result.scanned,
|
||||
"created_organizations": result.created_organizations,
|
||||
"created_extensions": result.created_extensions,
|
||||
"updated_extensions": result.updated_extensions,
|
||||
"created_records": result.created_records,
|
||||
"updated_records": result.updated_records,
|
||||
"created_financial_lines": result.created_financial_lines,
|
||||
"updated_financial_lines": result.updated_financial_lines,
|
||||
"unresolved": result.unresolved,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
)
|
||||
self.log_success(rendered)
|
||||
return rendered
|
||||
Reference in New Issue
Block a user