"""
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 =================================================
# Backward-compatible alias
GatewayAccountObject = GatewayAccountParamInput
# Backward-compatible alias
PayableEntityObject = PayableEntityInput
# Backward-compatible alias
PayableChargeObject = EntityChargeInput
# Backward-compatible alias
PayableEntityRequestObject = PayableEntityRequestInput
[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
# Backward-compatible alias
CreateAccountObject = BillingAccountCreateParamsInput
# Backward-compatible alias
CreatePaymentRequestObject = PaymentRequestParamsInput