Skip to content

Commit

Permalink
fix bug where esup magazine data not showing in preview certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
asinn134 committed Dec 13, 2024
1 parent 0be6a12 commit 106d4ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
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)
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

0 comments on commit 106d4ed

Please sign in to comment.