Skip to content

Commit de11c57

Browse files
committed
Fixes Loans process will not launch if any loans have due date before checkout date #928
1 parent ede57e0 commit de11c57

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/folio_migration_tools/migration_tasks/loans_migrator.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from art import tprint
1818

1919
from folio_migration_tools.circulation_helper import CirculationHelper
20+
from folio_migration_tools.custom_exceptions import TransformationRecordFailedError
2021
from folio_migration_tools.helper import Helper
2122
from folio_migration_tools.library_configuration import (
2223
FileDefinition,
@@ -302,7 +303,7 @@ def set_renewal_count(self, legacy_loan: LegacyLoan, res_checkout: TransactionRe
302303

303304
def wrap_up(self):
304305
for k, v in self.failed.items():
305-
self.failed_and_not_dupe[k] = [v.to_dict()]
306+
self.failed_and_not_dupe[k] = [v if type(v) is dict else v.to_dict()]
306307
print(f"Wrapping up. Unique loans in failed:{len(self.failed_and_not_dupe)}")
307308

308309
self.write_failed_loans_to_file()
@@ -404,6 +405,19 @@ def load_and_validate_legacy_loans(self, loans_reader, service_point_id: str) ->
404405
] = legacy_loan
405406
else:
406407
results.append(legacy_loan)
408+
except TransformationRecordFailedError as trfe:
409+
num_bad += 1
410+
self.migration_report.add_general_statistics(
411+
i18n.t("Loans failed pre-validation")
412+
)
413+
self.migration_report.add(
414+
"DiscardedLoans",
415+
f"{trfe.message} - see data issues log",
416+
)
417+
trfe.log_it()
418+
self.failed[
419+
legacy_loan_dict.get("item_barcode", f"no_barcode_{legacy_loan_count}")
420+
] = legacy_loan_dict
407421
except ValueError as ve:
408422
logging.exception(ve)
409423
logging.info(

src/folio_migration_tools/transaction_migration/legacy_loan.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dateutil.parser import parse, ParserError
99

1010
from folio_migration_tools.migration_report import MigrationReport
11-
from folio_migration_tools.custom_exceptions import TransformationProcessError
11+
from folio_migration_tools.custom_exceptions import TransformationRecordFailedError
1212

1313
utc = ZoneInfo("UTC")
1414

@@ -124,7 +124,13 @@ def correct_for_1_day_loans(self):
124124
if self.out_date.hour == 0:
125125
self.out_date = self.out_date.replace(hour=0, minute=1)
126126
if self.due_date <= self.out_date:
127-
raise TransformationProcessError(self.row, i18n.t("Due date is before out date, or date information is missing from both"), json.dumps(self.legacy_loan_dict, indent=2))
127+
raise TransformationRecordFailedError(
128+
self.row,
129+
i18n.t(
130+
"Due date is before out date, or date information is missing from both"
131+
),
132+
json.dumps(self.legacy_loan_dict, indent=2)
133+
)
128134

129135
def to_dict(self):
130136
return {

tests/test_legacy_loan.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from folio_migration_tools.migration_report import MigrationReport
66
from folio_migration_tools.transaction_migration.legacy_loan import LegacyLoan
7-
from folio_migration_tools.custom_exceptions import TransformationProcessError
7+
from folio_migration_tools.custom_exceptions import TransformationProcessError, TransformationRecordFailedError
88

99

1010
def test_init():
@@ -272,10 +272,10 @@ def test_correct_for_1_day_loans_due_date_is_before_out_date() -> None:
272272
tenant_timezone = ZoneInfo("UTC")
273273
migration_report = MigrationReport()
274274
expected_err_message = (
275-
"Critical Process issue. Check configuration, mapping files and reference data\t"
275+
"Critical data issue. Record needs fixing\t"
276276
f"0\tDue date is before out date, or date information is missing from both\t{json.dumps(loan_dict, indent=2)}"
277277
)
278-
with pytest.raises(TransformationProcessError, match=expected_err_message):
278+
with pytest.raises(TransformationRecordFailedError, match=expected_err_message):
279279
LegacyLoan(loan_dict, "", migration_report, tenant_timezone)
280280

281281
def test_correct_for_1_day_loans_no_out_or_due_date_info() -> None:
@@ -290,8 +290,8 @@ def test_correct_for_1_day_loans_no_out_or_due_date_info() -> None:
290290
tenant_timezone = ZoneInfo("UTC")
291291
migration_report = MigrationReport()
292292
expected_err_message = (
293-
"Critical Process issue. Check configuration, mapping files and reference data\t"
293+
"Critical data issue. Record needs fixing\t"
294294
f"0\tDue date is before out date, or date information is missing from both\t{json.dumps(loan_dict, indent=2)}"
295295
)
296-
with pytest.raises(TransformationProcessError, match=expected_err_message):
296+
with pytest.raises(TransformationRecordFailedError, match=expected_err_message):
297297
LegacyLoan(loan_dict, "", migration_report, tenant_timezone)

0 commit comments

Comments
 (0)