def factory_payment_line_item(invoice_id: str, fee_schedule_id: int, filing_fees: int = 10, total: int = 10): """Factory.""" return PaymentLineItem( invoice_id=invoice_id, fee_schedule_id=fee_schedule_id, filing_fees=filing_fees, total=total, line_item_status_code=Status.CREATED.value, )
def factory_payment_line_item(invoice_id: str, fee_schedule_id: int, filing_fees: int = 10, total: int = 10, status: str = LineItemStatus.ACTIVE.value): """Return Factory.""" return PaymentLineItem( invoice_id=invoice_id, fee_schedule_id=fee_schedule_id, filing_fees=filing_fees, total=total, line_item_status_code=status, )
def factory_payment_line_item(invoice_id: str, fee_schedule_id: int, filing_fees: int = 10, total: int = 10, service_fees: int = 0, status: str = LineItemStatus.ACTIVE.value): """Return Factory.""" return PaymentLineItem( invoice_id=invoice_id, fee_schedule_id=fee_schedule_id, filing_fees=filing_fees, total=total, service_fees=service_fees, line_item_status_code=status, fee_distribution_id=DistributionCode.find_by_active_for_fee_schedule( fee_schedule_id).distribution_code_id)
def create_invoice(self, payment_account: PaymentAccount, # pylint: disable=too-many-locals line_items: [PaymentLineItem], invoice: Invoice, **kwargs) -> InvoiceReference: """Create Invoice in PayBC.""" current_app.logger.debug('<create_invoice') # Build line item model array, as that's needed for CFS Service line_item_models: List[PaymentLineItemModel] = [] for line_item in line_items: line_item_models.append(PaymentLineItemModel.find_by_id(line_item.id)) invoice_response = self.create_account_invoice(invoice.id, line_item_models, payment_account) invoice_reference: InvoiceReference = InvoiceReference.create( invoice.id, invoice_response.json().get('invoice_number', None), invoice_response.json().get('pbc_ref_number', None)) current_app.logger.debug('>create_invoice') return invoice_reference
def _refund_and_create_credit_memo(invoice: InvoiceModel): # Create credit memo in CFS if the invoice status is PAID. # Don't do anything is the status is APPROVED. current_app.logger.info( f'Creating credit memo for invoice : {invoice.id}, {invoice.invoice_status_code}' ) if invoice.invoice_status_code == InvoiceStatus.APPROVED.value \ and InvoiceReferenceModel.find_reference_by_invoice_id_and_status( invoice.id, InvoiceReferenceStatus.ACTIVE.value) is None: return cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id( invoice.payment_account_id) line_items: List[PaymentLineItemModel] = [] for line_item in invoice.payment_line_items: line_items.append(PaymentLineItemModel.find_by_id(line_item.id)) cms_response = CFSService.create_cms(line_items=line_items, cfs_account=cfs_account) # TODO Create a payment record for this to show up on transactions, when the ticket comes. # Create a credit with CM identifier as CMs are not reported in payment interface file # until invoice is applied. CreditModel(cfs_identifier=cms_response.get('credit_memo_number'), is_credit_memo=True, amount=invoice.total, remaining_amount=invoice.total, account_id=invoice.payment_account_id).flush() # Add up the credit amount and update payment account table. payment_account: PaymentAccountModel = PaymentAccountModel.find_by_id( invoice.payment_account_id) payment_account.credit = (payment_account.credit or 0) + invoice.total current_app.logger.info( f'Updating credit amount to {payment_account.credit} for account {payment_account.auth_account_id}' ) payment_account.flush()