-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
24195 tweaks on filing queries #3166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -851,7 +851,7 @@ def get_temp_reg_filing(temp_reg_id: str, filing_id: str = None): | |
q = db.session.query(Filing).filter(Filing.temp_reg == temp_reg_id) | ||
|
||
if filing_id: | ||
q.filter(Filing.id == filing_id) | ||
q = q.filter(Filing.id == filing_id) | ||
|
||
filing = q.one_or_none() | ||
return filing | ||
|
@@ -896,7 +896,7 @@ def get_filings_by_types(business_id: int, filing_types): | |
filter(Filing.business_id == business_id). \ | ||
filter(Filing._filing_type.in_(filing_types)). \ | ||
filter(Filing._status == Filing.Status.COMPLETED.value). \ | ||
order_by(desc(Filing.effective_date)). \ | ||
order_by(desc(Filing.transaction_id)). \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order with transaction_id for COMPLETED filing queries |
||
all() | ||
return filings | ||
|
||
|
@@ -956,23 +956,21 @@ def get_filings_by_type_pairs(business_id: int, filing_type_pairs: list, status: | |
return filings | ||
|
||
@staticmethod | ||
def get_a_businesses_most_recent_filing_of_a_type(business_id: int, filing_type: str, filing_sub_type: str = None): | ||
"""Return the filings of a particular type.""" | ||
max_filing = db.session.query(db.func.max(Filing._filing_date).label('last_filing_date')).\ | ||
filter(Filing._filing_type == filing_type). \ | ||
filter(Filing.business_id == business_id) | ||
if filing_sub_type: | ||
max_filing = max_filing.filter(Filing._filing_sub_type == filing_sub_type) | ||
max_filing = max_filing.subquery() | ||
def get_most_recent_filing(business_id: str, filing_type: str = None, filing_sub_type: str = None): | ||
"""Return the most recent filing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified and generalize this function |
||
|
||
filing = Filing.query.join(max_filing, Filing._filing_date == max_filing.c.last_filing_date). \ | ||
filing_type is required, if filing_sub_type is provided, it will be used to filter the query. | ||
""" | ||
query = db.session.query(Filing). \ | ||
filter(Filing.business_id == business_id). \ | ||
filter(Filing._filing_type == filing_type). \ | ||
filter(Filing._status == Filing.Status.COMPLETED.value) | ||
if filing_sub_type: | ||
filing = filing.filter(Filing._filing_sub_type == filing_sub_type) | ||
if filing_type: | ||
query = query.filter(Filing._filing_type == filing_type) | ||
if filing_sub_type: | ||
query = query.filter(Filing._filing_sub_type == filing_sub_type) | ||
|
||
return filing.one_or_none() | ||
query = query.order_by(Filing.transaction_id.desc()) | ||
return query.first() | ||
|
||
@staticmethod | ||
def get_most_recent_legal_filing(business_id: str, filing_type: str = None): | ||
|
@@ -1037,15 +1035,14 @@ def get_all_filings_by_status(status): | |
@staticmethod | ||
def get_previous_completed_filing(filing): | ||
"""Return the previous completed filing.""" | ||
filings = db.session.query(Filing). \ | ||
query = db.session.query(Filing). \ | ||
filter(Filing.business_id == filing.business_id). \ | ||
filter(Filing._status == Filing.Status.COMPLETED.value). \ | ||
filter(Filing.id < filing.id). \ | ||
filter(Filing.effective_date < filing.effective_date). \ | ||
order_by(Filing.effective_date.desc()).all() | ||
if filings: | ||
return filings[0] | ||
return None | ||
filter(Filing._status == Filing.Status.COMPLETED.value) | ||
|
||
if filing.transaction_id: # transaction_id will be None for the pending filings (intermediate state) | ||
query = query.filter(Filing.transaction_id < filing.transaction_id) | ||
|
||
return query.order_by(Filing.transaction_id.desc()).first() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order with transaction_id for COMPLETED filing queries |
||
|
||
@staticmethod | ||
def has_completed_filing(business_id: int, filing_type: str) -> bool: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,6 @@ def get_businesses(identifier: str): | |
recent_filing_json = CoreFiling.get_most_recent_filing_json(business.id, None, jwt) | ||
if recent_filing_json: | ||
business_json['submitter'] = recent_filing_json['filing']['header']['submitter'] | ||
business_json['lastModified'] = recent_filing_json['filing']['header']['date'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required to override. lastModified will be updated in entity-filer while processing a filing |
||
|
||
allowed_filings = str(request.args.get('allowed_filings', None)).lower() == 'true' | ||
if allowed_filings: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included in _slim_json