mirror of
https://git.hiabuto.net/C3MA/CCMA.git
synced 2026-08-25 06:55:17 +02:00
Add asset records, claims, and credit workflows
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user