def factory_invoice(payment_account: PaymentAccount, status_code: str = InvoiceStatus.CREATED.value, corp_type_code='CP', business_identifier: str = 'CP0001234', service_fees: float = 0.0, total=0, payment_method_code: str = PaymentMethod.DIRECT_PAY.value, created_on: datetime = datetime.now(), cfs_account_id: int = 0, routing_slip=None): """Return Factory.""" status_code = InvoiceStatus.APPROVED.value if payment_method_code == PaymentMethod.PAD.value else status_code invoice = Invoice(invoice_status_code=status_code, payment_account_id=payment_account.id, total=total, created_by='test', created_on=created_on, business_identifier=business_identifier, corp_type_code=corp_type_code, folio_number='1234567890', service_fees=service_fees, bcol_account=payment_account.bcol_account, payment_method_code=payment_method_code or payment_account.payment_method, routing_slip=routing_slip) if cfs_account_id != 0: invoice.cfs_account_id = cfs_account_id invoice.save() return invoice
def _create_nsf_invoice(cls, cfs_account: CfsAccountModel, rs_number: str, payment_account: PaymentAccountModel) -> InvoiceModel: """Create Invoice, line item and invoice reference records.""" fee_schedule: FeeScheduleModel = FeeScheduleModel.find_by_filing_type_and_corp_type(corp_type_code='BCR', filing_type_code='NSF') invoice = InvoiceModel( bcol_account=payment_account.bcol_account, payment_account_id=payment_account.id, cfs_account_id=cfs_account.id, invoice_status_code=InvoiceStatus.CREATED.value, total=fee_schedule.fee.amount, service_fees=0, paid=0, payment_method_code=PaymentMethod.INTERNAL.value, corp_type_code='BCR', created_on=datetime.now(), created_by='SYSTEM', routing_slip=rs_number ) invoice = invoice.save() distribution: DistributionCodeModel = DistributionCodeModel.find_by_active_for_fee_schedule( fee_schedule.fee_schedule_id) line_item = PaymentLineItemModel( invoice_id=invoice.id, total=invoice.total, fee_schedule_id=fee_schedule.fee_schedule_id, description=fee_schedule.filing_type.description, filing_fees=invoice.total, gst=0, priority_fees=0, pst=0, future_effective_fees=0, line_item_status_code=LineItemStatus.ACTIVE.value, service_fees=0, fee_distribution_id=distribution.distribution_code_id) line_item.save() invoice_response = CFSService.create_account_invoice(transaction_number=invoice.id, line_items=invoice.payment_line_items, cfs_account=cfs_account) invoice_number = invoice_response.json().get('invoice_number', None) current_app.logger.info(f'invoice_number {invoice_number} created in CFS for NSF.') InvoiceReferenceModel( invoice_id=invoice.id, invoice_number=invoice_number, reference_number=invoice_response.json().get('pbc_ref_number', None), status_code=InvoiceReferenceStatus.ACTIVE.value ).save() return invoice
def _create_nsf_invoice(cfs_account: CfsAccountModel, inv_number: str, payment_account: PaymentAccountModel) -> InvoiceModel: """Create Invoice, line item and invoice referwnce records.""" fee_schedule: FeeScheduleModel = FeeScheduleModel.find_by_filing_type_and_corp_type( corp_type_code='BCR', filing_type_code='NSF') invoice = InvoiceModel(bcol_account=payment_account.bcol_account, payment_account_id=payment_account.id, cfs_account_id=cfs_account.id, invoice_status_code=InvoiceStatus.CREATED.value, total=fee_schedule.fee.amount, service_fees=0, paid=0, payment_method_code=PaymentMethod.CC.value, corp_type_code='BCR', created_on=datetime.now(), created_by='SYSTEM') invoice = invoice.save() distribution: DistributionCodeModel = DistributionCodeModel.find_by_active_for_fee_schedule( fee_schedule.fee_schedule_id) line_item = PaymentLineItemModel( invoice_id=invoice.id, total=invoice.total, fee_schedule_id=fee_schedule.fee_schedule_id, description=fee_schedule.filing_type.description, filing_fees=invoice.total, gst=0, priority_fees=0, pst=0, future_effective_fees=0, line_item_status_code=LineItemStatus.ACTIVE.value, service_fees=0, fee_distribution_id=distribution.distribution_code_id if distribution else 1) # TODO line_item.save() inv_ref: InvoiceReferenceModel = InvoiceReferenceModel( invoice_id=invoice.id, invoice_number=inv_number, reference_number=InvoiceReferenceModel. find_any_active_reference_by_invoice_number( invoice_number=inv_number).reference_number, status_code=InvoiceReferenceStatus.ACTIVE.value) inv_ref.save() return invoice