diff --git a/jobs/payment-jobs/tasks/ejv_partner_distribution_task.py b/jobs/payment-jobs/tasks/ejv_partner_distribution_task.py index 045add26a..fd478f4b2 100644 --- a/jobs/payment-jobs/tasks/ejv_partner_distribution_task.py +++ b/jobs/payment-jobs/tasks/ejv_partner_distribution_task.py @@ -192,14 +192,17 @@ def _create_ejv_file_for_partner(cls, batch_type: str): # pylint:disable=too-ma control_total += 1 + sequence = 1 # Create ejv invoice link records and set invoice status for inv in invoices: # Create Ejv file link and flush link_model = EjvInvoiceLinkModel(invoice_id=inv.id, ejv_header_id=ejv_header_model.id, - disbursement_status_code=DisbursementStatus.UPLOADED.value) + disbursement_status_code=DisbursementStatus.UPLOADED.value, + sequence=sequence) # Set distribution status to invoice db.session.add(link_model) + sequence += 1 inv.disbursement_status_code = DisbursementStatus.UPLOADED.value db.session.flush() diff --git a/jobs/payment-jobs/tasks/ejv_payment_task.py b/jobs/payment-jobs/tasks/ejv_payment_task.py index 52450ea68..55c15f716 100644 --- a/jobs/payment-jobs/tasks/ejv_payment_task.py +++ b/jobs/payment-jobs/tasks/ejv_payment_task.py @@ -177,12 +177,15 @@ def _create_ejv_file_for_gov_account(cls, batch_type: str): # pylint:disable=to # Create ejv invoice link records and set invoice status current_app.logger.info('Creating ejv invoice link records and setting invoice status.') + sequence = 1 for inv in invoices: current_app.logger.debug(f'Creating EJV Invoice Link for invoice id: {inv.id}') # Create Ejv file link and flush ejv_invoice_link = EjvInvoiceLinkModel(invoice_id=inv.id, ejv_header_id=ejv_header_model.id, - disbursement_status_code=DisbursementStatus.UPLOADED.value) + disbursement_status_code=DisbursementStatus.UPLOADED.value, + sequence=sequence) db.session.add(ejv_invoice_link) + sequence += 1 # Set distribution status to invoice # Create invoice reference record current_app.logger.debug(f'Creating Invoice Reference for invoice id: {inv.id}') diff --git a/pay-api/migrations/versions/2023_11_30_49eaec3210e0_.py b/pay-api/migrations/versions/2023_11_30_49eaec3210e0_.py new file mode 100644 index 000000000..a642a5785 --- /dev/null +++ b/pay-api/migrations/versions/2023_11_30_49eaec3210e0_.py @@ -0,0 +1,23 @@ +"""Add in a sequence column to the ejv_invoice_links table + +Revision ID: 49eaec3210e0 +Revises: 598bbfce4dad +Create Date: 2023-11-30 10:38:00.644319 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '49eaec3210e0' +down_revision = '598bbfce4dad' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('ejv_invoice_links', sa.Column('sequence', sa.Integer(), nullable=True)) + + +def downgrade(): + op.drop_column('ejv_invoice_links', 'sequence') diff --git a/pay-api/src/pay_api/models/ejv_invoice_link.py b/pay-api/src/pay_api/models/ejv_invoice_link.py index 47e7606a2..ba7d10471 100644 --- a/pay-api/src/pay_api/models/ejv_invoice_link.py +++ b/pay-api/src/pay_api/models/ejv_invoice_link.py @@ -39,7 +39,8 @@ class EjvInvoiceLink(BaseModel): # pylint: disable=too-few-public-methods 'disbursement_status_code', 'ejv_header_id', 'invoice_id', - 'message' + 'message', + 'sequence' ] } @@ -48,3 +49,4 @@ class EjvInvoiceLink(BaseModel): # pylint: disable=too-few-public-methods ejv_header_id = db.Column(db.Integer, ForeignKey('ejv_headers.id'), nullable=False) disbursement_status_code = db.Column(db.String(20), ForeignKey('disbursement_status_codes.code'), nullable=True) message = db.Column('message', db.String, nullable=True, index=False) + sequence = db.Column(db.Integer, nullable=True)