def test_get_next_line_number_fill_gap():
    """get the number for the next invoice line"""
    invoice = InvoiceFactory()
    InvoiceLineFactory(invoice=invoice, line_number=1)
    InvoiceLineFactory(invoice=invoice, line_number=2)
    InvoiceLineFactory(invoice=invoice, line_number=4)
    assert 3 == invoice.get_next_line_number()
def test_get_next_line_number_two_invoices():
    """get the number for the next invoice line"""
    invoice_1 = InvoiceFactory()
    InvoiceLineFactory(invoice=invoice_1, line_number=1)
    InvoiceLineFactory(invoice=invoice_1, line_number=2)
    invoice_2 = InvoiceFactory()
    InvoiceLineFactory(invoice=invoice_2, line_number=1)
    assert 3 == invoice_1.get_next_line_number()
    assert 2 == invoice_2.get_next_line_number()
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()]
Exemplo n.º 4
0
def test_ticket_totals():
    start_date = date(day=3, month=2, year=2017)
    ticket = TicketFactory()
    """
    This loop generates the following timerecords:
    Date       Start Tm End Tm   Delta   Billable Invoice Line
    2017-02-03 01:01:00 01:02:00 0:01:00 False    None
    2017-02-03 02:02:00 02:05:00 0:03:00 True     None
    2017-02-03 03:03:00 03:10:00 0:07:00 False    None
    2017-02-03 04:04:00 04:17:00 0:13:00 True     None
    2017-02-03 05:05:00 05:26:00 0:21:00 False    None
    2017-02-03 06:06:00 06:37:00 0:31:00 True     0 1.00 description_0 @0.00
    2017-02-03 08:00:00 None     0:00:00 True     None
    """
    for t in range(1, 7):
        start_time = time(hour=t, minute=t)
        end_time = time(hour=t, minute=t*t+1)
        tr = TimeRecordFactory(
            ticket=ticket, date_started=start_date, start_time=start_time,
            end_time=end_time, billable=t % 2 == 0,
        )
    # make the last time record invoiced
    tr.invoice_line = InvoiceLineFactory(timerecord=tr)
    tr.save()
    # open time record - should be ignored
    TimeRecordFactory(
        ticket=ticket, date_started=start_date, start_time=time(hour=8),
        end_time=None, billable=True,
    )
    totals = ticket.totals()
    assert str(totals['total']) == '1:16:00'
    assert str(totals['not_billable']) == '0:29:00'
    assert str(totals['pending']) == '0:16:00'
    assert str(totals['billable']) == '0:47:00'
    assert str(totals['invoiced']) == '0:31:00'
 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_has_lines():
    """does the invoice have any lines"""
    invoice = InvoiceFactory()
    InvoiceLineFactory(
        invoice=invoice,
        quantity=Decimal('1.3'),
        units='hours',
        price=Decimal('300.00'),
    )
    assert invoice.has_lines is True
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_report_total_by_user():
    contact = ContactFactory()
    invoice = InvoiceFactory(contact=contact)
    InvoiceSettingsFactory()
    # no time records
    InvoiceLineFactory(invoice=invoice)
    # u1's time records
    invoice_line = InvoiceLineFactory(invoice=invoice)
    t1 = TicketFactory(contact=contact)
    TimeRecordFactory(ticket=t1,
                      user=UserFactory(username='******'),
                      invoice_line=invoice_line)
    # u2's time records
    invoice_line = InvoiceLineFactory(invoice=invoice)
    u2 = UserFactory(username='******')
    t2 = TicketFactory(contact=contact)
    TimeRecordFactory(ticket=t2, user=u2, invoice_line=invoice_line)
    invoice_line = InvoiceLineFactory(invoice=invoice)
    t3 = TicketFactory(contact=contact)
    TimeRecordFactory(ticket=t3, user=u2, invoice_line=invoice_line)
    result = invoice.time_analysis()
    # invoice has a line with no time records
    assert '' in result
    # fred recorded time on one ticket
    assert 'u1' in result
    u1 = result['u1']
    assert 1 == len(u1)
    assert t1.pk in u1
    # sara recorded time on two tickets
    assert 'u2' in result
    u2 = result['u2']
    assert 2 == len(u2)
    assert t2.pk in u2
    assert t3.pk in u2
    # web user added an invoice line, but didn't record time
    assert 'web' not in result
    # check net total matches invoice
    net = Decimal()
    for user, tickets in result.items():
        for ticket_pk, totals in tickets.items():
            net = net + totals['net']
    assert invoice.net == net
def test_create_with_lines():
    """ Create a simple invoice with lines """
    VatSettingsFactory()
    invoice = InvoiceFactory()
    line = InvoiceLineFactory(
        invoice=invoice,
        quantity=Decimal('1.3'),
        units='hours',
        price=Decimal('300.00'),
    )
    line = InvoiceLineFactory(
        invoice=invoice,
        quantity=Decimal('2.4'),
        units='hours',
        price=Decimal('200.23'),
    )
    assert invoice.pk > 0
    assert Decimal('870.55') == invoice.net
    assert Decimal('1044.66') == invoice.gross
    assert line.is_credit is False
def test_to_invoice():
    contact = ContactFactory()
    d = date(2012, 7, 1)
    #
    TimeRecordFactory(
        title='t1',
        ticket=TicketFactory(contact=contact),
        date_started=d,
    )
    # exclude records created after the invoice date
    TimeRecordFactory(
        title='t2',
        ticket=TicketFactory(contact=contact),
        date_started=date(2012, 8, 1),
    )
    # exclude records for another contact
    TimeRecordFactory(
        title='t3',
        ticket=TicketFactory(contact=ContactFactory()),
        date_started=d,
    )
    # exclude records which have already been invoiced
    TimeRecordFactory(
        title='t4',
        ticket=TicketFactory(contact=contact),
        date_started=d,
        invoice_line=InvoiceLineFactory(),
    )
    # exclude records which have a fixed price ticket
    TimeRecordFactory(
        title='t5',
        ticket=TicketFactory(contact=contact, fixed_price=True),
        date_started=d,
    )
    #
    TimeRecordFactory(
        title='t6',
        ticket=TicketFactory(contact=contact),
        date_started=d,
    )
    qs = TimeRecord.objects.to_invoice(contact, date(2012, 7, 31))
    assert ['t1', 't6'] == [x.title for x in qs]
def test_user_can_edit_invoice_line():
    invoice_line = InvoiceLineFactory()
    time_record = TimeRecordFactory(invoice_line=invoice_line)
    assert time_record.user_can_edit is False
def test_user_can_edit_has_time():
    line = InvoiceLineFactory()
    TimeRecordFactory(invoice_line=line)
    assert line.user_can_edit is False
def test_user_can_edit():
    line = InvoiceLineFactory()
    assert line.user_can_edit is True
 def test_has_time_record(self):
     invoice_line = InvoiceLineFactory()
     TimeRecordFactory(invoice_line=invoice_line)
     self.assertTrue(invoice_line.has_time_record)
 def test_has_time_record_not(self):
     invoice_line = InvoiceLineFactory()
     self.assertFalse(invoice_line.has_time_record)
Exemplo n.º 16
0
def test_invoice_line_update(perm_check):
    invoice = InvoiceFactory()
    InvoiceLineFactory(invoice=invoice)
    url = reverse('invoice.line.update', kwargs={'pk': invoice.pk})
    perm_check.staff(url)