feat(contracts): hour-balance consumption, rate resolution, lifecycle (PMS-64) #75

Merged
vas2000-work merged 3 commits from feat/pms-64-contracts into main 2026-06-05 04:24:26 +02:00
Owner

Implements PMS-64 working components. consume_hours decrements current-period contract_hour_balances, computes overage at overage_rate, roll_to_next_period rolls unused hours capped at max_rollover_hours (periods derived from start_date + billing_cycle). resolve_rate returns emergency/after-hours/standard per work type. expire_due_contracts expires or auto-renews past-end contracts, driven hourly by a ContractLifecycleWorker (scheduler::Job). list_recurring_items feeds PMS-33. Migration 025 adds the balance unique constraint. tests/contracts.rs 6/6 green (within-allotment, overage, rollover-cap, renewal/expiry). rust_decimal throughout; clippy -D warnings clean. Contract audit hooks follow after PMS-117 merges.

Implements PMS-64 working components. consume_hours decrements current-period contract_hour_balances, computes overage at overage_rate, roll_to_next_period rolls unused hours capped at max_rollover_hours (periods derived from start_date + billing_cycle). resolve_rate returns emergency/after-hours/standard per work type. expire_due_contracts expires or auto-renews past-end contracts, driven hourly by a ContractLifecycleWorker (scheduler::Job). list_recurring_items feeds PMS-33. Migration 025 adds the balance unique constraint. tests/contracts.rs 6/6 green (within-allotment, overage, rollover-cap, renewal/expiry). rust_decimal throughout; clippy -D warnings clean. Contract audit hooks follow after PMS-117 merges.
feat(contracts): hour-balance consumption, rate resolution, lifecycle (PMS-64)
Some checks failed
Check / fmt + clippy + compile + tests (pull_request) Failing after 57s
Build OCI container / Build and push mokosh-api image (push) Successful in 3m11s
9c14ffa417
PMS-64: implement the contract working components on top of the existing CRUD.

consume_hours decrements the current-period contract_hour_balances row, computes overage at the block-hour item's overage_rate once included hours are exhausted, and roll_to_next_period folds unused hours into the next period capped at max_rollover_hours. Periods are derived contiguously from the contract start_date stepped by billing_cycle. resolve_rate returns the emergency / after-hours / standard rate per work type from rate_card_items. expire_due_contracts transitions contracts past end_date to expired, or renews (advancing dates per renewal_terms) when auto_renew; a ContractLifecycleWorker (scheduler::Job) runs it hourly. list_recurring_items exposes recurring items for billing (PMS-33).

Adds migration 025 (unique constraint on contract_hour_balances period) required by the balance upsert. Integration tests in tests/contracts.rs cover within-allotment consumption, overage, rollover-with-cap, and renewal/expiry. All money uses rust_decimal.

Audit-log hooks for contract mutations are intentionally NOT included here: the audit helper lands in PMS-117 (separate PR) and is not on this branch; they follow once that merges.

#PMS-64

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into feat/pms-64-contracts
All checks were successful
Check / fmt + clippy + compile + tests (pull_request) Successful in 1m18s
Build OCI container / Build and push mokosh-api image (push) Successful in 3m34s
ba69f112eb
Merge remote-tracking branch 'origin/main' into feat/pms-64-contracts
All checks were successful
Check / fmt + clippy + compile + tests (pull_request) Successful in 1m14s
Build OCI container / Build and push mokosh-api image (push) Successful in 3m17s
Create release / Create release from merged PR (pull_request) Has been skipped
39950bff90
# Conflicts:
#	tests/common/mod.rs
vas2000-work deleted branch feat/pms-64-contracts 2026-06-05 04:24:27 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!75
No description provided.