"""Unit tests for Ledger Adjustment Detail model.""" from decimal import Decimal from ledger.constants.constants import DISTRIBUTION_TYPES from ledger.models.ledger_adjustment_detail import LedgerAdjustmentDetail from tests.utils.factories import ReferenceAdjustmentTypeFactory def test_create_adjustment_detail(mock_event_fixtures): """Test to create a Ledger Adjustment Detail.""" adjustment_type = ReferenceAdjustmentTypeFactory.create() assert len(LedgerAdjustmentDetail.query.all()) == 0 LedgerAdjustmentDetail.create( account_id=1, contract_id=1, activity_statement_period_id=1, apply_to_statement_period_id=2, currency_code='USD', amount=Decimal('550.23'), upc='543234251515', distribution_type=DISTRIBUTION_TYPES.PHYSICAL, note='info message', reference_adjustment_type_id=adjustment_type.reference_adjustment_type_id, ) records = LedgerAdjustmentDetail.query.all() assert len(records) == 1 assert records[0].ledger_adjustment_detail_id == 1 assert records[0].distribution_type == DISTRIBUTION_TYPES.PHYSICAL def test_create_adjustment_detail_with_upc_leading_zero(mock_event_fixtures): """Test to create a Ledger Adjustment Detail with an upc that has a leading zeros.""" adjustment_type = ReferenceAdjustmentTypeFactory.create() assert len(LedgerAdjustmentDetail.query.all()) == 0 LedgerAdjustmentDetail.create( account_id=50, contract_id=2, activity_statement_period_id=1, apply_to_statement_period_id=2, currency_code='AUD', amount=Decimal('550.23'), upc='001234211514', distribution_type=DISTRIBUTION_TYPES.PHYSICAL, note='info message', reference_adjustment_type_id=adjustment_type.reference_adjustment_type_id, ) records = LedgerAdjustmentDetail.query.all() assert len(records) == 1 assert records[0].ledger_adjustment_detail_id == 1 assert records[0].distribution_type == DISTRIBUTION_TYPES.PHYSICAL assert records[0].upc == '001234211514'