"""Functional tests for payment entity endpoints.""" from moneyhub.constants.constants import VatCategory from tests.functional.conftest import insert_mock_data def test_get_vat_data_by_payment_entity_and_statement_period_accountin_run(fixture_client): """Test getting VAT data by payment entity when data is in the accounting run vat table.""" payment_entity_id = 111 statement_period_id = 123 insert_mock_data({ 'account': {'account_id': 24601}, 'abacus_event': {'abacus_event_id': 1}, 'reference_payment_entity': {'reference_payment_entity_id': payment_entity_id}, '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': payment_entity_id, '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': 1001, 'reference_signing_entity_id': 1, }, 'ledger_account_contract': {'abacus_event_id': 1, 'account_id': 24601, 'contract_id': 1001}, 'statement_period': {'statement_period_id': statement_period_id}, 'accounting_period': { 'accounting_period_id': 1, 'statement_period_id': statement_period_id }, 'run_controller': {'run_controller_id': 1}, 'accounting_run': { 'accounting_run_id': 1, 'accounting_period_id': 1, 'run_controller_id': 1, }, 'account_payment_term': { 'account_id': 24601, 'currency_code': 'GBP', 'payment_entity_id': payment_entity_id, 'agreement_type_id': 1, }, 'ledger_accounting_run_vat': { 'accounting_run_id': 1, 'abacus_event_id': 1, 'contract_id': 1001, 'currency_code': 'GBP', 'gross_revenue': 1000.0, 'net_revenue': 800.0, 'distribution_fee': 200.0, 'gross_vat_rate': 20.0, 'distribution_vat_rate': 20.0, 'gross_vat': 200.0, 'distribution_vat': 200.0, 'adjusted_net_revenue': 200.0, }, }) result = fixture_client.get( f'/payment-entity/{payment_entity_id}/statement-period/{statement_period_id}/vat') assert result.status_code == 200 assert result.json() == {'vat_data': True} def test_get_vat_data_by_payment_entity_and_statement_period_no_data(fixture_client): """Test getting VAT data by payment entity when there is no data.""" payment_entity_id = 111 statement_period_id = 123 insert_mock_data({ 'account': {'account_id': 24601}, 'reference_payment_entity': {'reference_payment_entity_id': 222}, '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': 222, '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': 1001, 'reference_signing_entity_id': 1, }, 'statement_period': {'statement_period_id': statement_period_id}, 'abacus_event': {'abacus_event_id': 1}, 'account_payment_term': { 'account_id': 24601, 'currency_code': 'GBP', 'payment_entity_id': 222, 'agreement_type_id': 1, }, 'ledger_vat_summary': { 'statement_period_id': statement_period_id, 'activity_statement_period_id': statement_period_id, 'abacus_event_id': 1, 'account_id': 24601, 'contract_id': 1001, 'vat_category': VatCategory.GROSS_REVENUE, 'payee_currency_code': 'GBP', 'vat_currency_code': 'GBP', 'base_amount_payee_currency': 1000.00, 'vat_rate': 20.0, 'vat_amount_payee_currency': 200.00, 'vat_amount_vat_currency': 200.00, 'net_amount_payee_currency': 800.00, }, }) result = fixture_client.get( f'/payment-entity/{payment_entity_id}/statement-period/{statement_period_id}/vat') assert result.status_code == 200 assert result.json() == {'vat_data': False} def test_get_vat_data_by_payment_entity_and_statement_period(fixture_client): """Test getting VAT data by payment entity.""" payment_entity_id = 1 statement_period_id = 123 activity_statement_period_id = 122 insert_mock_data({ 'account': {'account_id': 24601}, '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': 1001, 'reference_signing_entity_id': 1, }, 'statement_period': [ {'statement_period_id': statement_period_id}, {'statement_period_id': activity_statement_period_id}, ], 'abacus_event': {'abacus_event_id': 1}, 'account_payment_term': { 'account_id': 24601, 'currency_code': 'GBP', 'payment_entity_id': 1, 'agreement_type_id': 1, }, 'ledger_vat_summary': { 'statement_period_id': statement_period_id, 'activity_statement_period_id': activity_statement_period_id, 'abacus_event_id': 1, 'account_id': 24601, 'contract_id': 1001, 'vat_category': VatCategory.GROSS_REVENUE, 'payee_currency_code': 'GBP', 'vat_currency_code': 'GBP', 'base_amount_payee_currency': 1000.00, 'vat_rate': 20.0, 'vat_amount_payee_currency': 200.00, 'vat_amount_vat_currency': 200.00, 'net_amount_payee_currency': 800.00, }, }) result = fixture_client.get( f'/payment-entity/{payment_entity_id}/statement-period/{activity_statement_period_id}/vat') # noqa: E501 assert result.status_code == 200 assert result.json() == {'vat_data': True}