def test_it_should_handle_multicurrency_univoiced_charges(self):
        Charge.objects.create(account=self.account,
                              amount=Money(10, 'CHF'),
                              product_code='10CHF')
        Charge.objects.create(account=self.account,
                              amount=Money(30, 'EUR'),
                              product_code='30EURO')

        invoices = accounts.create_invoices(account_id=self.account.pk,
                                            due_date=date.today())

        assert len(invoices) == 2

        # For some reason the output is always sorted. This makes asserting easy
        invoice1 = invoices[0]
        items1 = invoice1.items.all()
        assert len(items1) == 1
        assert items1[0].product_code == '10CHF'
        assert invoice1.due().currencies() == ['CHF']

        invoice2 = invoices[1]
        items2 = invoice2.items.all()
        assert len(items2) == 1
        assert items2[0].product_code == '30EURO'
        assert invoice2.due().currencies() == ['EUR']

        # Verify there is nothing left to invoice on this account
        assert not accounts.create_invoices(account_id=self.account.pk,
                                            due_date=date.today())
    def test_it_should_send_a_signal_when_an_invoice_was_created(self):
        Charge.objects.create(account=self.account,
                              amount=Money(10, 'CHF'),
                              product_code='ACHARGE')

        with catch_signal(invoice_ready) as signal_handler:
            accounts.create_invoices(account_id=self.account.pk,
                                     due_date=date.today())

        assert signal_handler.call_count == 1
예제 #3
0
 def test_mark_account_as_delinquent_when_pending_invoices_greater_than_0(
         self):
     Charge.objects.create(account=self.account,
                           amount=Money(10, 'CHF'),
                           product_code='10CHF')
     accounts.create_invoices(account_id=self.account.pk,
                              due_date=date.today())
     new_delinquent_account_ids, _ = (
         accounts.get_accounts_which_delinquent_status_has_to_change(
             [self.account.id]))
     assert self.account.id in new_delinquent_account_ids
    def test_it_should_create_an_invoice_when_money_is_due(self):
        Charge.objects.create(account=self.account,
                              amount=Money(10, 'CHF'),
                              product_code='ACHARGE')
        Charge.objects.create(account=self.account,
                              amount=Money(-3, 'CHF'),
                              product_code='ACREDIT')

        invoices = accounts.create_invoices(account_id=self.account.pk,
                                            due_date=date.today())
        assert len(invoices) == 1
        invoice = invoices[0]
        assert invoice.total_charges() == Total(10, 'CHF')
        assert invoice.due() == Total(10, 'CHF')
        assert invoice.items.count() == 1

        # Verify there is nothing left to invoice on this account
        assert not accounts.create_invoices(account_id=self.account.pk,
                                            due_date=date.today())
 def test_it_should_not_create_invoice_no_charges_are_due(self):
     invoice = Invoice.objects.create(account=self.account,
                                      due_date=date.today())
     Charge.objects.create(account=self.account,
                           amount=Money(10, 'CHF'),
                           product_code='DELETED',
                           deleted=True)
     Charge.objects.create(account=self.account,
                           amount=Money(30, 'CHF'),
                           product_code='INVOICED',
                           invoice=invoice)
     assert not accounts.create_invoices(account_id=self.account.pk,
                                         due_date=date.today())
예제 #6
0
 def test_dont_mark_account_as_delinquent_when_account_has_a_positive_balance(
         self):
     Charge.objects.create(account=self.account,
                           amount=Money(10, 'CHF'),
                           product_code='10CHF')
     invoice = accounts.create_invoices(account_id=self.account.pk,
                                        due_date=date.today())[0]
     invoice.status = Invoice.PAID
     invoice.save()
     new_delinquent_account_ids, _ = (
         accounts.get_accounts_which_delinquent_status_has_to_change(
             [self.account.id]))
     assert not new_delinquent_account_ids
 def test_it_should_create_an_invoice_even_when_enough_credit(self):
     Charge.objects.create(account=self.account,
                           amount=Money(10, 'CHF'),
                           product_code='ACHARGE')
     Charge.objects.create(account=self.account,
                           amount=Money(-30, 'CHF'),
                           product_code='ACREDIT')
     invoices = accounts.create_invoices(account_id=self.account.pk,
                                         due_date=date.today())
     assert len(invoices) == 1
     invoice = invoices[0]
     assert invoice.total_charges() == Total(10, 'CHF')
     assert invoice.due() == Total(10, 'CHF')
     assert invoice.items.count() == 1