from decimal import Decimal from enum import IntEnum, StrEnum SUCCESS_MSG = 'Success: calculating payments finished' NO_PAYMENT_GROUP_PAYMENT_FOUND_ERR = 'No payment_group_payment found with id {}' NO_ELIGIBLE_ACCOUNTS_ERR = 'No accounts for payment_group_payment {}' NO_WORKSHEET_ENTRIES_REFRESH_ERR = ( 'No worksheet payable after tax entries to refresh for abacus_event {}' ) REFRESH_CLOSING_BALANCE_NOT_FOUND_ERR = 'Closing balance not found for contract_id={}' INVALID_REFERENCE_PAYMENT_TYPE_ID_ERR = 'reference_payment_type_id not supported: {}' NO_PAYMENT_ENTITY_TAX_POLICY_MAPPING_ERR = 'Payment entity to tax policy country mapping not available for payment_group_id: {}' NO_COUNTRY_OF_TAX_RESIDENCE_ERR = ( 'Account {} does not have country_of_tax_residence and will be skipped' ) NO_PAYMENT_ENTITY_ERR = 'Account {} does not have payment_entity_id and will be skipped' ACCOUNT_MSG = 'Getting eligible accounts for payment_group {}' PAYMENT_GROUP_MSG = 'Getting payment group payment by id {}' CLOSE_BALANCE_MSG = 'Getting contract close balance entries for {} accounts' POST_BALANCE_ENTRIES_AFTER_TAX = 'Sending {} contract balance entries after tax' POST_BALANCE_DETAILS_ENTRIES = 'Sending {} contract payable balance details entries' POST_CATCHUP_BALANCE_DETAILS_ENTRIES = ( 'Sending {} catchup contract payable balance details entries' ) POST_BALANCE_DETAILS_NO_ENTRIES = 'No payable balance details entries for the batch' REFRESH_BATCH_MSG = 'Refreshing batch of {} worksheet payable after tax entries' REFRESH_ENTRIES_MSG = 'Refreshing {} of {} worksheet payable after tax entries' NO_REFRESH_ENTRIES_MSG = ( 'No worksheet payable after tax entries need refresh in this batch' ) REFRESH_DRIFT_MSG = ( 'Refresh %s worksheet_after_tax_id=%s: current=%s details_sum=%s pending_sum=%s' ) REFRESH_DISABLED_ERR_MSG = 'Tax refresh is disabled' ROLLBACK_ENTRIES = 'Doing rollback for balance after tax and payable details entries' ERROR_MSG = 'Failed to calculate payments, exception details: {}' BATCH_SIZE = 100 BATCH_SIZE_REFRESH = 200 EXTENDED_TIMEOUT_SECONDS = 60 GENERATE_PAYMENTS_EVENT_NAME = 'payments_generate' GENERATE_PAYMENTS_EVENT_ERROR = ( 'Failed to send generate payments event, exception details: {}' ) AUTHENTICATION = { 'Orchard-Profile-Id': '461406', 'Orchard-Profile-UUID': '19ab6392-4662-4b1d-9923-0b06bc2c81f1', 'Orchard-Identity-Id': '5e598fbe-d403-493d-9772-833046be3fa2', 'Orchard-Roles': 'administrator', 'Orchard-Profile-Type': 'AbacusProfile', } UPDATE_STATE_MSG = 'Updating abacus states by id {}' ACTION_NAME = 'calculate_payments' PARENT_TABLE_NAME = 'payment_group_payment' # state definitions ACCOUNT_PAYEE_TABLE = 'account_payee' TAX_ELIGIBILITY_STATE = 'tax_eligibility' class PayableDetailTypes(IntEnum): """ Payable detail types. TODO: This Enum should be replaced with an API request in future. """ closing_balance = 1 withholding_tax = 2 vat = 3 withholding_tax_correction = 4 vat_correction = 5 flowthrough_allocation = 6 class TaxCorrectionTypes(StrEnum): """Tax correction types.""" wht = 'wht' vat = 'vat' class TaxCorrectionStatuses(StrEnum): """Tax correction statuses.""" active = 'active' pending = 'pending' class AbacusStateActionStatuses(StrEnum): """Tax correction statuses.""" complete = 'complete' class RevenueTransactionTypes(StrEnum): """Revenue transaction types.""" digital = 'digital' physical = 'physical' closing_balance = 'closing_balance' class ReferencePaymentTypes(IntEnum): """Reference payment types.""" check = 10 class TableNames(StrEnum): worksheet_tax_correction = 'worksheet_tax_correction' worksheet_tax_correction_vat = 'worksheet_tax_correction_vat' payment_allocation = 'payment_allocation' COUNTRY_USA = 'USA' PAYABLE_PAYMENT_ALLOCATION_FLOWTHROUGH_STATUSES = ['init', 'returned'] # reference_payable_detail_type.detail_group_name values used to fetch correction WHT_DETAIL_GROUP = 'tax_withholding' VAT_DETAIL_GROUP = 'vat_amount' CORRECTION_DETAIL_GROUPS = [WHT_DETAIL_GROUP, VAT_DETAIL_GROUP] DECIMAL_ZERO = Decimal('0') # feature flags TAP_DRAFT_PAYMENTS_FEATURE = 'abacus_tap_draft_payments'