From 096f24e0a2347359a63adb3ea0f356ef8540f8a6 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Thu, 23 Jan 2025 16:32:08 -0300 Subject: [PATCH] feat(import): cleanup --- app/apps/import_app/schemas.py | 0 app/apps/import_app/schemas/v1.py | 11 ++++++----- app/apps/import_app/services/v1.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 app/apps/import_app/schemas.py diff --git a/app/apps/import_app/schemas.py b/app/apps/import_app/schemas.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/apps/import_app/schemas/v1.py b/app/apps/import_app/schemas/v1.py index 22df7c2..f5710f6 100644 --- a/app/apps/import_app/schemas/v1.py +++ b/app/apps/import_app/schemas/v1.py @@ -17,7 +17,6 @@ class CompareDeduplicationRule(BaseModel): class ReplaceTransformationRule(BaseModel): - field: str type: Literal["replace", "regex"] = Field( ..., description="Type of transformation: replace or regex" ) @@ -30,9 +29,8 @@ class ReplaceTransformationRule(BaseModel): class DateFormatTransformationRule(BaseModel): - field: str type: Literal["date_format"] = Field( - ..., description="Type of transformation: replace or regex" + ..., description="Type of transformation: date_format" ) original_format: str = Field(..., description="Original date format") new_format: str = Field(..., description="New date format to use") @@ -50,7 +48,6 @@ class MergeTransformationRule(BaseModel): class SplitTransformationRule(BaseModel): - fields: List[str] type: Literal["split"] separator: str = Field(default=",", description="Separator to use when splitting") index: int | None = Field( @@ -97,6 +94,7 @@ class TransactionAccountMapping(ColumnMapping): target: Literal["account"] = Field(..., description="Transaction field to map to") type: Literal["id", "name"] = "name" coerce_to: Literal["str|int"] = Field("str|int", frozen=True) + required: bool = Field(True, frozen=True) class TransactionTypeMapping(ColumnMapping): @@ -115,6 +113,7 @@ class TransactionDateMapping(ColumnMapping): target: Literal["date"] = Field(..., description="Transaction field to map to") format: List[str] | str coerce_to: Literal["date"] = Field("date", frozen=True) + required: bool = Field(True, frozen=True) class TransactionReferenceDateMapping(ColumnMapping): @@ -128,6 +127,7 @@ class TransactionReferenceDateMapping(ColumnMapping): class TransactionAmountMapping(ColumnMapping): target: Literal["amount"] = Field(..., description="Transaction field to map to") coerce_to: Literal["positive_decimal"] = Field("positive_decimal", frozen=True) + required: bool = Field(True, frozen=True) class TransactionDescriptionMapping(ColumnMapping): @@ -144,6 +144,7 @@ class TransactionNotesMapping(ColumnMapping): class TransactionTagsMapping(ColumnMapping): target: Literal["tags"] = Field(..., description="Transaction field to map to") + type: Literal["id", "name"] = "name" create: bool = Field( default=True, description="Create new tags if they doesn't exist" ) @@ -218,7 +219,7 @@ class EntityNameMapping(ColumnMapping): class EntityActiveMapping(ColumnMapping): - target: Literal["entitiy_active"] = Field(..., description="Entity field to map to") + target: Literal["entity_active"] = Field(..., description="Entity field to map to") coerce_to: Literal["bool"] = Field("bool", frozen=True) diff --git a/app/apps/import_app/services/v1.py b/app/apps/import_app/services/v1.py index abda751..d49ef9a 100644 --- a/app/apps/import_app/services/v1.py +++ b/app/apps/import_app/services/v1.py @@ -200,14 +200,14 @@ class ImportService: # self.import_run.acc.add(category) if "tags" in data: - tag_names = data.pop("tags").split(",") + tag_names = data.pop("tags") for tag_name in tag_names: tag, _ = TransactionTag.objects.get_or_create(name=tag_name.strip()) tags.append(tag) self.import_run.tags.add(tag) if "entities" in data: - entity_names = data.pop("entities").split(",") + entity_names = data.pop("entities") for entity_name in entity_names: entity, _ = TransactionEntity.objects.get_or_create( name=entity_name.strip()