Skip to content

feat: add Charge schemas with category/party validation - #61

Merged
NouhJama merged 1 commit into
mainfrom
feature/charge-schemas
Aug 25, 2026
Merged

NouhJama merged 1 commit into
mainfrom
feature/charge-schemas

Conversation

@NouhJama

Copy link
Copy Markdown
Owner

ChargeBase carries validate_party_for_category (model_validator, mode=after), which is where the 'exactly one of owner_id/tenant_id' rule is genuinely enforced: service_charge requires an owner_id and a percentage and forbids a tenant_id; rent/water/move_out require a tenant_id and forbid both owner_id and percentage. The database deliberately allows both FK columns to be nullable, since a single column can't conditionally point at two tables with real referential integrity -- so the pairing rule lives at the schema layer, same approach as Unit's bedrooms/unit_type rule.

amount and percentage use Decimal, never float, matching the model's Numeric columns.

ChargeUpdate deliberately excludes category, unit_id, owner_id and tenant_id -- changing any of them would silently rewrite financial history rather than correct it; cancel the wrong charge and create a correct one instead. is_cancelled is excluded too, since cancelling has its own narrow admin-only schema (ChargeCancel).

Charge has no delete schema anywhere by design -- financial records are voided, never destroyed, so the audit trail always survives.

Verified: 10 schema checks pass (valid rent, valid service_charge, and 5 distinct rejection cases), all 51 existing tests still pass.

ChargeBase carries validate_party_for_category (model_validator,
mode=after), which is where the 'exactly one of owner_id/tenant_id'
rule is genuinely enforced: service_charge requires an owner_id
and a percentage and forbids a tenant_id; rent/water/move_out
require a tenant_id and forbid both owner_id and percentage. The
database deliberately allows both FK columns to be nullable, since
a single column can't conditionally point at two tables with real
referential integrity -- so the pairing rule lives at the schema
layer, same approach as Unit's bedrooms/unit_type rule.

amount and percentage use Decimal, never float, matching the
model's Numeric columns.

ChargeUpdate deliberately excludes category, unit_id, owner_id and
tenant_id -- changing any of them would silently rewrite financial
history rather than correct it; cancel the wrong charge and create
a correct one instead. is_cancelled is excluded too, since
cancelling has its own narrow admin-only schema (ChargeCancel).

Charge has no delete schema anywhere by design -- financial
records are voided, never destroyed, so the audit trail always
survives.

Verified: 10 schema checks pass (valid rent, valid service_charge,
and 5 distinct rejection cases), all 51 existing tests still pass.
@NouhJama
NouhJama merged commit 20a335e into main Aug 25, 2026
1 check passed
@NouhJama
NouhJama deleted the feature/charge-schemas branch August 25, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant