Skip to content

Commit

Permalink
[MDS-4259] ESUP amendment without permit number (#2704)
Browse files Browse the repository at this point in the history
* wip

* remove print statement.

* update permit number logic.

* remove feature flag

* remove permit number assignment.

* add unit tests, fix PR comments.
  • Loading branch information
henryoforeh-dev authored Oct 3, 2023
1 parent 56d0a92 commit 04794a3
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,9 @@ def find_by_mine_guid(cls, mine_guid):
def find_by_explosives_permit_guid(cls, explosives_permit_guid):
return cls.query.filter_by(
explosives_permit_guid=explosives_permit_guid, deleted_ind=False).one_or_none()

@classmethod
def find_permit_number_by_explosives_permit_id(cls, explosives_permit_id):
obj = cls.query.filter_by(
explosives_permit_id=explosives_permit_id, deleted_ind=False).one_or_none()
return obj.permit_number if obj else None
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.schema import Sequence

from app.api.mines.documents.models.mine_document import MineDocument
from app.api.mines.explosives_permit.models.explosives_permit import ExplosivesPermit
from app.api.mines.explosives_permit.models.explosives_permit_document_type import ExplosivesPermitDocumentType

from app.api.mines.explosives_permit_amendment.models.explosives_permit_amendment_document_xref import \
Expand Down Expand Up @@ -84,7 +85,6 @@ def create(cls,
description,
issue_date,
expiry_date,
permit_number,
issuing_inspector_party_guid,
mine_manager_mine_party_appt_id,
permittee_mine_party_appt_id,
Expand All @@ -107,7 +107,6 @@ def create(cls,
application_number = ExplosivesPermitAmendment.get_next_application_number()
received_timestamp = datetime.utcnow()
is_closed = False
permit_number = None
issue_date = None
expiry_date = None
if is_closed:
Expand All @@ -117,6 +116,8 @@ def create(cls,
closed_reason = None
closed_timestamp = None

permit_number = ExplosivesPermit.find_permit_number_by_explosives_permit_id(explosives_permit_id)

explosives_permit_amendment = cls(
permit_guid=permit_guid,
explosives_permit_id=explosives_permit_id,
Expand Down Expand Up @@ -175,6 +176,7 @@ def find_by_explosives_permit_amendment_guid(cls, explosives_permit_amendment_gu
explosives_permit_amendment_guid=explosives_permit_amendment_guid, deleted_ind=False).one_or_none()

def update(self,
explosives_permit_id,
permit_guid,
now_application_guid,
issuing_inspector_party_guid,
Expand Down Expand Up @@ -327,8 +329,8 @@ def create_issued_permit():
)
return ExplosivesPermitAmendmentDocumentResource.generate_explosives_permit_document(
token, True, False, False)
if self.application_status == 'REC' and application_status == 'APP':
self.permit_number = ExplosivesPermitAmendment.get_next_permit_number()

permit_number = ExplosivesPermit.find_permit_number_by_explosives_permit_id(explosives_permit_id)
create_permit_enclosed_letter()
create_issued_permit()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
from app.api.mines.explosives_permit_amendment.models.explosives_permit_amendment import ExplosivesPermitAmendment
class ExplosivesPermitAmendmentResource(Resource, UserMixin):
parser = CustomReqparser()
parser.add_argument(
'explosives_permit_id',
type=str,
store_missing=False,
required=False,
)
parser.add_argument(
'explosives_permit_guid',
type=str,
Expand Down Expand Up @@ -180,6 +186,7 @@ def put(self,mine_guid, explosives_permit_amendment_guid):
data = self.parser.parse_args()

explosives_permit_amendment.update(
data.get('explosives_permit_id'),
data.get('permit_guid'), data.get('now_application_guid'),
data.get('issuing_inspector_party_guid'), data.get('mine_manager_mine_party_appt_id'),
data.get('permittee_mine_party_appt_id'), data.get('application_status'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ class ExplosivesPermitAmendmentListResource(Resource, UserMixin):
store_missing=False,
required=False,
)
parser.add_argument(
'permit_number',
type=str,
store_missing=False,
required=False,
)
parser.add_argument(
'detonator_magazines',
type=list,
Expand Down Expand Up @@ -159,7 +153,6 @@ def post(self, mine_guid):
data.get('latitude'), data.get('longitude'),
data.get('description'), data.get('issue_date'),
data.get('expiry_date'),
data.get('permit_number'),
data.get('issuing_inspector_party_guid'),
data.get('mine_manager_mine_party_appt_id'),
data.get('permittee_mine_party_appt_id'),
Expand Down
1 change: 1 addition & 0 deletions services/core-api/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ class Params:
mine_manager_mine_party_appt_id = factory.SelfAttribute('mine_manager.mine_party_appt_id')
permittee_mine_party_appt_id = factory.SelfAttribute('permittee.mine_party_appt_id')

explosives_permit_id = factory.Faker('random_int', min=1000, max=9999)
originating_system = 'Core'
application_number = factory.Faker('sentence', nb_words=1)
received_timestamp = TODAY
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from tests.factories import ExplosivesPermitAmendmentFactory, create_mine_and_permit, MinePartyAppointmentFactory, \
ExplosivesPermitFactory
import json

def test_post_explosives_permit_amendment_application(test_client, db_session, auth_headers):
mine, permit = create_mine_and_permit()
mine_manager = MinePartyAppointmentFactory(mine=mine)
permittee = MinePartyAppointmentFactory(mine=mine)
explosives_permit = ExplosivesPermitFactory()
data = {
'explosives_permit_id': explosives_permit.explosives_permit_id,
'originating_system':
'Core',
'permit_guid':
str(permit.permit_guid),
'mine_manager_mine_party_appt_id':
mine_manager.mine_party_appt_id,
'permittee_mine_party_appt_id':
permittee.mine_party_appt_id,
'application_date':
'2021-07-12',
'description':
'Other Information.',
'latitude':
'54',
'longitude':
'40',
'explosive_magazines': [{
'type_no': '1',
'tag_no': '1',
'construction': '1',
'quantity': '1',
'latitude': '1',
'longitude': '1',
'distance_road': '1',
'distance_dwelling': '1',
'length': '1',
'width': '1',
'height': '1'
}],
'detonator_magazines': [{
'type_no': '1',
'tag_no': '1',
'construction': '1',
'quantity': '1',
'longitude': '1',
'latitude': '1',
'detonator_type': '1',
'distance_road': '1',
'distance_dwelling': '1',
'width': '1',
'height': '1',
'length': '1'
}]
}

post_resp = test_client.post(
f'/mines/{mine.mine_guid}/explosives-permits-amendment',
json=data,
headers=auth_headers['full_auth_header'])

assert post_resp.status_code == 201
assert len(mine.explosives_permits_amendments) == 1

post_data = json.loads(post_resp.data.decode())
assert post_data['explosives_permit_id'] != None
assert post_data['mine_guid'] == str(mine.mine_guid)
assert post_data['permit_guid'] == data['permit_guid']
assert post_data['application_status'] == 'REC'
assert post_data['application_number'] != None
assert post_data['received_timestamp'] != None
assert post_data['is_closed'] == False
assert post_data['permit_number'] == None
assert post_data['issue_date'] == None
assert post_data['expiry_date'] == None
assert len(post_data['explosive_magazines']) == len(data['explosive_magazines'])
assert len(post_data['detonator_magazines']) == len(data['detonator_magazines'])

0 comments on commit 04794a3

Please sign in to comment.