"""Statement period payment entity model tests.""" import pytest from moneyhub.constants.constants import StatementPeriodStatus from moneyhub.models.statement_period_payment_entity import StatementPeriodPaymentEntity from tests.unit.conftest import insert_mock_data def test_get_for_account_and_statement_period(): """Test getting visible statement period IDs for account/statement period.""" account_id = 24601 statement_period_id = 123 insert_mock_data({ 'account': [ {'account_id': 12345}, {'account_id': account_id}, ], 'reference_payment_entity': [ {'reference_payment_entity_id': 1}, {'reference_payment_entity_id': 2} ], 'reference_sap_profit_center': [ { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, { 'reference_sap_profit_center_id': 2, 'profit_center': 'UK1234', 'company_code': '12345', '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, }, { 'reference_signing_entity_id': 2, 'reference_payment_entity_id': 2, 'reference_sap_profit_center_id': 2, 'company_code': '12345', 'tax_entity_company_code': '12345', 'legal_name': 'Company1', 'vat_number': '12351235', 'company_registration_number': '12351235', 'address': None, }], 'account_payment_term': [ {'account_id': 12345, 'payment_entity_id': 1}, {'account_id': account_id, 'payment_entity_id': 2}, ], 'statement_period': [ {'statement_period_id': 111}, {'statement_period_id': statement_period_id}, {'statement_period_id': 999}, ], 'statement_period_payment_entity': [ { 'statement_period_id': 111, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 0, }, { 'statement_period_id': 111, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 0, }, { 'statement_period_id': statement_period_id, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 0, }, { 'statement_period_id': statement_period_id, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 1, }, { 'statement_period_id': 999, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 0, }, { 'statement_period_id': 999, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 0, }, ] }) result = StatementPeriodPaymentEntity.get_for_account_and_statement_period( account_id, statement_period_id) assert result.is_visible_to_customer == 1 def test_get_visible_statement_period_ids(): """Test getting visible statement period IDs.""" account_id1 = 24601 account_id2 = 12345 insert_mock_data({ 'account': [ {'account_id': account_id2}, {'account_id': account_id1}, ], 'reference_payment_entity': [ {'reference_payment_entity_id': 1}, {'reference_payment_entity_id': 2} ], 'reference_sap_profit_center': [ { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, { 'reference_sap_profit_center_id': 2, 'profit_center': 'UK1234', 'company_code': '12345', '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, }, { 'reference_signing_entity_id': 2, 'reference_payment_entity_id': 2, 'reference_sap_profit_center_id': 2, 'company_code': '12345', 'tax_entity_company_code': '12345', 'legal_name': 'Company1', 'vat_number': '12362234', 'company_registration_number': '12341234', 'address': None, }], 'account_payment_term': [ {'account_id': account_id2, 'payment_entity_id': 1}, {'account_id': account_id1, 'payment_entity_id': 2}, ], 'statement_period': [ {'statement_period_id': 111, 'statement_period_status': StatementPeriodStatus.CLOSED}, {'statement_period_id': 222, 'statement_period_status': StatementPeriodStatus.CLOSED}, {'statement_period_id': 333, 'statement_period_status': StatementPeriodStatus.CURRENT}, {'statement_period_id': 444, 'statement_period_status': StatementPeriodStatus.OPEN}, ], 'statement_period_payment_entity': [ {'statement_period_id': 111, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 1}, {'statement_period_id': 111, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 0}, {'statement_period_id': 222, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 1}, {'statement_period_id': 222, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 1}, {'statement_period_id': 333, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 1}, {'statement_period_id': 333, 'reference_payment_entity_id': 2, 'is_visible_to_customer': 0}, {'statement_period_id': 444, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 0}, {'statement_period_id': 444, 'reference_payment_entity_id': 1, 'is_visible_to_customer': 0}, ] }) result = StatementPeriodPaymentEntity.get_visible_statement_period_ids( account_id1) assert result == [111, 222] result = StatementPeriodPaymentEntity.get_visible_statement_period_ids( account_id2) assert result == [111, 222, 333] @pytest.mark.parametrize( 'period_status,is_visible,expected', [ (StatementPeriodStatus.CLOSED, 1, True), (StatementPeriodStatus.CLOSED, 0, True), (StatementPeriodStatus.OPEN, 1, True), (StatementPeriodStatus.OPEN, 0, False), ] ) def test_is_statement_period_visible(period_status, is_visible, expected): """Test checking if a statement period is visible.""" account_id = 24601 statement_period_id = 123 insert_mock_data({ 'account': {'account_id': account_id}, 'account_payment_term': {'account_id': account_id, 'payment_entity_id': 1}, 'statement_period': { 'statement_period_id': statement_period_id, 'statement_period_status': period_status, }, 'statement_period_payment_entity': { 'statement_period_id': statement_period_id, 'reference_payment_entity_id': 1, 'is_visible_to_customer': is_visible, }, }) result = StatementPeriodPaymentEntity.is_statement_period_visible( account_id, statement_period_id) assert result is expected