Api reference
components.income.public.actions ¶
parse_and_create_income_declaration ¶
parse_and_create_income_declaration(
user_id,
effective_start_date,
selected_bracket_data,
income_brackets_data,
declaration_type,
subscription_id=None,
commit=False,
)
Create income declaration from raw dictionary data with Pydantic validation. Args: user_id: User identifier effective_start_date: When the income declaration becomes effective selected_bracket_data: User's selected income bracket (dict with min/max keys) income_brackets_data: Available income bracket options (list of dicts) declaration_type: Type of declaration to create subscription_id: Subscription identifier commit: Whether to commit the database transaction
Source code in components/income/internal/actions/create_income_declaration.py
send_unpaid_leave_start_email ¶
Source code in components/income/internal/actions/income_unpaid_leave_start_mailer.py
components.income.public.dependencies ¶
IncomeDependency ¶
IncomeDependency defines the interface that apps using the income component need to implement
get_async_mailer ¶
get_async_mailer(
category,
priority,
email_queue_name,
delivery=DEFAULT_DELIVERY,
job_timeout=None,
enqueue=True,
redacted_args=None,
)
Get the local async_mailer
Source code in components/income/internal/dependencies/income.py
get_eligibility_requests_for_user ¶
Returns income eligibility requests for a user.
get_income_brackets_for_subscription_on ¶
Returns income brackets for a given subscription on a specific date.
Source code in components/income/internal/dependencies/income.py
get_income_brackets_for_subscriptions_on ¶
Returns income brackets for multiple subscriptions on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscription_ids
|
list[str]
|
List of subscription IDs to get income brackets for |
required |
on_date
|
date
|
The date to check the income brackets against |
required |
for_target
|
Optional[IncomeBracketTarget]
|
Optional target for which the income brackets are requested |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[IncomeBracketEntity]]
|
dict[str, list[IncomeBracketEntity]]: Mapping of subscription_id to income brackets |
dict[str, list[IncomeBracketEntity]]
|
Only includes subscriptions that have income brackets |
Source code in components/income/internal/dependencies/income.py
get_member_type_for_user_on ¶
get_subscription_id_for_user_on ¶
Returns user subscription id linked to the user on a given on_date
get_subscription_ids_for_users_on ¶
Get user subscription IDs active at a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_ids
|
list[str]
|
List of user IDs to get subscription IDs for |
required |
on_date
|
date
|
The date to check for active subscriptions |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: Mapping of user_id to their subscription_id. Only includes users with active subscriptions. |
Source code in components/income/internal/dependencies/income.py
get_subscription_info_for_subscriptions_on ¶
Returns subscription info for a list of subscription IDs at a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscription_ids
|
list[str]
|
List of subscription IDs to get info for |
required |
on_date
|
date
|
The date to get subscription info at |
required |
Returns:
| Type | Description |
|---|---|
list[SubscriptionInfoEntity]
|
list[SubscriptionInfoEntity]: List of subscription info entities |
Source code in components/income/internal/dependencies/income.py
get_user_income_sources_from_dsn ¶
Fetches the salary for a user from the DSN for given months.
has_enrollment_depending_on_income_brackets_on ¶
Checks if the user has an enrollment depending on income brackets on a given date.
Source code in components/income/internal/dependencies/income.py
is_subscription_linked_to_income_brackets ¶
Checks if the subscription is linked to income brackets.
set_app_dependency ¶
Sets the income dependency to the app so it can be accessed within this component at runtime
Source code in components/income/internal/dependencies/income.py
components.income.public.entities ¶
IncomeBracketEntity
dataclass
¶
Bases: DataClassJsonMixin
__eq__ ¶
__post_init__ ¶
Source code in components/income/internal/entities/income_bracket.py
build_list_from_mins
classmethod
¶
Source code in components/income/internal/entities/income_bracket.py
is_upper_bracket_of ¶
Source code in components/income/internal/entities/income_bracket.py
IncomeBracketTarget ¶
Bases: AlanBaseEnum
Status of an income declaration.
The target can be for a specific context such as 'option' or 'dependent'. This enum is used to determine the context for which income brackets are requested. Possible values include 'option' or 'dependent'.
IncomeDeclarationEntity
dataclass
¶
IncomeDeclarationEntity(
id,
min_declared_monthly_income,
max_declared_monthly_income,
min_effective_monthly_income,
max_effective_monthly_income,
user_ref,
submission_date,
affiliation_start_date,
status,
member_type,
declaration_type,
sources,
income_brackets,
subscription_id,
proof_requested_on_date=None,
invalidation_reason=None,
validated_on_date=None,
)
Entity representing an income declaration model.
dsn_validating_months
property
¶
Get the months for which DSN validation is applicable. This includes the first full month after affiliation start date and all subsequent months until the end of the year.
Returns:
| Type | Description |
|---|---|
list[Month]
|
list[Month]: List of months for DSN validation |
find_highest_bracket ¶
Find the highest income bracket available.
Returns:
| Name | Type | Description |
|---|---|---|
IncomeBracketEntity |
IncomeBracketEntity
|
The highest income bracket (with the highest minimum threshold) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no brackets are available |
Source code in components/income/internal/entities/income_declaration.py
find_matching_bracket_for_income ¶
Find the appropriate income bracket for a given income amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
income_in_cents
|
int
|
The income amount in cents |
required |
Returns:
| Name | Type | Description |
|---|---|---|
IncomeBracketEntity |
IncomeBracketEntity
|
The appropriate income bracket |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no appropriate bracket is found |
Source code in components/income/internal/entities/income_declaration.py
first_full_month
property
¶
Get the first full month after affiliation start date. If the affiliation start date the first day of a month, we take that month, otherwise we take the next month.
Returns:
| Name | Type | Description |
|---|---|---|
Month |
Month
|
first full month after affiliation start date |
get_admin_override_sources ¶
Get all admin override sources from this declaration.
Returns:
| Type | Description |
|---|---|
list[IncomeSourceEntity]
|
list[IncomeSourceEntity]: List of admin override sources |
Source code in components/income/internal/entities/income_declaration.py
get_invalidating_dsn_sources ¶
Get all DSN sources that invalidate the declared income (monthly_income > max_declared_monthly_income).
Returns:
| Type | Description |
|---|---|
list[IncomeSourceEntity]
|
list[IncomeSourceEntity]: List of invalidating DSN sources |
Source code in components/income/internal/entities/income_declaration.py
get_proof_document_sources ¶
Get all proof document sources from this declaration.
Returns:
| Type | Description |
|---|---|
list[IncomeSourceEntity]
|
list[IncomeSourceEntity]: List of proof document sources |
Source code in components/income/internal/entities/income_declaration.py
get_validating_dsn_sources ¶
Get all DSN sources that validate the declared income (monthly_income <= max_declared_monthly_income).
Returns:
| Type | Description |
|---|---|
list[IncomeSourceEntity]
|
list[IncomeSourceEntity]: List of validating DSN sources |
Source code in components/income/internal/entities/income_declaration.py
IncomeDeclarationStatus ¶
Bases: AlanBaseEnum
Status of an income declaration.
The declaration can be pending (waiting for validation), validated (approved), invalidated (rejected), or cancelled.
IncomeDeclarationType ¶
Bases: AlanBaseEnum
Type of an income declaration.
The declaration can be: - declaration: Initial declaration made by the user - renewal: Renewal of an existing declaration - amendment: Amendment to an existing declaration
IncomeEligibilityRequest
dataclass
¶
IncomeEligibilityRequestStatus ¶
Bases: AlanBaseEnum
Enum representing the status of an income eligibility request.
Attributes:
| Name | Type | Description |
|---|---|---|
uploaded |
The request has been uploaded. |
|
parsing |
The request is currently being parsed. |
|
parsed |
The request has been parsed. |
|
to_manual_review |
The request is waiting for manual review. |
|
rejected |
The request has been rejected. |
|
validated |
The request has been validated. |
|
not_eligible |
The request is not eligible. |
IncomeSourceEntity
dataclass
¶
IncomeSourceEntity(
id,
monthly_income,
user_ref,
start_month,
end_month,
submission_date,
source_type,
source_ref=None,
income_declaration_id=None,
)
Entity representing an income source model.
MemberType ¶
components.income.public.fixtures ¶
create_income_declaration ¶
create_income_declaration(
user_id,
min_income_in_cents,
max_income_in_cents,
effective_start_date,
income_brackets_mins,
submission_date=None,
)
Source code in components/income/internal/fixtures/create_income_declaration.py
expire_income_declaration ¶
Update the income declaration if it is in those 3 cases: - has not received any DSN source after the first full month after their affiliation start date: their status should be updated to proof requested and an email should be sent to the user. - pending after 3 full months after their affiliation start date: they should be validated/invalidated based on the DSN sources we already have, even if less than 3. - declarations that are pending and with the status proof requested for over a month: they should be invalidated and an email should be sent to the user
Source code in components/income/internal/actions/expire_income_declaration.py
components.income.public.message_types ¶
components.income.public.queries ¶
ProofUploadDeadline
dataclass
¶
get_proof_upload_deadline ¶
Returns the deadline date and member type for uploading proof for a user's income declaration.
This function checks if: 1. A proof was requested for any income declaration 2. For each proof request date, it checks if there are any non-rejected eligibility requests for income type that were created after that date 3. Returns the deadline date (proof_request_date + time_frame) and member type as soon as we find a proof request date that has no valid eligibility requests after it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_ref
|
str
|
The user ref to check |
required |
Returns:
| Type | Description |
|---|---|
ProofUploadDeadline | None
|
The ProofUploadDeadline containing deadline date and member type, or None if no proof was requested or all proofs have been provided. |
Source code in components/income/internal/queries/needs_proof_for_income.py
get_user_income_on ¶
Returns the IncomeEntity for a user on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The user ID to get income brackets for |
required |
on_date
|
date
|
The date to check the income against |
required |
Returns:
| Type | Description |
|---|---|
IncomeEntity | None
|
IncomeEntity or None if there is no income for the user on the given date. |
Source code in components/income/internal/queries/get_user_income.py
get_user_income_timeline ¶
Returns a timeline of IncomePeriod for a user. The timeline is sorted but not necessarily continuous. IncomePeriods can't overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
The user ID to get income brackets for |
required |
Returns:
| Type | Description |
|---|---|
Timeline[IncomePeriod]
|
A timeline of IncomePeriod for the user. |
Source code in components/income/internal/queries/get_user_income.py
has_subscription_price_depending_on_income_brackets ¶
Source code in components/income/internal/queries/has_price_depending_on_income_brackets.py
is_subscription_price_linked_to_income_brackets ¶
Source code in components/income/internal/queries/has_price_depending_on_income_brackets.py
preload_user_income_timelines ¶
This function precomputes calls to get_user_income_timelines, caches
them and returns a new function get_cached_user_income_timeline that can be
used instead of the original implementation.