def test_transfer_credit_without_credit(self): original_credit_balance = 0 CreditLine.add_credit( original_credit_balance, account=self.subscription.account, subscription=self.subscription, ) original_balance = self.invoice.balance adjustment_amount = random.randint(1, 5) adjust_balance_form = AdjustBalanceForm( self.invoice, { 'adjustment_type': 'credit', 'custom_amount': adjustment_amount, 'method': CreditAdjustmentReason.TRANSFER, 'note': 'some text', 'invoice_id': self.invoice.id, } ) self.assertTrue(adjust_balance_form.is_valid()) adjust_balance_form.adjust_balance() self.assertEqual(original_balance, self.invoice.balance) self.assertEqual(original_credit_balance, sum( credit_line.balance for credit_line in CreditLine.get_credits_for_invoice(self.invoice) ))
def test_manual_adjustment(self): original_balance = self.invoice.balance adjustment_amount = random.randint(1, 5) adjust_balance_form = AdjustBalanceForm( self.invoice, { 'adjustment_type': 'credit', 'custom_amount': adjustment_amount, 'method': CreditAdjustmentReason.MANUAL, 'note': 'some text', 'invoice_id': self.invoice.id, }) self.assertTrue(adjust_balance_form.is_valid()) adjust_balance_form.adjust_balance() self.assertEqual(original_balance - adjustment_amount, self.invoice.balance)
def test_manual_adjustment(self): original_balance = self.invoice.balance adjustment_amount = random.randint(1, 5) adjust_balance_form = AdjustBalanceForm( self.invoice, { 'adjustment_type': 'credit', 'custom_amount': adjustment_amount, 'method': CreditAdjustmentReason.MANUAL, 'note': 'some text', 'invoice_id': self.invoice.id, } ) self.assertTrue(adjust_balance_form.is_valid()) adjust_balance_form.adjust_balance() self.assertEqual(original_balance - adjustment_amount, self.invoice.balance)
def adjust_balance_form(self): if self.request.method == 'POST': return AdjustBalanceForm(self.invoice, self.request.POST) return AdjustBalanceForm(self.invoice)
def adjust_balance_form(self): return AdjustBalanceForm( Invoice.objects.get(id=int(self.request.POST.get('invoice_id'))), self.request.POST )
def adjust_balance_forms(self): return [AdjustBalanceForm(invoice) for invoice in self.invoices]