Ejemplo n.º 1
0
    def test_invoice_pdf(self):
        """
        Test that the invoice pdf is generated and downloaded.
        """
        project = ProjectFactory.create(flat_fee=3500)
        invoice = InvoiceFactory.create(client=project.client, date=date(2015, 10, 15))
        InvoiceItemFactory.create(
            invoice=invoice, project=project,
            rate=3500, amount=1,
            source_object=project
        )

        project.client.contacts.add(ContactFactory(user=self.user))

        self.assertFalse(invoice.invoice_number)
        invoice.generate()

        url = reverse('invoices:detail-pdf', kwargs={'invoice_number': invoice.invoice_number})
        response = self.app.get(url)
        expected = '{}?next={}'.format(settings.LOGIN_URL, url)
        self.assertRedirects(response, expected, fetch_redirect_response=False)

        response = self.app.get(url, user=self.user)
        invoice.refresh_from_db()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content_type, 'application/pdf')
        self.assertGreater(response.content_length, 0)
        self.assertEqual(response.content_length, invoice.pdf.size)
        self.assertEqual(response.content, invoice.pdf.read())
Ejemplo n.º 2
0
    def test_generate_invoice_flat_fee(self):
        project = ProjectFactory.create(flat_fee=3500)
        invoice = InvoiceFactory.create(client=project.client, date=date(2015, 10, 15))
        InvoiceItemFactory.create(
            invoice=invoice, project=project,
            rate=3500, amount=1,
            source_object=project
        )

        self.assertFalse(invoice.invoice_number)
        invoice.generate()
        self.assertEqual(invoice.invoice_number, '201500001')
        self.assertEqual(invoice.get_totals(), {
            'base__sum': Decimal(3500),
            'tax__sum': Decimal('735')
        })
Ejemplo n.º 3
0
    def test_generate_invoice_flat_fee(self):
        project = ProjectFactory.create(flat_fee=3500)
        invoice = InvoiceFactory.create(client=project.client,
                                        date=date(2015, 10, 15))
        InvoiceItemFactory.create(invoice=invoice,
                                  project=project,
                                  rate=3500,
                                  amount=1,
                                  source_object=project)

        self.assertFalse(invoice.invoice_number)
        invoice.generate()
        self.assertEqual(invoice.invoice_number, '201500001')
        self.assertEqual(invoice.get_totals(), {
            'base__sum': Decimal(3500),
            'tax__sum': Decimal('735')
        })
Ejemplo n.º 4
0
    def test_render_pdf(self):
        project = ProjectFactory.create(flat_fee=3500)
        invoice = InvoiceFactory.create(client=project.client, date=date(2015, 10, 15))
        InvoiceItemFactory.create(
            invoice=invoice, project=project,
            rate=3500, amount=1,
            source_object=project
        )

        self.assertFalse(invoice.invoice_number)
        invoice.generate()

        request = RequestFactory().get('/')
        render_invoice_pdf(request, invoice)

        self.assertEqual(invoice.pdf.name, 'invoices/2015/10/201500001.pdf')
        self.assertTrue(os.path.exists(invoice.pdf.path))
Ejemplo n.º 5
0
    def test_render_pdf(self):
        project = ProjectFactory.create(flat_fee=3500)
        invoice = InvoiceFactory.create(client=project.client,
                                        date=date(2015, 10, 15))
        InvoiceItemFactory.create(invoice=invoice,
                                  project=project,
                                  rate=3500,
                                  amount=1,
                                  source_object=project)

        self.assertFalse(invoice.invoice_number)
        invoice.generate()

        request = RequestFactory().get('/')
        render_invoice_pdf(request, invoice)

        self.assertEqual(invoice.pdf.name, 'invoices/2015/10/201500001.pdf')
        self.assertTrue(os.path.exists(invoice.pdf.path))
