Skip to content
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

[MDS-6285] ESUP amendments detonator magazine missing #3348

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.api.utils.models_mixins import AuditMixin, Base
from app.extensions import db
from app.api.mines.exceptions.mine_exceptions import MineException
from app.api.mines.explosives_permit_amendment.models.explosives_permit_amendment_magazine import ExplosivesPermitAmendmentMagazine

PERMIT_SIGNATURE_IMAGE_HEIGHT_INCHES = 0.8
LETTER_SIGNATURE_IMAGE_HEIGHT_INCHES = 0.8
Expand Down Expand Up @@ -40,7 +41,7 @@ def get_with_context(cls, document_type_code, context_guid):

return document_type

def transform_template_data(self, template_data, explosives_permit):
def transform_template_data(self, template_data, explosives_permit, explosives_permit_amendment_id=None):
def validate_issuing_inspector(explosives_permit):
if not explosives_permit.issuing_inspector:
raise MineException("No Issuing Inspector has been assigned",
Expand Down Expand Up @@ -172,9 +173,16 @@ def is_explosive_type(mag):
}
transformed_magazines.append(transformed_magazine)
return transformed_magazines

explosive_magazines = transform_magazines(explosives_permit.explosive_magazines or [])
detonator_magazines = transform_magazines(explosives_permit.detonator_magazines or [])
untransformed_explosive_magazines = explosives_permit.explosive_magazines
untransformed_detonator_magazines = explosives_permit.detonator_magazines

explosives_permit_amendment_magazines = ExplosivesPermitAmendmentMagazine.find_by_explosives_permit_amendment_id(explosives_permit_amendment_id)
if explosives_permit_amendment_id and len(explosives_permit_amendment_magazines) > 0:
untransformed_explosive_magazines = list(filter(lambda mag: mag.explosives_permit_amendment_magazine_type_code == "EXP", explosives_permit_amendment_magazines))
untransformed_detonator_magazines = list(filter(lambda mag: mag.explosives_permit_amendment_magazine_type_code == "DET", explosives_permit_amendment_magazines))

explosive_magazines = transform_magazines(untransformed_explosive_magazines or [])
detonator_magazines = transform_magazines(untransformed_detonator_magazines or [])
magazines = explosive_magazines + detonator_magazines
template_data['magazines'] = magazines

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get(self, document_type_code):
class ExplosivesPermitDocumentGenerateResource(Resource, UserMixin):
parser = CustomReqparser()
parser.add_argument('explosives_permit_guid', type=str, location='json', required=True)
parser.add_argument('explosives_permit_amendment_id', type=str, location='json', required=False)
parser.add_argument('template_data', type=dict, location='json', required=True)

@api.doc(
Expand All @@ -70,12 +71,13 @@ def post(self, document_type_code):

explosives_permit_guid = data['explosives_permit_guid']
explosives_permit = ExplosivesPermit.find_by_explosives_permit_guid(explosives_permit_guid)
explosives_permit_amendment_id = data.get('explosives_permit_amendment_id', None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to perform a check here to make sure the explosives_permit_amendment_id is actually for this explosives_permit. Just a precaution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A check for this has been added now.

if not explosives_permit:
raise MineException("Explosives Permit not found",
status_code = 404)

template_data = data['template_data']
template_data = document_type.transform_template_data(template_data, explosives_permit)
template_data = document_type.transform_template_data(template_data, explosives_permit, explosives_permit_amendment_id)

form_spec_with_context = document_template._form_spec_with_context(explosives_permit_guid)
enforced_data = [x for x in form_spec_with_context if x.get('read-only') == True]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ def create(cls,
def find_by_explosives_permit_amendment_magazine_id(cls, explosives_permit_amendment_magazine_id):
return cls.query.filter_by(
explosives_permit_amendment_magazine_id=explosives_permit_amendment_magazine_id,
deleted_ind=False).one_or_none()
deleted_ind=False).one_or_none()

@classmethod
def find_by_explosives_permit_amendment_id(cls, explosives_permit_amendment_id):
return cls.query.filter_by(
explosives_permit_amendment_id=explosives_permit_amendment_id,
deleted_ind=False).order_by(cls.explosives_permit_amendment_magazine_id.asc()).all()
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const ExplosivesPermit: FC<ExplosivesPermitProps> = ({
if (record.isAmendment) values.amendment_no = record.amendment_no;
const payload = {
explosives_permit_guid: record.explosives_permit_guid,
...(record.explosives_permit_amendment_id && { explosives_permit_amendment_id: record.explosives_permit_amendment_id }),
template_data: values,
};
return props.generateExplosivesPermitDocument(
Expand Down
Loading