Source code for ace.centralize.models.finance

"""
    Finance models for Centralize

    Models for finance transactions, statements, payment accounts, and payment requests.

    Based on the Finance GraphQL schema (CreateTransactionInput, UpdateTransactionInput,
    CreateStatementInput, UpdateStatementInput, etc.)
"""
from datetime import date, datetime
from typing import List, Optional
from uuid import UUID

from ace.centralize.models.base import ModelBase


# ================================================== TRANSACTION =======================================================

[docs] class CreateFinanceTransactionObject(ModelBase): """Maps to CreateTransactionInput"""
[docs] def __init__( self, amount: float, amount_type_id: int, basis_amount: float, currency_id: int, rate: float, shared_percent: float, status_id: int, transaction_date: date, transaction_type_guid: UUID, description: Optional[str] = None, party_id: Optional[int] = None, reference_entity_id: Optional[int] = None, reference_entity_type_id: Optional[str] = None, statement_id: Optional[int] = None, ): self.amount = amount self.amountTypeId = amount_type_id self.basisAmount = basis_amount self.currencyId = currency_id self.rate = rate self.sharedPercent = shared_percent self.statusId = status_id self.transactionDate = transaction_date self.transactionTypeGuid = transaction_type_guid if description is not None: self.description = description if party_id is not None: self.partyId = party_id if reference_entity_id is not None: self.referenceEntityId = reference_entity_id if reference_entity_type_id is not None: self.referenceEntityTypeId = reference_entity_type_id if statement_id is not None: self.statementId = statement_id
[docs] class UpdateFinanceTransactionObject(ModelBase): """Maps to UpdateTransactionInput"""
[docs] def __init__( self, transaction_detail_id: int, amount: Optional[float] = None, amount_type_id: Optional[int] = None, basis_amount: Optional[float] = None, description: Optional[str] = None, party_id: Optional[int] = None, rate: Optional[float] = None, reference_entity_id: Optional[int] = None, reference_entity_type_id: Optional[str] = None, shared_percent: Optional[float] = None, statement_id: Optional[int] = None, status_id: Optional[int] = None, transaction_date: Optional[date] = None, ): self.transactionDetailId = transaction_detail_id if amount is not None: self.amount = amount if amount_type_id is not None: self.amountTypeId = amount_type_id if basis_amount is not None: self.basisAmount = basis_amount if description is not None: self.description = description if party_id is not None: self.partyId = party_id if rate is not None: self.rate = rate if reference_entity_id is not None: self.referenceEntityId = reference_entity_id if reference_entity_type_id is not None: self.referenceEntityTypeId = reference_entity_type_id if shared_percent is not None: self.sharedPercent = shared_percent if statement_id is not None: self.statementId = statement_id if status_id is not None: self.statusId = status_id if transaction_date is not None: self.transactionDate = transaction_date
# =================================================== STATEMENT =======================================================
[docs] class CreateFinanceStatementObject(ModelBase): """Maps to CreateStatementInput"""
[docs] def __init__( self, currency_id: int, issuer_party_id: int, period_end_date: date, period_start_date: date, recipient_party_id: int, statement_type_guid: str, status_id: int, total_amount: float, description: Optional[str] = None, reference_number: Optional[str] = None, transaction_ids: Optional[List[int]] = None, ): self.currencyId = currency_id self.issuerPartyId = issuer_party_id self.periodEndDate = period_end_date self.periodStartDate = period_start_date self.recipientPartyId = recipient_party_id self.statementTypeGuid = statement_type_guid self.statusId = status_id self.totalAmount = total_amount if description is not None: self.description = description if reference_number is not None: self.referenceNumber = reference_number if transaction_ids is not None: self.transactionIds = transaction_ids
[docs] class UpdateFinanceStatementObject(ModelBase): """Maps to UpdateStatementInput"""
[docs] def __init__( self, statement_id: int, description: Optional[str] = None, period_end_date: Optional[date] = None, period_start_date: Optional[date] = None, reference_number: Optional[str] = None, status_id: Optional[int] = None, total_amount: Optional[float] = None, ): self.statementId = statement_id if description is not None: self.description = description if period_end_date is not None: self.periodEndDate = period_end_date if period_start_date is not None: self.periodStartDate = period_start_date if reference_number is not None: self.referenceNumber = reference_number if status_id is not None: self.statusId = status_id if total_amount is not None: self.totalAmount = total_amount
# ================================================== BILLING / PAYMENT =================================================
[docs] class GatewayAccountParamInput(ModelBase): """Maps to GatewayAccountParamInput in GraphQL schema."""
[docs] def __init__(self, name: str, value: str): self.name = name self.value = value
# Backward-compatible alias GatewayAccountObject = GatewayAccountParamInput
[docs] class PayableEntityInput(ModelBase): """Maps to PayableEntityInput in GraphQL schema."""
[docs] def __init__(self, entity_id: int, entity_type_id: str): self.entityId = entity_id self.entityTypeId = entity_type_id
# Backward-compatible alias PayableEntityObject = PayableEntityInput
[docs] class EntityChargeInput(ModelBase): """Maps to EntityChargeInput in GraphQL schema."""
[docs] def __init__( self, amount: float, entity_id: int, entity_type_id: str, amount_type_guid: Optional[str] = None, amount_type_id: Optional[int] = None, description: Optional[str] = None, ): self.amount = amount self.entityId = entity_id self.entityTypeId = entity_type_id if amount_type_guid is not None: self.amountTypeGuid = amount_type_guid if amount_type_id is not None: self.amountTypeId = amount_type_id if description is not None: self.description = description
# Backward-compatible alias PayableChargeObject = EntityChargeInput
[docs] class PayableEntityRequestInput(ModelBase): """Maps to PayableEntityRequestInput in GraphQL schema."""
[docs] def __init__( self, entity_id: int, entity_type_id: str, charges: Optional[List[EntityChargeInput]] = None, description: Optional[str] = None, ): self.entityId = entity_id self.entityTypeId = entity_type_id if charges is not None: self.charges = charges if description is not None: self.description = description
# Backward-compatible alias PayableEntityRequestObject = PayableEntityRequestInput
[docs] class BillingAccountEntityCreateParamsInput(ModelBase): """Maps to BillingAccountEntityCreateParamsInput in GraphQL schema (nested in policy create/update)."""
[docs] def __init__( self, id: Optional[int] = None, default_currency_id: Optional[int] = None, gateway_account_params: Optional[List[GatewayAccountParamInput]] = None, party_id: Optional[int] = None, payment_gateway_id: Optional[int] = None, ): if id is not None: self.id = id if default_currency_id is not None: self.defaultCurrencyId = default_currency_id if gateway_account_params is not None: self.gatewayAccountParams = gateway_account_params if party_id is not None: self.partyId = party_id if payment_gateway_id is not None: self.paymentGatewayId = payment_gateway_id
[docs] class CreatePaymentAccountObject(ModelBase): """Convenience wrappers for creating Stripe payment accounts."""
[docs] class StripeCreditCard:
[docs] def __init__( self, account_id: Optional[int] = None, default_currency_id: Optional[int] = None, payment_gateway_id: Optional[int] = None, customer_id: str = None, payment_method_id: str = None ): from ace.centralize.codes import Billing gateway_account_params = [ GatewayAccountParamInput( name=Billing.Gateway.AccountParameters.CUSTOMER_ID.NAME, value=customer_id ), GatewayAccountParamInput( name=Billing.Gateway.AccountParameters.PAYMENT_METHOD_ID.NAME, value=payment_method_id ) ] if account_id: self.id = account_id else: if payment_gateway_id: self.paymentGatewayId = payment_gateway_id if default_currency_id: self.defaultCurrencyId = default_currency_id self.gatewayAccountParams = gateway_account_params
[docs] class StripeEFT:
[docs] def __init__( self, account_id: Optional[int] = None, default_currency_id: Optional[int] = None, payment_gateway_id: Optional[int] = None, customer_id: str = None, payment_method_id: str = None, mandate_id: str = None ): from ace.centralize.codes import Billing gateway_account_params = [ GatewayAccountParamInput( name=Billing.Gateway.AccountParameters.CUSTOMER_ID.NAME, value=customer_id ), GatewayAccountParamInput( name=Billing.Gateway.AccountParameters.PAYMENT_METHOD_ID.NAME, value=payment_method_id ), GatewayAccountParamInput( name=Billing.Gateway.AccountParameters.MANDATE_ID.NAME, value=mandate_id ) ] if account_id: self.id = account_id else: if payment_gateway_id: self.paymentGatewayId = payment_gateway_id if default_currency_id: self.defaultCurrencyId = default_currency_id self.gatewayAccountParams = gateway_account_params
[docs] class BillingAccountCreateParamsInput(ModelBase): """Maps to BillingAccountCreateParamsInput in GraphQL schema (standalone create)."""
[docs] def __init__( self, gateway_account_params: List[GatewayAccountParamInput], default_currency_id: Optional[int] = None, party_id: Optional[int] = None, payable_entities: Optional[List[PayableEntityInput]] = None, payment_gateway_id: Optional[int] = None, ): self.gatewayAccountParams = gateway_account_params if default_currency_id is not None: self.defaultCurrencyId = default_currency_id if party_id is not None: self.partyId = party_id if payable_entities is not None: self.payableEntities = payable_entities if payment_gateway_id is not None: self.paymentGatewayId = payment_gateway_id
# Backward-compatible alias CreateAccountObject = BillingAccountCreateParamsInput
[docs] class PaymentRequestParamsInput(ModelBase): """Maps to PaymentRequestParamsInput in GraphQL schema."""
[docs] def __init__( self, entities: List[PayableEntityRequestInput], request_id: str, account_id: Optional[int] = None, currency_id: Optional[int] = None, description: Optional[str] = None, payment_request_datetime_utc: Optional[datetime] = None, ): self.entities = entities self.requestId = request_id if account_id is not None: self.accountId = account_id if currency_id is not None: self.currencyId = currency_id if description is not None: self.description = description if payment_request_datetime_utc is not None: self.paymentRequestDateTimeUTC = payment_request_datetime_utc
# Backward-compatible alias CreatePaymentRequestObject = PaymentRequestParamsInput