Ejemplo n.º 6
0
    def test_pickup_work_entries(self):
        """
        Test that the work entries are correctly picked up for a given invoice date.
        """
        client1, client2 = ClientFactory.create_batch(2)
        project1, project2 = ProjectFactory.create_batch(2, client=client1)
        project3 = ProjectFactory.create(client=client2)

        # worked a bit on project 1
        WorkEntryFactory.create(
            project=project1,
            start=datetime(2015, 9, 14, 8, 0).replace(tzinfo=timezone.utc),
            end=datetime(2015, 9, 14, 12, 0).replace(tzinfo=timezone.utc)
        )

        # worked a bit on project 2
        WorkEntryFactory.create(
            project=project2,
            start=datetime(2015, 9, 14, 13, 0).replace(tzinfo=timezone.utc),
            end=datetime(2015, 9, 14, 15, 30).replace(tzinfo=timezone.utc)
        )
        WorkEntryFactory.create(
            project=project2,
            start=datetime(2015, 9, 30, 13, 0).replace(tzinfo=timezone.utc),
            end=datetime(2015, 9, 30, 15, 30).replace(tzinfo=timezone.utc)
        )

        # future entry to be ignored
        WorkEntryFactory.create(
            project=project1,
            start=datetime(2015, 10, 1, 8, 0).replace(tzinfo=timezone.utc),
            end=datetime(2015, 10, 1, 11, 0).replace(tzinfo=timezone.utc)
        )

        # different client
        WorkEntryFactory.create(
            project=project3,
            start=datetime(2015, 9, 21, 8, 0).replace(tzinfo=timezone.utc),
            end=datetime(2015, 9, 21, 11, 0).replace(tzinfo=timezone.utc)
        )

        # create the invoices
        invoice1 = InvoiceFactory.create(client=client1, date=date(2015, 9, 30))
        invoice2 = InvoiceFactory.create(client=client1, date=date(2015, 10, 31))

        # generate the invoices and check that the correct number of lines are created
        invoice1.generate()
        self.assertIsNotNone(invoice1.generated)
        self.assertEqual(invoice1.invoice_number, '201500001')
        self.assertEqual(InvoiceItem.objects.count(), 3)

        # check the financial data
        for item in InvoiceItem.objects.all():
            self.assertEqual(item.rate, item.project.base_rate)

        expected_vat_free_total = project1.base_rate * 4 + project2.base_rate * 5
        self.assertEqual(invoice1.total_no_vat, expected_vat_free_total)
        self.assertEqual(invoice1.total_with_vat, expected_vat_free_total * Decimal('1.21'))

        invoice2.generate()
        self.assertEqual(InvoiceItem.objects.count(), 4)
Ejemplo n.º 7
0
    def test_pickup_work_entries(self):
        """
        Test that the work entries are correctly picked up for a given invoice date.
        """
        client1, client2 = ClientFactory.create_batch(2)
        project1, project2 = ProjectFactory.create_batch(2, client=client1)
        project3 = ProjectFactory.create(client=client2)

        # worked a bit on project 1
        WorkEntryFactory.create(project=project1,
                                start=datetime(2015, 9, 14, 8,
                                               0).replace(tzinfo=timezone.utc),
                                end=datetime(2015, 9, 14, 12,
                                             0).replace(tzinfo=timezone.utc))

        # worked a bit on project 2
        WorkEntryFactory.create(project=project2,
                                start=datetime(2015, 9, 14, 13,
                                               0).replace(tzinfo=timezone.utc),
                                end=datetime(2015, 9, 14, 15,
                                             30).replace(tzinfo=timezone.utc))
        WorkEntryFactory.create(project=project2,
                                start=datetime(2015, 9, 30, 13,
                                               0).replace(tzinfo=timezone.utc),
                                end=datetime(2015, 9, 30, 15,
                                             30).replace(tzinfo=timezone.utc))

        # future entry to be ignored
        WorkEntryFactory.create(project=project1,
                                start=datetime(2015, 10, 1, 8,
                                               0).replace(tzinfo=timezone.utc),
                                end=datetime(2015, 10, 1, 11,
                                             0).replace(tzinfo=timezone.utc))

        # different client
        WorkEntryFactory.create(project=project3,
                                start=datetime(2015, 9, 21, 8,
                                               0).replace(tzinfo=timezone.utc),
                                end=datetime(2015, 9, 21, 11,
                                             0).replace(tzinfo=timezone.utc))

        # create the invoices
        invoice1 = InvoiceFactory.create(client=client1,
                                         date=date(2015, 9, 30))
        invoice2 = InvoiceFactory.create(client=client1,
                                         date=date(2015, 10, 31))

        # generate the invoices and check that the correct number of lines are created
        invoice1.generate()
        self.assertIsNotNone(invoice1.generated)
        self.assertEqual(invoice1.invoice_number, '201500001')
        self.assertEqual(InvoiceItem.objects.count(), 3)

        # check the financial data
        for item in InvoiceItem.objects.all():
            self.assertEqual(item.rate, item.project.base_rate)

        expected_vat_free_total = project1.base_rate * 4 + project2.base_rate * 5
        self.assertEqual(invoice1.total_no_vat, expected_vat_free_total)
        self.assertEqual(invoice1.total_with_vat,
                         expected_vat_free_total * Decimal('1.21'))

        invoice2.generate()
        self.assertEqual(InvoiceItem.objects.count(), 4)