mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-24 01:28:42 +02: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")
|
fields: list[str] = Field(..., description="Compare fields for deduplication")
|
||||||
match_type: Literal["lax", "strict"] = "lax"
|
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):
|
class ReplaceTransformationRule(BaseModel):
|
||||||
type: Literal["replace", "regex"] = Field(
|
type: Literal["replace", "regex"] = Field(
|
||||||
@@ -103,7 +97,7 @@ class TransactionTypeMapping(ColumnMapping):
|
|||||||
|
|
||||||
class TransactionIsPaidMapping(ColumnMapping):
|
class TransactionIsPaidMapping(ColumnMapping):
|
||||||
target: Literal["is_paid"] = Field(..., description="Transaction field to map to")
|
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)
|
coerce_to: Literal["is_paid"] = Field("is_paid", frozen=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -151,6 +145,7 @@ class TransactionTagsMapping(ColumnMapping):
|
|||||||
|
|
||||||
class TransactionEntitiesMapping(ColumnMapping):
|
class TransactionEntitiesMapping(ColumnMapping):
|
||||||
target: Literal["entities"] = Field(..., description="Transaction field to map to")
|
target: Literal["entities"] = Field(..., description="Transaction field to map to")
|
||||||
|
type: Literal["id", "name"] = "name"
|
||||||
create: bool = Field(
|
create: bool = Field(
|
||||||
default=True, description="Create new entities if they doesn't exist"
|
default=True, description="Create new entities if they doesn't exist"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -296,14 +296,19 @@ class ImportService:
|
|||||||
for entity_name in entity_names:
|
for entity_name in entity_names:
|
||||||
try:
|
try:
|
||||||
if entities_mapping:
|
if entities_mapping:
|
||||||
if getattr(entities_mapping, "create", False):
|
if entities_mapping.type == "id":
|
||||||
entity, _ = TransactionEntity.objects.get_or_create(
|
entity = TransactionTag.objects.filter(
|
||||||
name=entity_name.strip()
|
id=entity_name
|
||||||
)
|
|
||||||
else:
|
|
||||||
entity = TransactionEntity.objects.filter(
|
|
||||||
name=entity_name.strip()
|
|
||||||
).first()
|
).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:
|
if entity:
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
@@ -468,9 +473,7 @@ class ImportService:
|
|||||||
raise ValueError("Invalid transaction type detection method")
|
raise ValueError("Invalid transaction type detection method")
|
||||||
elif coerce_to == "is_paid":
|
elif coerce_to == "is_paid":
|
||||||
if isinstance(mapping, version_1.TransactionIsPaidMapping):
|
if isinstance(mapping, version_1.TransactionIsPaidMapping):
|
||||||
if mapping.detection_method == "sign":
|
if mapping.detection_method == "boolean":
|
||||||
return not value.startswith("-")
|
|
||||||
elif mapping.detection_method == "boolean":
|
|
||||||
return value.lower() in ["true", "1", "yes", "y", "on"]
|
return value.lower() in ["true", "1", "yes", "y", "on"]
|
||||||
elif mapping.detection_method == "always_paid":
|
elif mapping.detection_method == "always_paid":
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user