Coverage for src/usaspending/models/loan.py: 97%

32 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-03 17:15 -0700

1"""Loan award model for USASpending data.""" 

2 

3from __future__ import annotations 

4from typing import Dict, Any, Optional, List 

5 

6from .grant import Grant 

7from .award import Award 

8from ..utils.formatter import to_float 

9 

10 

11class Loan(Grant): 

12 """Loan award type.""" 

13 

14 TYPE_FIELDS = [ 

15 "fain", 

16 "uri", 

17 "total_subsidy_cost", 

18 "total_loan_value", 

19 "cfda_info", 

20 "cfda_number", 

21 "primary_cfda_info", 

22 "sai_number", 

23 ] 

24 

25 SEARCH_FIELDS = Award.SEARCH_FIELDS + [ 

26 "Issued Date", 

27 "Loan Value", 

28 "Subsidy Cost", 

29 "SAI Number", 

30 "CFDA Number", 

31 "Assistance Listings", 

32 "primary_assistance_listing", 

33 ] 

34 

35 @property 

36 def fain(self) -> Optional[str]: 

37 """ 

38 An identification code assigned to each financial assistance award tracking 

39 purposes. The FAIN is tied to that award (and all future modifications to that 

40 award) throughout the award's life. Each FAIN is assigned by an agency. Within 

41 an agency, FAIN are unique: each new award must be issued a new FAIN. FAIN 

42 stands for Federal Award Identification Number, though the digits are letters, 

43 not numbers. 

44 """ 

45 return self._lazy_get("fain") 

46 

47 @property 

48 def uri(self) -> Optional[str]: 

49 """The uri of the award""" 

50 return self._lazy_get("uri") 

51 

52 @property 

53 def total_subsidy_cost(self) -> Optional[float]: 

54 """The total of the original_loan_subsidy_cost from associated transactions""" 

55 return to_float( 

56 self._lazy_get("Subsidy Cost", "total_subsidy_cost", default=None) 

57 ) 

58 

59 @property 

60 def total_loan_value(self) -> Optional[float]: 

61 """The total of the face_value_loan_guarantee from associated transactions""" 

62 return to_float(self._lazy_get("Loan Value", "total_loan_value", default=None)) 

63 

64 @property 

65 def cfda_info(self) -> List[Dict[str, Any]]: 

66 """Catalog of Federal Domestic Assistance information for loans.""" 

67 return self._lazy_get("cfda_info", "Assistance Listings", default=[]) 

68 

69 @property 

70 def cfda_number(self) -> Optional[str]: 

71 """Primary CFDA number for loans.""" 

72 return self._lazy_get("cfda_number", "CFDA Number") 

73 

74 @property 

75 def primary_cfda_info(self) -> Optional[Dict[str, Any]]: 

76 """Primary CFDA program information.""" 

77 return self._lazy_get("primary_cfda_info", "primary_assistance_listing") 

78 

79 @property 

80 def sai_number(self) -> Optional[str]: 

81 """System for Award Identification (SAI) number for loans.""" 

82 return self._lazy_get("sai_number", "SAI Number")