"""Common fixtures for tests.""" import base64 from datetime import datetime import pytest from abacus_common_logic.connectors.database import db from abacus_common_logic.constants.constants import SYSTEM_TIMEZONE from abacus_common_logic.db.adapters import get_adapter from freezegun import freeze_time from abacus_contract.tests.utils.factories import ( AccountContractFactory, ContractFactory, ReferenceSapProfitCenterFactory, ReferenceSigningEntityFactory, ) from royalties.constants.constants import ( EARNINGS_TRANSFER_INPUT, EARNINGS_TRANSFER_RATE_TYPES, EARNINGS_TRANSFER_TYPES, EXCHANGE_RATE_BULK_FIELD, ) from royalties.tests.utils.factories import ( EarningsTransferFactory, RunControllerFactory, StatementPeriodAdjustmentFileFactory, StatementPeriodFactory, ) # --- DB --- @pytest.fixture def fresh_db(): """Refresh the test database.""" top_level_tables = ( 'account', 'abacus_state_history', 'abacus_state', 'earnings_transfer', 'signing_entity_sap_profit_center', 'reference_signing_entity', 'reference_sap_profit_center', 'accounting_period_report', 'accounting_period', 'exchange_rate', 'accounting_run', 'sales_file', 'run_controller_contract', 'run_controller', 'account_contract', 'account_payment_term', 'contract', 'contract_lifecycle', 'account', 'file_upload', 'file_upload_config', 'reference_payment_entity', 'statement_period', 'statement_period_adjustment_batch_criteria', 'statement_period_adjustment_file', 'statement_period_payment_entity', 'worksheet_adjustment', ) with db.engine.connect() as conn: get_adapter(conn).truncate_tables(conn, top_level_tables) @pytest.fixture def remove_fks(): """Delete foreign keys.""" drop_fk_run_controller_contract_contract_sql = """ ALTER TABLE `run_controller_contract` DROP FOREIGN KEY `fk_run_controller_contract_contract` """ adapter = get_adapter(db.engine) with db.engine.connect() as conn: adapter.set_fk(conn, False) try: conn.exec_driver_sql(drop_fk_run_controller_contract_contract_sql) except Exception: pass finally: adapter.set_fk(conn, True) # --- Mocks --- @pytest.fixture def account_contract_fixtures(reference_payment_entity_fixtures): """Create account, contract, and account_contract records.""" account_insert = """ INSERT INTO account( account_id, account_name, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'Test Account', 'dana', CURRENT_TIMESTAMP, 'dana', CURRENT_TIMESTAMP), (2, 'Test Account 2', 'Test User', CURRENT_TIMESTAMP, 'Test User', CURRENT_TIMESTAMP); """ db.engine.execute(account_insert) account_payment_term_insert = """ INSERT INTO account_payment_term( account_id, currency_code, payment_minimum, payment_entity_id, agreement_type_id, payment_schedule, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'USD', '12.90', 1, NULL, '30_days_after_month_end', 'Test User' , CURRENT_TIMESTAMP, 'Test User' , CURRENT_TIMESTAMP), (2, 'USD', '1.22', 2, NULL, '60_days_after_month_end', 'Test User' , CURRENT_TIMESTAMP, 'Test User' , CURRENT_TIMESTAMP); """ db.engine.execute(account_payment_term_insert) reference_sap_profit_center = ReferenceSapProfitCenterFactory.create( reference_sap_profit_center_id=1, profit_center='UK4914', company_code='4914' ) reference_signing_entity = ReferenceSigningEntityFactory.create( reference_sap_profit_center=reference_sap_profit_center ) contract_1 = ContractFactory.create( reference_signing_entity=reference_signing_entity, contract_name='Test Contract 1', contract_type='distribution', term_start='2020-01-01', ) contract_2 = ContractFactory.create( reference_signing_entity=reference_signing_entity, contract_name='Test Contract 2', contract_type='distribution', term_start='2020-02-02', ) contract_3 = ContractFactory.create( reference_signing_entity=reference_signing_entity, contract_name='Test Contract 3', contract_type='distribution', term_start='2020-03-03', ) AccountContractFactory.create(account_id=1, contract=contract_1) AccountContractFactory.create(account_id=1, contract=contract_2) AccountContractFactory.create(account_id=1, contract=contract_3) @pytest.fixture def reference_payment_entity_fixtures(): """Create reference_payment_entity records for testing.""" reference_payment_entity_insert = """ INSERT INTO reference_payment_entity( reference_payment_entity_id, payment_entity_name, country_of_tax_reporting, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'AWAL-UK', 'GBR', 'test_user', CURRENT_TIMESTAMP, 'test_user', CURRENT_TIMESTAMP), (2, 'AWAL-US', 'USA', 'test_user', CURRENT_TIMESTAMP, 'test_user', CURRENT_TIMESTAMP), (3, 'KNR-UK', 'NLD', 'test_user', CURRENT_TIMESTAMP, 'test_user', CURRENT_TIMESTAMP), (4, 'KNR-NL', 'GBR', 'test_user', CURRENT_TIMESTAMP, 'test_user', CURRENT_TIMESTAMP); """ db.engine.execute(reference_payment_entity_insert) @pytest.fixture def run_controller_fixtures(): """Run controller fixture.""" return [ RunControllerFactory.create(run_controller_name=name) for name in ('High Priority 2', 'Medium Priority', 'High Priority 1') ] @pytest.fixture def b64encoded_exchange_rates(): """Return csv data encoded into string.""" return ( 'YWNjb3VudGluZ19wZXJpb2RfaWQJZnJvbV9jdXJyZW5jeV9jb2RlCXRv' 'X2N1cnJlbmN5X2NvZGUJcmF0ZQoxMDI2CVVTRAlFVVIJMS4zNgoxMDI2CVVTRA' 'lVQUgJMC4wMzkKMTAyNglVU0QJUlVCCTAuMDEyMwoxMDI2CVVTRAlHQlAJMS4x' 'MgoxMDI2CVVTRAlQTE4JMC4xMgo=' ) @pytest.fixture def standard_fx_data_with_semicolons(): """Return request data in standard format.""" data = {} data['statement_period_id'] = 123 exchange_rates = '\n'.join( [ 'period_id;from;AUD;USD', '268;AED;0,3514;0,2722', '268;AOA;0,0019;0,0015', '268;ARS;0,0138;0,01072', ] ) data[EXCHANGE_RATE_BULK_FIELD] = base64.b64encode(exchange_rates.encode()).decode() return data @pytest.fixture def standard_fx_data_with_tabs(): """Return request data in standard format.""" data = {} data['statement_period_id'] = 123 exchange_rates = '\n'.join( [ '\t'.join(['period_id', 'from', 'AUD', 'USD']), '\t'.join(['268', 'AED', '0,3514', '0,2722']), '\t'.join(['268', 'AOA', '0,0019', '0,0015']), '\t'.join(['268', 'ARS', '0,0138', '0,01072']), ] ) data[EXCHANGE_RATE_BULK_FIELD] = base64.b64encode(exchange_rates.encode()).decode() return data @pytest.fixture def statement_period_fixtures(): """Create statement periods' test data in the database.""" for ind in range(10): StatementPeriodFactory.create( statement_period_name=f'Month {ind}', statement_period_status='closed', statement_month=ind, statement_year=2020, closed_date='2021-01-01', closed_by='admin', ) StatementPeriodFactory.create( statement_period_name='Month 10', statement_period_status='current', statement_month=10, statement_year=2024, closed_date=None, closed_by=None, ) for ind in range(11, 40): StatementPeriodFactory.create( statement_period_name=f'Month {ind}', statement_month=ind, statement_year=2024, statement_period_status='open', closed_date=None, closed_by=None, ) @pytest.fixture def mock_statement_period_adjustment_files(account_contract_fixtures): """Mock statement_period_adjustment_file records with abacus states.""" statement_period_1 = StatementPeriodFactory.create( statement_period_id=999, statement_period_name='statement period 999' ) statement_period_2 = StatementPeriodFactory.create( statement_period_id=998, statement_period_name='statement period 998', statement_period_status='current', ) adjustment_file_1 = StatementPeriodAdjustmentFileFactory.create( statement_period_adjustment_file_id=90, statement_period=statement_period_2, created_at='2023-10-21 15:01:07', created_by='d5ca8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_2 = StatementPeriodAdjustmentFileFactory.create( statement_period_adjustment_file_id=91, statement_period=statement_period_2, created_at='2023-10-21 15:01:07', created_by='e5ca8bc3-7e52-4793-8775-50d11282504c', ) adjustment_file_3 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-1-2024.xlsx', statement_period_adjustment_file_id=92, statement_period=statement_period_1, total_rounded_amount_multicurrency=15, created_at='2023-10-21 15:01:07', created_by='e5ca8bc3-7e52-4793-8775-50d11282504c', ) adjustment_file_4 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-2-2024.xlsx', statement_period_adjustment_file_id=93, statement_period=statement_period_1, total_rounded_amount_multicurrency=20.50, created_at='2023-10-21 15:01:07', created_by='d5ca8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_5 = StatementPeriodAdjustmentFileFactory.create( statement_period_adjustment_file_id=94, created_at='2024-02-01 19:01:07', statement_period=statement_period_2, deleted_by='test user', deleted_at='2024-02-02 01:02:01', created_by='d5ca8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_6 = StatementPeriodAdjustmentFileFactory.create( statement_period_adjustment_file_id=96, statement_period=statement_period_2, created_at='2024-02-01 19:01:07', deleted_by='test user', deleted_at='2024-02-02 01:02:01', created_by='effff8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_7 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-1001-2026.xlsx', statement_period_adjustment_file_id=1001, statement_period=statement_period_2, batch_type='auto', created_at='2024-02-01 19:01:07', created_by='effff8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_8 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-1002-2026.xlsx', statement_period_adjustment_file_id=1002, statement_period=statement_period_2, batch_type='auto', created_at='2024-02-01 19:01:07', created_by='effff8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_9 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-1003-2026.xlsx', statement_period_adjustment_file_id=1003, statement_period=statement_period_2, batch_type='auto', created_at='2024-02-01 19:01:07', created_by='effff8ac3-7e51-4793-8775-50d11282504c', last_modified='2024-02-01 19:01:07', last_modified_by='effff8ac3-7e51-4793-8775-50d11282504c', ) adjustment_file_10 = StatementPeriodAdjustmentFileFactory.create( file_name='adjustment-file-1004-2026.xlsx', statement_period_adjustment_file_id=1004, statement_period=statement_period_2, batch_type='auto', created_at='2024-02-01 19:01:07', created_by='effff8ac3-7e51-4793-8775-50d11282504c', ) query = """ INSERT INTO abacus_state ( parent_table_id, parent_table_name, action_name, action_status, message, created_by, created_at, last_modified_by, last_modified ) VALUES ( {}, 'statement_period_adjustment_file', 'upload_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-11-18 15:01:07' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', CURRENT_TIMESTAMP ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', CURRENT_TIMESTAMP ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-11-18 15:01:07' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-11-19 10:02:07' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2023-11-21 07:11:17' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-11-19 01:00:00' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-11-19 02:00:07' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', CURRENT_TIMESTAMP ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-12-13 18:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2023-12-14 05:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'complete', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2023-12-15 11:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'complete', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2024-02-01 07:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2024-02-01 07:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'validate_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'import_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2024-02-01 07:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'error', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'validate_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'import_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2024-02-01 07:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 04:18:01', 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 05:00:01' ), ( {}, 'statement_period_adjustment_file', 'validate_file', 'running', NULL, 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 04:18:01', 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 05:14:01' ), ( {}, 'statement_period_adjustment_file', 'import_file', 'init', NULL, 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 04:18:01', 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 04:18:01', 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 04:18:01', 'effff8ac3-7e51-4793-8775-50d11282504c', '2024-02-01 07:02:07' ), ( {}, 'statement_period_adjustment_file', 'upload_file', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'validate_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'import_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 05:18:01' ), ( {}, 'statement_period_adjustment_file', 'approve_file', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', '2024-02-01 06:10:03' ), ( {}, 'statement_period_adjustment_file', 'apply_file', 'init', NULL, 'Test Apply User', CURRENT_TIMESTAMP, 'Test Apply User', '2024-02-01 07:02:07' ); """ db.engine.execute( query.format( adjustment_file_1.statement_period_adjustment_file_id, adjustment_file_1.statement_period_adjustment_file_id, adjustment_file_1.statement_period_adjustment_file_id, adjustment_file_2.statement_period_adjustment_file_id, adjustment_file_2.statement_period_adjustment_file_id, adjustment_file_2.statement_period_adjustment_file_id, adjustment_file_3.statement_period_adjustment_file_id, adjustment_file_3.statement_period_adjustment_file_id, adjustment_file_3.statement_period_adjustment_file_id, adjustment_file_4.statement_period_adjustment_file_id, adjustment_file_4.statement_period_adjustment_file_id, adjustment_file_4.statement_period_adjustment_file_id, adjustment_file_5.statement_period_adjustment_file_id, adjustment_file_5.statement_period_adjustment_file_id, adjustment_file_5.statement_period_adjustment_file_id, adjustment_file_6.statement_period_adjustment_file_id, adjustment_file_6.statement_period_adjustment_file_id, adjustment_file_6.statement_period_adjustment_file_id, adjustment_file_7.statement_period_adjustment_file_id, adjustment_file_7.statement_period_adjustment_file_id, adjustment_file_7.statement_period_adjustment_file_id, adjustment_file_7.statement_period_adjustment_file_id, adjustment_file_7.statement_period_adjustment_file_id, adjustment_file_8.statement_period_adjustment_file_id, adjustment_file_8.statement_period_adjustment_file_id, adjustment_file_8.statement_period_adjustment_file_id, adjustment_file_8.statement_period_adjustment_file_id, adjustment_file_8.statement_period_adjustment_file_id, adjustment_file_9.statement_period_adjustment_file_id, adjustment_file_9.statement_period_adjustment_file_id, adjustment_file_9.statement_period_adjustment_file_id, adjustment_file_9.statement_period_adjustment_file_id, adjustment_file_9.statement_period_adjustment_file_id, adjustment_file_10.statement_period_adjustment_file_id, adjustment_file_10.statement_period_adjustment_file_id, adjustment_file_10.statement_period_adjustment_file_id, adjustment_file_10.statement_period_adjustment_file_id, adjustment_file_10.statement_period_adjustment_file_id, ) ) event_query = """ INSERT INTO abacus_event ( statement_period_id, event_name, target_type, target_id, event_date, created_by ) VALUES ( {}, 'apply_pending_adjustments', 'statement_period_adjustment_file', {}, '2023-12-15 11:02:07', 'Test Apply User' ), ( {}, 'apply_pending_adjustments', 'statement_period_adjustment_file', {}, '2024-02-01 07:02:07', 'Test Apply User' ); """ db.engine.execute( event_query.format( adjustment_file_4.statement_period_id, adjustment_file_4.statement_period_adjustment_file_id, adjustment_file_5.statement_period_id, adjustment_file_5.statement_period_adjustment_file_id, ) ) worksheet_adjustment_query = """ INSERT INTO worksheet_adjustment( worksheet_adjustment_id, statement_period_adjustment_file_id, abacus_event_id, account_id, contract_id, activity_statement_period_id, apply_to_statement_period_id, reference_adjustment_type_id, adjustment_amount, adjustment_currency_code, note, internal_note, created_by, created_at, last_modified_by, last_modified, deleted_by, deleted_at ) VALUES ( 1, {}, 1, 1, 1, {}, {}, 1, 4.00, 'USD', null, null, 'Test', '2023-10-09 13:49:00', 'Test', '2023-10-09 13:49:01', null, null ), ( 2, {}, 1, 1, 1, {}, {}, 1, 4.00, 'USD', null, null, 'Test', '2023-10-09 13:49:00', 'Test', '2023-10-09 13:49:01', null, null ),( 3, {}, 1, 1, 1, {}, {}, 1, 4.00, 'USD', null, null, 'Test', '2023-10-09 13:49:00', 'Test', '2023-10-09 13:49:01', null, null ) """ db.engine.execute( worksheet_adjustment_query.format( adjustment_file_2.statement_period_adjustment_file_id, adjustment_file_2.statement_period_id, adjustment_file_2.statement_period_id, adjustment_file_3.statement_period_adjustment_file_id, adjustment_file_3.statement_period_id, adjustment_file_3.statement_period_id, adjustment_file_4.statement_period_adjustment_file_id, adjustment_file_4.statement_period_id, adjustment_file_4.statement_period_id, ) ) return [ adjustment_file_1, adjustment_file_2, adjustment_file_3, adjustment_file_4, adjustment_file_5, ] @pytest.fixture def payment_entities_actions_fixtures(): """Mock states for statement_period_payment_entity.""" states_query = """ INSERT INTO abacus_state ( parent_table_id, parent_table_name, action_name, action_status, message, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 'statement_period_payment_entity', 'close_balance', 'complete', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', CURRENT_TIMESTAMP ), ( 2, 'statement_period_payment_entity', 'close_balance', 'init', NULL, 'Test User', CURRENT_TIMESTAMP, 'Test User', CURRENT_TIMESTAMP ) """ db.engine.execute(states_query) @pytest.fixture def adjustments_fixture(): """Fixture for a list of adjustments to validate.""" return [ { 'account_id': '1', 'contract_id': '1', 'upc': '111111111111', 'amount': 1.23, 'currency': 'USD', 'activity_month': '1', 'activity_year': '2026', 'statement_month': '1', 'statement_year': '2026', 'adjustment_type': 'Label Earnings', 'client_facing_comments': 'Comments', 'distribution_type': 'Physical', } ] @pytest.fixture @freeze_time(datetime(2026, 5, 5, 0, 0, 0, tzinfo=SYSTEM_TIMEZONE)) def mock_earnings_transfer_fixture(account_contract_fixtures): """Mock earnings transfer.""" reference_sap_profit_center = ReferenceSapProfitCenterFactory.create( reference_sap_profit_center_id=2, profit_center='UK4915', company_code='4915' ) reference_signing_entity = ReferenceSigningEntityFactory.create( reference_sap_profit_center=reference_sap_profit_center ) mock_from_contract_1 = ContractFactory.create( contract_id=90001, reference_signing_entity=reference_signing_entity ) mock_from_contract_2 = ContractFactory.create( contract_id=90002, reference_signing_entity=reference_signing_entity ) mock_to_contract_1 = ContractFactory.create( contract_id=90003, reference_signing_entity=reference_signing_entity ) mock_to_contract_2 = ContractFactory.create( contract_id=90004, reference_signing_entity=reference_signing_entity ) AccountContractFactory.create(account_id=1, contract=mock_from_contract_1) AccountContractFactory.create(account_id=2, contract=mock_from_contract_2) AccountContractFactory.create(account_id=1, contract=mock_to_contract_1) AccountContractFactory.create(account_id=1, contract=mock_to_contract_2) EarningsTransferFactory.create( from_contract=mock_from_contract_1, to_contract=mock_to_contract_1, transfer_type=EARNINGS_TRANSFER_TYPES.TRANSFER, rate_type=EARNINGS_TRANSFER_RATE_TYPES.PERCENT, transfer_amount=128.911000000000, input=EARNINGS_TRANSFER_INPUT.NET_REVENUE, negative=0, comment='Test Earnings Transfer', ) EarningsTransferFactory.create( from_contract=mock_from_contract_2, to_contract=mock_to_contract_2, transfer_type=EARNINGS_TRANSFER_TYPES.OVERRIDE, rate_type=EARNINGS_TRANSFER_RATE_TYPES.FLAT_RATE, transfer_amount=99.911000000000, input=EARNINGS_TRANSFER_INPUT.GROSS_REVENUE, negative=0, comment='Test Earnings Transfer', )