Skip to content

Commit

Permalink
25328 - Support Update and Save NoW Draft for Bootstrap Filing (#3183)
Browse files Browse the repository at this point in the history
* 25328-Add-special-case-for-NoW-when-getting-file-for-temp-reg-id

* 25328-Update-requirements-for-schema-update

* 25328-Clean-up-code

* 25328-Optimize-query-for-temp-reg-filing
  • Loading branch information
meawong authored Jan 28, 2025
1 parent 507d7c0 commit f7a217b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion legal-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ PyPDF2==1.26.0
reportlab==3.6.12
html-sanitizer==2.4.1
lxml==5.2.2
git+https://github.com/bcgov/[email protected].32#egg=registry_schemas
git+https://github.com/bcgov/[email protected].33#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=sql-versioning&subdirectory=python/common/sql-versioning
2 changes: 1 addition & 1 deletion legal-api/requirements/bcregistry-libraries.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/bcgov/[email protected].32#egg=registry_schemas
git+https://github.com/bcgov/[email protected].33#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=sql-versioning&subdirectory=python/common/sql-versioning
2 changes: 1 addition & 1 deletion legal-api/src/legal_api/core/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def validate():
def get(identifier, filing_id=None) -> Optional[Filing]:
"""Return a Filing domain by the id."""
if identifier.startswith('T'):
storage = FilingStorage.get_temp_reg_filing(identifier)
storage = FilingStorage.get_temp_reg_filing(identifier, filing_id)
else:
storage = Business.get_filing_by_id(identifier, filing_id)

Expand Down
28 changes: 20 additions & 8 deletions legal-api/src/legal_api/models/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,26 @@ def find_by_id(cls, filing_id: str = None):

@staticmethod
def get_temp_reg_filing(temp_reg_id: str, filing_id: str = None):
"""Return a Filing by it's payment token."""
q = db.session.query(Filing).filter(Filing.temp_reg == temp_reg_id)

if filing_id:
q = q.filter(Filing.id == filing_id)

filing = q.one_or_none()
return filing
"""Return a filing by the temp id and filing id (if applicable)."""
if not filing_id:
return db.session.query(Filing).filter(Filing.temp_reg == temp_reg_id).one_or_none()

return (
db.session.query(Filing).filter(
db.or_(
db.and_(
Filing.id == filing_id,
Filing.temp_reg == temp_reg_id
),
db.and_( # special case for NoW
Filing.id == filing_id,
Filing._filing_type == 'noticeOfWithdrawal',
Filing.withdrawn_filing_id == db.session.query(Filing.id)
.filter(Filing.temp_reg == temp_reg_id)
.scalar_subquery()
)
)
).one_or_none())

@staticmethod
def get_filing_by_payment_token(token: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1764,3 +1764,16 @@ def test_notice_of_withdrawal_filing(session, client, jwt, test_name, legal_type
assert now_filing.withdrawal_pending == False
if is_temp:
assert now_filing.temp_reg == None

# update and save notice of withdrawal draft filing
now_json_data['filing']['header']['certifiedBy'] = 'test123'

rv_draft = client.put(f'/api/v2/businesses/{identifier}/filings/{now_filing.id}?draft=true',
json=now_json_data,
headers=create_header(jwt, [STAFF_ROLE], identifier))

# validate
assert rv_draft.status_code == HTTPStatus.ACCEPTED
assert rv_draft.json['filing']['header']['certifiedBy'] == 'test123'


0 comments on commit f7a217b

Please sign in to comment.