Exemplo n.º 1
0
    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)
        ))
Exemplo n.º 2
0
    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)
        ))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 def adjust_balance_form(self):
     if self.request.method == 'POST':
         return AdjustBalanceForm(self.invoice, self.request.POST)
     return AdjustBalanceForm(self.invoice)
Exemplo n.º 6
0
 def adjust_balance_form(self):
     return AdjustBalanceForm(
         Invoice.objects.get(id=int(self.request.POST.get('invoice_id'))),
         self.request.POST
     )
Exemplo n.º 7
0
 def adjust_balance_forms(self):
     return [AdjustBalanceForm(invoice) for invoice in self.invoices]