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_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