def test_invoice_create_pdf_not_draft(self):
     """Cannot create a PDF if the invoice has already been printed"""
     InvoiceSettingsFactory()
     VatSettingsFactory()
     invoice = InvoiceFactory()
     InvoiceLineFactory(invoice=invoice)
     InvoicePrint().create_pdf(invoice, None)
     self.assertRaises(InvoiceError,
                       InvoicePrint().create_pdf, invoice, None)
def test_remove_time_lines_not_extra():
    """Remove all but one line.

    The extra line is not removed because it isn't linked to a time record.

    .. important:: This test will fail if you try to run it around midnight.
                   The end time will be something like ``time(0, 45)`` and
                   the start time will be something like ``time(23, 45)``.
                   Both are for the same date, and the end date will look as if
                   it is before the start date!

    """
    InvoiceSettingsFactory()
    VatSettingsFactory()
    tr = TimeRecordFactory()
    InvoiceContactFactory(contact=tr.ticket.contact)
    TimeRecordFactory(ticket=tr.ticket)
    invoice = InvoiceCreate().create(
        tr.user,
        tr.ticket.contact,
        date.today()
    )
    extra_line = InvoiceLineFactory(invoice=invoice)
    assert invoice.is_draft is True
    InvoicePrint().create_pdf(invoice, None)
    assert invoice.has_lines is True
    invoice.set_to_draft()
    invoice.remove_time_lines()
    assert [extra_line.pk] == [i.pk for i in invoice.invoiceline_set.all()]
 def test_invoice_create_pdf(self):
     InvoiceSettingsFactory()
     VatSettingsFactory()
     contact = ContactFactory()
     InvoiceContactFactory(contact=contact)
     ticket = TicketFactory(contact=contact)
     TimeRecordFactory(ticket=ticket, date_started=date(2013, 12, 1))
     invoice = InvoiceCreate().create(UserFactory(), contact,
                                      date(2013, 12, 31))
     InvoicePrint().create_pdf(invoice, None)
def test_user_can_edit_invoice():
    InvoiceSettingsFactory()
    VatSettingsFactory()
    invoice = InvoiceFactory()
    line = InvoiceLineFactory(invoice=invoice)
    TimeRecordFactory(invoice_line=line)
    InvoicePrint().create_pdf(invoice, None)
    # refresh
    line = InvoiceLine.objects.get(pk=line.pk)
    assert line.user_can_edit is False
def test_is_not_draft():
    InvoiceSettingsFactory()
    VatSettingsFactory()
    tr = TimeRecordFactory()
    InvoiceContactFactory(contact=tr.ticket.contact)
    invoice = InvoiceCreate().create(
        tr.user, tr.ticket.contact, date.today()
    )
    assert invoice.is_draft is True
    InvoicePrint().create_pdf(invoice, None)
    assert invoice.is_draft is False
 def test_print_not_negative_and_positive(self):
     credit = self._credit_note()
     InvoiceLineFactory(
         invoice=credit,
         price=Decimal('2.02'),
         quantity=Decimal('1'),
     )
     self.assertRaises(
         InvoiceError,
         InvoicePrint().create_pdf,
         credit,
         None,
     )
def test_refresh_draft_only():
    """Only draft invoices can be refreshed."""
    InvoiceSettingsFactory()
    VatSettingsFactory()
    tr = TimeRecordFactory()
    InvoiceContactFactory(contact=tr.ticket.contact)
    invoice = InvoiceCreate().create(
        tr.user, tr.ticket.contact, date.today()
    )
    assert 1 == invoice.invoiceline_set.count()
    InvoicePrint().create_pdf(invoice, None)
    with pytest.raises(InvoiceError) as e:
        InvoiceCreate().refresh(tr.user, invoice, date.today())
    assert 'Time records can only be added to a draft invoice' in str(e.value)
示例#8
0
def test_invoice_download(perm_check):
    InvoiceSettingsFactory()
    VatSettingsFactory()
    contact = ContactFactory()
    InvoiceContactFactory(contact=contact)
    ticket = TicketFactory(contact=contact)
    TimeRecordFactory(ticket=ticket, date_started=date(2013, 12, 1))
    invoice = InvoiceCreate().create(
        UserFactory(),
        contact,
        date(2013, 12, 31)
    )
    InvoicePrint().create_pdf(invoice, header_image=None)
    url = reverse('invoice.download', kwargs={'pk': invoice.pk})
    perm_check.staff(url)
def test_remove_time_lines():
    """Remove all lines (because they are all linked to time records)."""
    InvoiceSettingsFactory()
    VatSettingsFactory()
    tr = TimeRecordFactory()
    InvoiceContactFactory(contact=tr.ticket.contact)
    TimeRecordFactory(ticket=tr.ticket)
    invoice = InvoiceCreate().create(
        tr.user, tr.ticket.contact, date.today()
    )
    assert invoice.is_draft is True
    InvoicePrint().create_pdf(invoice, None)
    assert invoice.has_lines is True
    invoice.set_to_draft()
    invoice.remove_time_lines()
    assert invoice.has_lines is False
def test_invoice_with_time_records():
    """Invoice time records."""
    InvoiceSettingsFactory()
    VatSettingsFactory()
    contact = ContactFactory()
    InvoiceContactFactory(contact=contact)
    ticket = TicketFactory(contact=contact)
    tr1 = TimeRecordFactory(ticket=ticket)
    TimeRecordFactory(ticket=ticket)
    invoice = InvoiceCreate().create(
        tr1.user, contact, date.today()
    )
    assert invoice.is_draft
    InvoicePrint().create_pdf(invoice, None)
    assert not invoice.is_draft
    assert Decimal('40.00') == invoice.net
def test_set_is_draft_too_late():
    """invoice can only be set back to draft on the day it is created."""
    InvoiceSettingsFactory()
    VatSettingsFactory()
    tr = TimeRecordFactory()
    InvoiceContactFactory(contact=tr.ticket.contact)
    TimeRecordFactory(ticket=tr.ticket)
    invoice = InvoiceCreate().create(
        tr.user, tr.ticket.contact, date.today()
    )
    invoice.invoice_date=date.today() + relativedelta(days=-1)
    invoice.save()
    assert invoice.is_draft is True
    InvoicePrint().create_pdf(invoice, None)
    assert invoice.is_draft is False
    with pytest.raises(InvoiceError) as e:
        invoice.set_to_draft()
    assert 'only set an invoice back to draft on the day' in str(e.value)
 def test_invoice_create_pdf_no_lines(self):
     """Cannot create a PDF if the invoice has no lines"""
     invoice = InvoiceFactory()
     self.assertRaises(InvoiceError,
                       InvoicePrint().create_pdf, invoice, None)
 def test_print_only_negative(self):
     credit = self._credit_note()
     InvoicePrint().create_pdf(credit, None)