Add asset records, claims, and credit workflows

This commit is contained in:
Marcel Peterkau
2026-06-26 23:03:06 +02:00
parent 30b6d253b2
commit d1dab793a6
11 changed files with 2060 additions and 10 deletions
+22 -1
View File
@@ -14,6 +14,7 @@ CLAIM_STATUS_LABELS = {
"paid": "BEZAHLT",
"overpaid": "ÜBERZAHLT",
"overdue": "ÜBERFÄLLIG",
"credit": "GUTSCHRIFT",
"cancelled": "STORNIERT",
}
@@ -57,10 +58,17 @@ def claim_total(claim: dict[str, Any]) -> Decimal:
return sum((decimal_value(item.get("amount", "0")) for item in claim_items(claim)), Decimal("0"))
def allocation_effect(data: ContributionData, allocation: dict[str, Any]) -> Decimal:
amount = decimal_value(allocation.get("amount", "0"))
if str(allocation.get("credit_id", "")):
return -amount
return amount
def allocated_total(data: ContributionData, claim_id: str) -> Decimal:
return sum(
(
decimal_value(allocation.get("amount", "0"))
allocation_effect(data, allocation)
for allocation in data.allocations
if str(allocation.get("claim_id", "")) == claim_id
),
@@ -79,6 +87,17 @@ def payment_allocated_total(data: ContributionData, payment_id: str) -> Decimal:
)
def credit_allocated_total(data: ContributionData, credit_id: str) -> Decimal:
return sum(
(
decimal_value(allocation.get("amount", "0"))
for allocation in data.allocations
if str(allocation.get("credit_id", "")) == credit_id
),
Decimal("0"),
)
def claim_balance(data: ContributionData, claim: dict[str, Any]) -> Decimal:
return (claim_total(claim) - allocated_total(data, str(claim.get("claim_id", "")))).quantize(CENT)
@@ -89,6 +108,8 @@ def claim_status(data: ContributionData, claim: dict[str, Any], *, today: date |
total = claim_total(claim)
paid = allocated_total(data, str(claim.get("claim_id", "")))
balance = total - paid
if total < 0:
return "credit"
if balance < 0:
return "overpaid"
if balance == 0:
+59
View File
@@ -20,6 +20,13 @@ MEMBERSHIP_STATUS_LABELS = {
"ended": "BEENDET",
}
ASSET_STATUS_LABELS = {
"available": "VERFUEGBAR",
"issued": "AUSGEGEBEN",
"lost": "VERLOREN",
"retired": "AUSGEMUSTERT",
}
HOUSEKEEPER_MEMBER_FIELD_LABELS = {
"nickname": "Nickname",
"email": "E-Mail-Adresse",
@@ -167,6 +174,55 @@ class Member:
)
@dataclass(slots=True)
class Asset:
asset_id: str
label: str
category: str = ""
inventory_number: str = ""
serial_number: str = ""
status: str = "available"
current_holder_member_id: str = ""
deposit_amount_default: str = "0.00"
notes: str = ""
created_at: str = field(default_factory=_iso_now)
updated_at: str = field(default_factory=_iso_now)
schema_version: int = 1
def to_dict(self) -> dict[str, Any]:
return {
"schema_version": self.schema_version,
"asset_id": self.asset_id,
"label": self.label,
"category": self.category,
"inventory_number": self.inventory_number,
"serial_number": self.serial_number,
"status": self.status,
"current_holder_member_id": self.current_holder_member_id,
"deposit_amount_default": self.deposit_amount_default,
"notes": self.notes,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@classmethod
def from_dict(cls, data: dict[str, Any]) -> Asset:
return cls(
schema_version=int(data.get("schema_version", 1)),
asset_id=str(data["asset_id"]),
label=str(data.get("label", "")),
category=str(data.get("category", "")),
inventory_number=str(data.get("inventory_number", "")),
serial_number=str(data.get("serial_number", "")),
status=str(data.get("status", "available")),
current_holder_member_id=str(data.get("current_holder_member_id", "")),
deposit_amount_default=str(data.get("deposit_amount_default", "0.00")),
notes=str(data.get("notes", "")),
created_at=str(data.get("created_at", _iso_now())),
updated_at=str(data.get("updated_at", _iso_now())),
)
@dataclass(slots=True)
class Event:
event_id: str
@@ -209,6 +265,7 @@ class Event:
class ContributionData:
claims: list[dict[str, Any]] = field(default_factory=list)
payments: list[dict[str, Any]] = field(default_factory=list)
credits: list[dict[str, Any]] = field(default_factory=list)
allocations: list[dict[str, Any]] = field(default_factory=list)
reminders: list[dict[str, Any]] = field(default_factory=list)
schema_version: int = 1
@@ -218,6 +275,7 @@ class ContributionData:
"schema_version": self.schema_version,
"claims": self.claims,
"payments": self.payments,
"credits": self.credits,
"allocations": self.allocations,
"reminders": self.reminders,
}
@@ -228,6 +286,7 @@ class ContributionData:
schema_version=int(data.get("schema_version", 1)),
claims=list(data.get("claims") or []),
payments=list(data.get("payments") or []),
credits=list(data.get("credits") or []),
allocations=list(data.get("allocations") or []),
reminders=list(data.get("reminders") or []),
)