"""Test cases for worksheet_account_contract_taxable_revenue model.""" from payment.constants import constants from payment.models.worksheet_account_contract_taxable_revenue import ( WorksheetAccountContractTaxableRevenue, ) from tests.utils.factories import WorksheetAccountContractTaxableRevenueFactory def test_create( mock_contracts, mock_accounts, mock_abacus_event, mock_statement_periods, mock_worksheet_account_contract_closing_balance, ): """Create a worksheet taxable revenue instance.""" contract_id = 1 account_id = 1 abacus_event_id = 1 statement_period_id = 1 close_balance_id = 1 reference_payment_entity_id = 1 currency_code = 'USD' amount = 100 is_us_revenue = True revenue_transaction_type = constants.REVENUE_TRANSACTION_TYPES.CLOSING_BALANCE created_item = WorksheetAccountContractTaxableRevenue.create( worksheet_account_contract_closing_balance_id=close_balance_id, contract_id=contract_id, account_id=account_id, reference_payment_entity_id=reference_payment_entity_id, abacus_event_id=abacus_event_id, statement_period_id=statement_period_id, currency_code=currency_code, amount=amount, revenue_transaction_type=revenue_transaction_type, is_us_revenue=is_us_revenue, ) found_item = WorksheetAccountContractTaxableRevenue.get_by_id( created_item.account_contract_taxable_revenue_id ) assert found_item == created_item assert found_item.contract_id == contract_id assert found_item.account_id == account_id assert found_item.abacus_event_id == abacus_event_id assert found_item.statement_period_id == statement_period_id assert found_item.worksheet_account_contract_closing_balance_id == close_balance_id assert found_item.reference_payment_entity_id == reference_payment_entity_id assert found_item.revenue_transaction_type == revenue_transaction_type assert found_item.is_us_revenue == is_us_revenue assert found_item.currency_code == currency_code assert found_item.amount == amount assert not found_item.deleted_at assert not found_item.deleted_by assert found_item.created_at assert found_item.last_modified assert found_item.last_modified_by def test_soft_delete_by_event_id( mock_contracts, mock_accounts, mock_abacus_event, mock_statement_periods, mock_worksheet_account_contract_closing_balance, ): """Soft delete worksheet taxable revenue instances by event id.""" contract_id = 1 account_id = 1 abacus_event_id = 1 statement_period_id = 1 close_balance_id = 1 reference_payment_entity_id = 1 currency_code = 'USD' amount = 100 is_us_revenue = True revenue_transaction_type = constants.REVENUE_TRANSACTION_TYPES.CLOSING_BALANCE created_item = WorksheetAccountContractTaxableRevenue.create( worksheet_account_contract_closing_balance_id=close_balance_id, contract_id=contract_id, account_id=account_id, reference_payment_entity_id=reference_payment_entity_id, abacus_event_id=abacus_event_id, statement_period_id=statement_period_id, currency_code=currency_code, amount=amount, revenue_transaction_type=revenue_transaction_type, is_us_revenue=is_us_revenue, ) WorksheetAccountContractTaxableRevenue.soft_delete_by_event_id(abacus_event_id) found_item = WorksheetAccountContractTaxableRevenue.get_by_id( created_item.worksheet_account_contract_closing_balance_id ) assert found_item.deleted_at assert found_item.deleted_by assert found_item.last_modified == found_item.deleted_at assert found_item.last_modified_by == found_item.deleted_by assert found_item.deleted_at >= found_item.created_at assert found_item.deleted_by == 'default_user_id' def test_get_filtered_items( mock_contracts, mock_accounts, mock_abacus_event, mock_statement_periods, mock_worksheet_account_contract_closing_balance, ): """Test get_filtered_items method.""" worksheet1 = WorksheetAccountContractTaxableRevenueFactory.create( contract_id=1, worksheet_account_contract_closing_balance_id=1, statement_period_id=1, ) worksheet2 = WorksheetAccountContractTaxableRevenueFactory.create( contract_id=2, worksheet_account_contract_closing_balance_id=2, statement_period_id=2, ) items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0 ) assert items == [worksheet1, worksheet2] assert total_count == 2 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=1, offset=1 ) assert items == [worksheet2] assert total_count == 2 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1, contract_ids=[1, 2], closing_balance_ids=[1, 2], ) assert items == [worksheet1] assert total_count == 1 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1 ) assert items == [worksheet1] assert total_count == 1 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1, contract_ids=[1] ) assert items == [worksheet1] assert total_count == 1 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1, contract_ids=[2] ) assert items == [] assert total_count == 0 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=3 ) assert items == [] assert total_count == 0 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1, closing_balance_ids=[1] ) assert items == [worksheet1] assert total_count == 1 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, statement_period_id=1, closing_balance_ids=[2] ) assert items == [] assert total_count == 0 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, closing_balance_ids=[2] ) assert items == [worksheet2] assert total_count == 1 items, total_count = WorksheetAccountContractTaxableRevenue.get_filtered_items( limit=100, offset=0, contract_ids=[2] ) assert items == [worksheet2] assert total_count == 1