"""Worksheet correction model tests.""" from decimal import Decimal from abacus_worksheet.constants import constants from abacus_worksheet.models.worksheet_correction import WorksheetCorrection from tests.utils.factories import WorksheetCorrectionFactory def test_worksheet_correction_create(mock_worksheet_correction_data): """Test worksheet correction model.""" mock_data = mock_worksheet_correction_data response = WorksheetCorrection.build(**mock_data) assert response.account_id == mock_data['account_id'] assert response.contract_id == mock_data['contract_id'] assert ( response.correction_statement_period_id == mock_data['correction_statement_period_id'] ) assert response.correction_type == mock_data['correction_type'] assert response.currency_code == mock_data['currency_code'] assert response.gross_revenue == mock_data['gross_revenue'] assert response.distribution_fee == mock_data['distribution_fee'] assert response.net_revenue == mock_data['net_revenue'] assert response.statement_period_id == mock_data['statement_period_id'] assert response.created_by is not None assert response.last_modified_by is not None assert response.mechanical_deduction_total is None assert response.mechanical_deduction_admin_fee_total is None def test_worksheet_correction_create_with_mech_columns(mock_worksheet_correction_data): """Test worksheet correction model including mech deduction columns.""" mock_data = mock_worksheet_correction_data response = WorksheetCorrection.build( **mock_data, mechanical_deduction_total=Decimal(80.89), mechanical_deduction_admin_fee_total=Decimal(78.11), ) assert response.account_id == mock_data['account_id'] assert response.contract_id == mock_data['contract_id'] assert ( response.correction_statement_period_id == mock_data['correction_statement_period_id'] ) assert response.correction_type == mock_data['correction_type'] assert response.currency_code == mock_data['currency_code'] assert response.gross_revenue == mock_data['gross_revenue'] assert response.distribution_fee == mock_data['distribution_fee'] assert response.net_revenue == mock_data['net_revenue'] assert response.statement_period_id == mock_data['statement_period_id'] assert response.created_by is not None assert response.last_modified_by is not None assert response.mechanical_deduction_total == Decimal(80.89) assert response.mechanical_deduction_admin_fee_total == Decimal(78.11) def test_get_unapplied_worksheet_corrections(create_mock_ledger_correction): """Test to get unapplied worksheet corrections. return records that don't exist in ledger_correction_table. """ statement_period = 2 correction_type = constants.CORRECTION_TYPES.ROYALTY_REVERSAL limit = 2 offset = 0 worksheet_correction = WorksheetCorrectionFactory.create( correction_type=correction_type ) items, total_count = WorksheetCorrection.get_unapplied_worksheet_corrections( statement_period, correction_type, limit, offset ) assert total_count == 1 assert ( items[0].worksheet_correction_id == worksheet_correction.worksheet_correction_id ) assert items[0].mechanical_deduction_total is None assert items[0].mechanical_deduction_admin_fee_total is None def test_get_unapplied_non_deleted_worksheet_corrections(): """Test to get unapplied worksheet corrections. return records that are not deleted. """ statement_period = 2 correction_type = constants.CORRECTION_TYPES.ROYALTY_CORRECTION limit = 2 offset = 0 WorksheetCorrectionFactory.create_batch(2) items, total_count = WorksheetCorrection.get_unapplied_worksheet_corrections( statement_period, correction_type, limit, offset ) assert total_count == 2 assert all([item.correction_type == correction_type for item in items]) assert all([item.deleted_at is None for item in items]) assert all([item.deleted_by is None for item in items])