diff --git a/python/form_handler/actions.py b/python/form_handler/actions.py index 5e341f488..fee60b310 100644 --- a/python/form_handler/actions.py +++ b/python/form_handler/actions.py @@ -12,7 +12,7 @@ from datetime import datetime from minio import Minio from minio.error import S3Error -from python.form_handler.models import Event,FormStorageRefs,VIForm,TwentyFourHourForm,TwelveHourForm,IRPForm,User,AgencyCrossref,CityCrossRef,JurisdictionCrossRef,ImpoundReasonCodes +from python.form_handler.models import Event,FormStorageRefs,VIForm,TwentyFourHourForm,TwelveHourForm,IRPForm,User,AgencyCrossref,CityCrossRef,JurisdictionCrossRef,ImpoundReasonCodes,IloIdCrossRef,ImpoundLotOperator from python.form_handler.icbc_service import submit_to_icbc from python.form_handler.vips_service import create_vips_doc,create_vips_imp from python.form_handler.payloads import vips_payload,vips_document_payload @@ -607,7 +607,35 @@ def prep_vips_payload(**args)->tuple: if "driver_jurisdiction" in event_data: tmp_payload["vipsImpoundCreate"]["dlJurisdictionCd"]=event_data["driver_jurisdiction"] if "driver_licence_no" in event_data: tmp_payload["vipsImpoundCreate"]["driverLicenceNo"]=event_data["driver_licence_no"] - tmp_payload["vipsImpoundCreate"]["impoundLotOperatorId"]=None + + # get ilo id from db + tmp_ilo_id=None + ilo_id_from_db=event_data.get("impound_lot_operator",None) + if ilo_id_from_db: + with application.app_context(): + ilo_data_db = db.session.query(ImpoundLotOperator) \ + .filter(ImpoundLotOperator.id == ilo_id_from_db) \ + .all() + if len(ilo_data_db) == 0: + logging.error("ilo db data not found") + else: + for i in ilo_data_db: + ilo_dict = i.__dict__ + ilo_dict.pop('_sa_instance_state', None) + tmp_ilo_name=ilo_dict["name"] + ilo_cross_ref = db.session.query(IloIdCrossRef) \ + .filter(IloIdCrossRef.ilo_name == tmp_ilo_name) \ + .all() + if len(ilo_cross_ref) == 0: + logging.error("ilo cross ref data not found") + else: + for c in ilo_cross_ref: + ilo_cross_ref_dict = c.__dict__ + ilo_cross_ref_dict.pop('_sa_instance_state', None) + tmp_ilo_id=ilo_cross_ref_dict["vips_impound_lot_operator_id"] + break + break + tmp_payload["vipsImpoundCreate"]["impoundLotOperatorId"]=tmp_ilo_id # convert impoundment_dt to string impoundment_dt=form_data.get("date_of_impound") @@ -626,7 +654,7 @@ def prep_vips_payload(**args)->tuple: tmp_payload["vipsImpoundCreate"]["noticeSubjectCd"]="VEHI" # get reason codes from DB - # TODO: Check the reason list + # DONE: Check the reason list reason_list=[] payload_reason_list=[] excessive_speeding=form_data.get("excessive_speed",False) @@ -657,8 +685,6 @@ def prep_vips_payload(**args)->tuple: reason_list.append("BACWARN3") with application.app_context(): # get reason data - policeDetatchmentId='' - agency_name='' for v in reason_list: reason_data = db.session.query(ImpoundReasonCodes) \ .filter(ImpoundReasonCodes.df_unique_code == v) \ diff --git a/python/form_handler/models.py b/python/form_handler/models.py index 542d0862e..78e8f7aa8 100644 --- a/python/form_handler/models.py +++ b/python/form_handler/models.py @@ -744,5 +744,15 @@ class ImpoundReasonCodes(db.Model): vips_value_cd = db.Column(db.String) vips_value_dsc = db.Column(db.String) vips_value_abbreviated_dsc = db.Column(db.String) + +@dataclass +class IloIdCrossRef(db.Model): + __tablename__ = 'ilo_cross_ref' + + ilo_name: str + vips_impound_lot_operator_id: int + + ilo_name = db.Column(db.String, primary_key=True) + vips_impound_lot_operator_id = db.Column(db.Integer) diff --git a/python/prohibition_web_svc/migrations/versions/237614f969cf_.py b/python/prohibition_web_svc/migrations/versions/237614f969cf_.py new file mode 100644 index 000000000..53b3504c2 --- /dev/null +++ b/python/prohibition_web_svc/migrations/versions/237614f969cf_.py @@ -0,0 +1,32 @@ +"""empty message + +Revision ID: 237614f969cf +Revises: b4b054d65515 +Create Date: 2023-12-02 14:47:40.537260 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '237614f969cf' +down_revision = 'b4b054d65515' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('ilo_cross_ref', + sa.Column('ilo_name', sa.String(), nullable=False), + sa.Column('vips_impound_lot_operator_id', sa.Integer(), nullable=True), + sa.PrimaryKeyConstraint('ilo_name') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('ilo_cross_ref') + # ### end Alembic commands ### diff --git a/python/prohibition_web_svc/models.py b/python/prohibition_web_svc/models.py index 542d0862e..78e8f7aa8 100644 --- a/python/prohibition_web_svc/models.py +++ b/python/prohibition_web_svc/models.py @@ -744,5 +744,15 @@ class ImpoundReasonCodes(db.Model): vips_value_cd = db.Column(db.String) vips_value_dsc = db.Column(db.String) vips_value_abbreviated_dsc = db.Column(db.String) + +@dataclass +class IloIdCrossRef(db.Model): + __tablename__ = 'ilo_cross_ref' + + ilo_name: str + vips_impound_lot_operator_id: int + + ilo_name = db.Column(db.String, primary_key=True) + vips_impound_lot_operator_id = db.Column(db.Integer) diff --git a/python/task_scheduler/models.py b/python/task_scheduler/models.py index 542d0862e..78e8f7aa8 100644 --- a/python/task_scheduler/models.py +++ b/python/task_scheduler/models.py @@ -744,5 +744,15 @@ class ImpoundReasonCodes(db.Model): vips_value_cd = db.Column(db.String) vips_value_dsc = db.Column(db.String) vips_value_abbreviated_dsc = db.Column(db.String) + +@dataclass +class IloIdCrossRef(db.Model): + __tablename__ = 'ilo_cross_ref' + + ilo_name: str + vips_impound_lot_operator_id: int + + ilo_name = db.Column(db.String, primary_key=True) + vips_impound_lot_operator_id = db.Column(db.Integer)