From ccd038a594d11c8c7fec031e227b65f208cacd38 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Mon, 11 Nov 2024 07:18:42 -0500 Subject: [PATCH] Add properties for latest 10K and 10Q --- edgar/entities.py | 35 +++++++++++++++++++++++------------ tests/test_entity.py | 14 ++++++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/edgar/entities.py b/edgar/entities.py index 2df28846..7d04dc5c 100644 --- a/edgar/entities.py +++ b/edgar/entities.py @@ -24,6 +24,7 @@ from edgar.core import (log, Result, display_size, listify, is_using_local_storage, filter_by_date, IntString, InvalidDateException, reverse_name, get_edgar_data_directory) from edgar.financials import Financials +from edgar.company_reports import TenK, TenQ from edgar.httprequests import download_json, download_text, download_bulk_data from edgar.reference import states from edgar.reference.tickers import get_company_tickers, get_icon_from_ticker, find_cik @@ -401,26 +402,36 @@ def __init__(self, self._loaded_all_filings: bool = False @property - def financials(self): - """ - Get the latest 10-K financials - """ + def latest_tenk(self) -> Optional[TenK]: if self.is_company: - # Get the latest 10-K latest_10k = self.get_filings(form='10-K', trigger_full_load=False).latest() if latest_10k is not None: - return Financials.extract(latest_10k) + return latest_10k.obj() @property - def quarterly_financials(self): + def latest_tenq(self) -> Optional[TenQ]: + if self.is_company: + latest_10q = self.get_filings(form='10-Q', trigger_full_load=False).latest() + if latest_10q is not None: + return latest_10q.obj() + + @property + def financials(self) -> Optional[Financials]: + """ + Get the latest 10-K financials + """ + tenk_filing = self.latest_tenk + if tenk_filing is not None: + return tenk_filing.financials + + @property + def quarterly_financials(self)-> Optional[Financials]: """ Get the latest 10-Q financials """ - if self.is_company: - # Get the latest 10-K - latest_10k = self.get_filings(form='10-Q', trigger_full_load=False).latest() - if latest_10k is not None: - return Financials.extract(latest_10k) + tenq_filing = self.latest_tenq + if tenq_filing is not None: + return tenq_filing.financials @property def is_company(self) -> bool: diff --git a/tests/test_entity.py b/tests/test_entity.py index 2894bd67..b071b6af 100644 --- a/tests/test_entity.py +++ b/tests/test_entity.py @@ -1,6 +1,6 @@ from edgar import get_entity from edgar.entities import get_entity_submissions, Entity, Company - +from edgar.company_reports import TenK, TenQ def test_entity_is_company(): # TSLA @@ -99,4 +99,14 @@ def test_getting_company_financials_does_not_load_additional_filings(): c = Company("KO") f = c.financials assert f - assert not c._loaded_all_filings \ No newline at end of file + assert not c._loaded_all_filings + + +def test_get_latest_company_reports(): + c = Company(1318605) + tenk = c.latest_tenk + assert tenk + assert isinstance(tenk, TenK) + tenq = c.latest_tenq + assert tenq + assert isinstance(tenq, TenQ) \ No newline at end of file