"""WorksheetAccountContractClosingBalance model tests.""" from datetime import datetime from decimal import Decimal import json from moneyhub.models import WorksheetAccountContractClosingBalance from tests.unit.conftest import insert_mock_data def test_get_payment_details(): """Test getting payment details for a given account and statement period.""" account_id = 1 statement_period_ids = [11, 12] contract = '{"contract_id": 521149,"currency_code": "GBP", "current_balance": "763.31"}' contract_payable = json.dumps(contract) insert_mock_data({ 'account': {'account_id': 1}, 'reference_payment_entity': {'reference_payment_entity_id': 1}, 'reference_sap_profit_center': { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, 'reference_signing_entity': { 'reference_signing_entity_id': 1, 'reference_payment_entity_id': 1, 'reference_sap_profit_center_id': 1, 'company_code': '1234', 'tax_entity_company_code': '1234', 'legal_name': 'Company', 'vat_number': '12341234', 'company_registration_number': '12341234', 'address': None, }, 'contract': { 'contract_id': 1, 'reference_signing_entity_id': 1, }, 'statement_period': [ {'statement_period_id': 11}, {'statement_period_id': 12}, ], 'abacus_event': [ {'abacus_event_id': 1, 'statement_period_id': 11}, {'abacus_event_id': 2, 'statement_period_id': 12}, {'abacus_event_id': 3, 'statement_period_id': 12}, ], 'ledger_account_contract': { 'ledger_account_contract_id': 1, 'account_id': 1, 'contract_id': 1, 'abacus_event_id': 1 }, 'reference_payoneer_program': { 'payoneer_program_id': 1, 'payoneer_program_name': 'fake-name', 'funding_currency': 'GBP' }, 'worksheet_account_contract_closing_balance': { 'worksheet_account_contract_closing_balance_id': 1, 'account_id': 1, 'contract_id': 1, 'statement_period_id': 11, 'amount': 306, 'deleted_by': None, }, 'worksheet_account_contract_payable_after_tax': { 'worksheet_account_contract_payable_after_tax_id': 1, 'worksheet_account_contract_closing_balance_id': 1, 'account_id': 1, 'statement_period_id': 11, 'contract_id': 1, 'abacus_event_id': 1, 'payable_amount_pre_tax': 361.30, 'tax_withholding_amount': 0.00, 'vat_amount': None, 'payable_amount_post_tax': 361.30, 'currency_code': 'GBP', 'country_of_tax_residence': 'USA', 'country_of_tax_policy': 'USA', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', 'deleted_at': None, 'deleted_by': None, }, 'payment_group': { 'payment_group_id': 1, 'group_name': 'KNR UK', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, 'payment_group_payment': { 'payment_group_payment_id': 1, 'payment_group_id': 1, 'statement_period_id': 11, 'payment_name': 'AWAL - UK - Sept 22 (Pt1)', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, 'payment_group_payment_account': { 'payment_group_payment_account_id': 1, 'payment_group_payment_id': 1, 'prior_payment_group_payment_id': 1, 'account_id': 1, 'payoneer_program_id': 1, 'last_statement_period_id': 11, 'current_statement_period_id': 12, 'currency_code': 'GBP', 'last_payment': 361.30, 'contracts_payable': contract_payable, 'current_balance': 361.30, 'vat_amount': None, 'balance_after_tax': 361.30, 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', 'deleted_at': None, 'deleted_by': None, }, 'payment_group_payment_account_detail': { 'payment_group_payment_account_detail_id': 1, 'payment_group_payment_account_id': 1, 'worksheet_account_contract_payable_after_tax_id': 1, 'account_id': 1, 'contract_id': 1, 'payable_amount_pre_tax': 361.30, 'tax_withholding_amount': 0.00, 'vat_amount': None, 'payable_amount_post_tax': 361.30, 'currency_code': 'GBP', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', 'deleted_at': None, 'deleted_by': None, }, 'payment_group_payment_batch': { 'payment_group_payment_batch_id': 1, 'payment_group_payment_id': 1, 'payoneer_program_id': 1, 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, 'payment_group_payment_batch_account': { 'payment_group_payment_batch_id': 1, 'payment_group_payment_account_id': 1, 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, 'abacus_state': [ { 'abacus_state_id': 1, 'parent_table_id': 1, 'parent_table_name': 'payment_group_payment_account', 'action_name': 'send_payments', 'action_status': 'complete', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, { 'abacus_state_id': 2, 'parent_table_id': 1, 'parent_table_name': 'payment_group_payment_batch', 'action_name': 'send_payment', 'action_status': 'complete', 'created_at': datetime(2010, 9, 8, 0, 0, 0), 'created_by': 'Me', 'last_modified': datetime(2010, 9, 8, 0, 0, 0), 'last_modified_by': 'Me', }, ], }) result = WorksheetAccountContractClosingBalance.get_payment_details( account_id, statement_period_ids) assert dict(result[0]) == { 'worksheet_account_contract_closing_balance_id': Decimal('1'), 'contract_id': Decimal('1'), 'closing_balance_statement_period': Decimal('11'), 'closing_balance_amount': Decimal('306.00'), 'payable_amount_pre_tax': 361.30, 'tax_withholding_amount': 0, 'vat_amount': None, 'payable_amount_post_tax': 361.30, 'currency_code': 'GBP', 'batch_status': 'complete', 'individual_payment_status': 'complete', 'payment_statement_period_id': 11, 'created_at': '2010-09-08 00:00:00.000000', 'last_modified': '2010-09-08 00:00:00.000000' }