def test_create_pad_invoice_single_transaction_run_again(session): """Assert PAD invoices are created.""" # Create an account and an invoice for the account account = factory_create_pad_account(auth_account_id='1', status=CfsAccountStatus.ACTIVE.value) previous_day = datetime.now() - timedelta(days=1) # Create an invoice for this account invoice = factory_invoice(payment_account=account, created_on=previous_day, total=10, status_code=InvoiceStatus.APPROVED.value, payment_method_code=None) fee_schedule = FeeScheduleModel.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() invoice_response = {'invoice_number': '10021', 'pbc_ref_number': '10005', 'party_number': '11111', 'party_name': 'invoice'} assert invoice.invoice_status_code == InvoiceStatus.APPROVED.value the_response = Response() the_response._content = json.dumps(invoice_response).encode('utf-8') with patch.object(CFSService, 'create_account_invoice', return_value=the_response) as mock_cfs: CreateInvoiceTask.create_invoices() mock_cfs.assert_called() updated_invoice: InvoiceModel = InvoiceModel.find_by_id(invoice.id) inv_ref: InvoiceReferenceModel = InvoiceReferenceModel. \ find_reference_by_invoice_id_and_status(invoice.id, InvoiceReferenceStatus.ACTIVE.value) assert inv_ref assert updated_invoice.invoice_status_code == InvoiceStatus.APPROVED.value with patch.object(CFSService, 'create_account_invoice', return_value=the_response) as mock_cfs: CreateInvoiceTask.create_invoices() mock_cfs.assert_not_called()
def test_create_pad_invoice_multiple_transactions(session): """Assert PAD invoices are created.""" # Create an account and an invoice for the account account = factory_create_pad_account(auth_account_id='1', status=CfsAccountStatus.ACTIVE.value) previous_day = datetime.now() - timedelta(days=1) # Create an invoice for this account invoice = factory_invoice(payment_account=account, created_on=previous_day, total=10, payment_method_code=None) fee_schedule = FeeScheduleModel.find_by_filing_type_and_corp_type( 'CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() # Create another invoice for this account invoice2 = factory_invoice(payment_account=account, created_on=previous_day, total=10, payment_method_code=None) fee_schedule2 = FeeScheduleModel.find_by_filing_type_and_corp_type( 'CP', 'OTADD') line2 = factory_payment_line_item( invoice2.id, fee_schedule_id=fee_schedule2.fee_schedule_id) line2.save() CreateInvoiceTask.create_invoices() invoice2 = InvoiceModel.find_by_id(invoice2.id) invoice = InvoiceModel.find_by_id(invoice.id) assert invoice2.invoice_status_code == invoice.invoice_status_code == InvoiceStatus.SETTLEMENT_SCHEDULED.value
def test_create_pad_invoice_for_frozen_accounts(session): """Assert PAD invoices are created.""" # Create an account and an invoice for the account account = factory_create_pad_account(auth_account_id='1', status=CfsAccountStatus.FREEZE.value) previous_day = datetime.now() - timedelta(days=1) # Create an invoice for this account invoice = factory_invoice(payment_account=account, created_on=previous_day, total=10, payment_method_code=None) fee_schedule = FeeScheduleModel.find_by_filing_type_and_corp_type( 'CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() assert invoice.invoice_status_code == InvoiceStatus.CREATED.value CreateInvoiceTask.create_invoices() updated_invoice: InvoiceModel = InvoiceModel.find_by_id(invoice.id) inv_ref: InvoiceReferenceModel = InvoiceReferenceModel. \ find_reference_by_invoice_id_and_status(invoice.id, InvoiceReferenceStatus.ACTIVE.value) assert inv_ref is None assert updated_invoice.invoice_status_code == InvoiceStatus.CREATED.value
def run(job_name): from tasks.cfs_create_account_task import CreateAccountTask from tasks.cfs_create_invoice_task import CreateInvoiceTask from tasks.distribution_task import DistributionTask from tasks.stale_payment_task import StalePaymentTask from tasks.statement_notification_task import StatementNotificationTask from tasks.statement_task import StatementTask from tasks.activate_pad_account_task import ActivatePadAccountTask from tasks.ejv_partner_distribution_task import EjvPartnerDistributionTask from tasks.unpaid_invoice_notify_task import UnpaidInvoiceNotifyTask from tasks.ejv_payment_task import EjvPaymentTask application = create_app() application.app_context().push() if job_name == 'UPDATE_GL_CODE': DistributionTask.update_failed_distributions() application.logger.info(f'<<<< Completed Updating GL Codes >>>>') elif job_name == 'GENERATE_STATEMENTS': StatementTask.generate_statements() application.logger.info(f'<<<< Completed Generating Statements >>>>') elif job_name == 'SEND_NOTIFICATIONS': StatementNotificationTask.send_notifications() application.logger.info(f'<<<< Completed Sending notifications >>>>') elif job_name == 'UPDATE_STALE_PAYMENTS': StalePaymentTask.update_stale_payments() application.logger.info(f'<<<< Completed Updating stale payments >>>>') elif job_name == 'CREATE_CFS_ACCOUNTS': CreateAccountTask.create_accounts() application.logger.info(f'<<<< Completed creating cfs accounts >>>>') elif job_name == 'CREATE_INVOICES': CreateInvoiceTask.create_invoices() application.logger.info(f'<<<< Completed creating cfs invoices >>>>') elif job_name == 'ACTIVATE_PAD_ACCOUNTS': ActivatePadAccountTask.activate_pad_accounts() application.logger.info(f'<<<< Completed Activating PAD accounts >>>>') elif job_name == 'EJV_PARTNER': EjvPartnerDistributionTask.create_ejv_file() application.logger.info(f'<<<< Completed Creating EJV File for partner distribution>>>>') elif job_name == 'NOTIFY_UNPAID_INVOICE_OB': UnpaidInvoiceNotifyTask.notify_unpaid_invoices() application.logger.info(f'<<<< Completed Sending notification for OB invoices >>>>') elif job_name == 'EJV_PAYMENT': EjvPaymentTask.create_ejv_file() application.logger.info(f'<<<< Completed running EJV payment >>>>') else: application.logger.debug('No valid args passed.Exiting job without running any ***************')
def test_create_rs_invoice_single_transaction(session): """Assert PAD invoices are created.""" # Create an account and an invoice for the account rs_number = '123' account = factory_routing_slip_account(number=rs_number, status=CfsAccountStatus.ACTIVE.value) previous_day = datetime.now() - timedelta(days=1) # Create an invoice for this account invoice = factory_invoice(payment_account=account, created_on=previous_day, total=10, status_code=InvoiceStatus.APPROVED.value, payment_method_code=PaymentMethod.INTERNAL.value, routing_slip=rs_number) fee_schedule = FeeScheduleModel.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() assert invoice.invoice_status_code == InvoiceStatus.APPROVED.value CreateInvoiceTask.create_invoices() updated_invoice: InvoiceModel = InvoiceModel.find_by_id(invoice.id) inv_ref: InvoiceReferenceModel = InvoiceReferenceModel. \ find_reference_by_invoice_id_and_status(invoice.id, InvoiceReferenceStatus.COMPLETED.value) assert inv_ref assert updated_invoice.invoice_status_code == InvoiceStatus.PAID.value
def test_create_invoice(session): """Test create invoice.""" CreateInvoiceTask.create_invoices() assert True