mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-03-24 02:11:18 +01:00
feat(import): final changes for release
This commit is contained in:
@@ -7,12 +7,6 @@ class CompareDeduplicationRule(BaseModel):
|
||||
fields: list[str] = Field(..., description="Compare fields for deduplication")
|
||||
match_type: Literal["lax", "strict"] = "lax"
|
||||
|
||||
@field_validator("fields", mode="before")
|
||||
def coerce_fields_to_dict(cls, v):
|
||||
if isinstance(v, list):
|
||||
return {k: v for d in v for k, v in d.items()}
|
||||
return v
|
||||
|
||||
|
||||
class ReplaceTransformationRule(BaseModel):
|
||||
type: Literal["replace", "regex"] = Field(
|
||||
@@ -103,7 +97,7 @@ class TransactionTypeMapping(ColumnMapping):
|
||||
|
||||
class TransactionIsPaidMapping(ColumnMapping):
|
||||
target: Literal["is_paid"] = Field(..., description="Transaction field to map to")
|
||||
detection_method: Literal["sign", "boolean", "always_paid", "always_unpaid"]
|
||||
detection_method: Literal["boolean", "always_paid", "always_unpaid"]
|
||||
coerce_to: Literal["is_paid"] = Field("is_paid", frozen=True)
|
||||
|
||||
|
||||
@@ -151,6 +145,7 @@ class TransactionTagsMapping(ColumnMapping):
|
||||
|
||||
class TransactionEntitiesMapping(ColumnMapping):
|
||||
target: Literal["entities"] = Field(..., description="Transaction field to map to")
|
||||
type: Literal["id", "name"] = "name"
|
||||
create: bool = Field(
|
||||
default=True, description="Create new entities if they doesn't exist"
|
||||
)
|
||||
|
||||
@@ -296,14 +296,19 @@ class ImportService:
|
||||
for entity_name in entity_names:
|
||||
try:
|
||||
if entities_mapping:
|
||||
if getattr(entities_mapping, "create", False):
|
||||
entity, _ = TransactionEntity.objects.get_or_create(
|
||||
name=entity_name.strip()
|
||||
)
|
||||
else:
|
||||
entity = TransactionEntity.objects.filter(
|
||||
name=entity_name.strip()
|
||||
if entities_mapping.type == "id":
|
||||
entity = TransactionTag.objects.filter(
|
||||
id=entity_name
|
||||
).first()
|
||||
else: # name
|
||||
if getattr(entities_mapping, "create", False):
|
||||
entity, _ = TransactionEntity.objects.get_or_create(
|
||||
name=entity_name.strip()
|
||||
)
|
||||
else:
|
||||
entity = TransactionEntity.objects.filter(
|
||||
name=entity_name.strip()
|
||||
).first()
|
||||
|
||||
if entity:
|
||||
entities.append(entity)
|
||||
@@ -468,9 +473,7 @@ class ImportService:
|
||||
raise ValueError("Invalid transaction type detection method")
|
||||
elif coerce_to == "is_paid":
|
||||
if isinstance(mapping, version_1.TransactionIsPaidMapping):
|
||||
if mapping.detection_method == "sign":
|
||||
return not value.startswith("-")
|
||||
elif mapping.detection_method == "boolean":
|
||||
if mapping.detection_method == "boolean":
|
||||
return value.lower() in ["true", "1", "yes", "y", "on"]
|
||||
elif mapping.detection_method == "always_paid":
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user