Example #1
0
 def create_form(self, id):
     project_name = id
     c.date = datetime.date.today()
     c.project = Project.load_or_create(project_name)
     c.timesheets = Timesheet.for_project(project_name, unbilled=True)
     c.total_time = sum(t.duration for t in c.timesheets)
     c.total_fee = c.total_time * c.project.rate
     c.next_invoice_number = Invoice.next_invoice_number()
     previous_invoices = Invoice.for_project(project_name)
     if previous_invoices.rows:
         c.bill_to = previous_invoices.rows[-1].bill_to
     return render("/invoice/invoice_form.html")
Example #2
0
 def project(self, id):
     c.project = Project.load_or_create(id)
     c.timesheets = Timesheet.for_project(id, unbilled=True)
     c.title = "Project Summary for %s" % id
     c.total_time = sum(t.duration for t in c.timesheets)
     c.total_fee = sum(t.fee for t in c.timesheets)
     c.invoices = Invoice.for_project(id)
     return render('/timesheet/project_summary.html')
Example #3
0
 def rate(self):
     project = Project.load(self.project)
     if self.invoice:
         invoice = Invoice.load(self.invoice)
         if invoice and invoice.rate:
             return invoice.rate
     if project:
         return project.rate
     return 0 
Example #4
0
    def mark_billed(self, id):
        """Sometimes we want to record timesheets as invoiced
        without creating an invoice (ie: to clear out unbilled
        stuff or because it was invoiced in another application.

        We do this by attaching those timesheets to a single
        invoice named 'no invoice'."""
        project_name = id
        invoice = Invoice.load("no invoice")
        if not invoice:
            invoice = Invoice(id="no invoice")
            invoice.store()

        timesheets = Timesheet.for_project(project_name, unbilled=True)
        for timesheet in timesheets:
            timesheet.invoice = invoice.id
            timesheet.store()
        return redirect(url(controller="timesheet", action="index"))
Example #5
0
 def summary(self, id):
     c.timesheets = Timesheet.for_invoice(id)
     c.title = "Invoice %s" % id
     c.total_time = sum(t.duration for t in c.timesheets)
     c.total_fee = sum(t.fee for t in c.timesheets)
     c.invoice = Invoice.load(id)
     c.taxes = c.total_fee * c.invoice.tax * Decimal("0.01")
     c.after_taxes = c.total_fee + c.taxes
     return render("/invoice/invoice_summary.html")
Example #6
0
 def view(self, id):
     invoice = Invoice.load(id)
     c.invoice = invoice
     c.project = Project.load_or_create(invoice.project)
     c.timesheets = Timesheet.for_invoice(id)
     c.total_time = sum(t.duration for t in c.timesheets)
     c.total_fee = c.total_time * invoice.rate
     c.taxes = c.total_fee * invoice.tax * Decimal("0.01")
     c.after_taxes = c.total_fee + c.taxes
     return render("/invoice/invoice.html")
Example #7
0
 def create(self, id):
     # yes, the swapping of id is confusing, thanks laziness
     # from default routes
     # id = name of the project
     # invoice.id = invoice number
     project_name = id
     project = Project.load_or_create(project_name)
     invoice = Invoice(
         project=project_name,
         id=self.form_result["invoice_number"],
         bill_to=self.form_result["bill_to"],
         tax=self.form_result["tax"],
         date=self.form_result["date"],
         rate=project.rate,
     )
     invoice.store()
     timesheets = Timesheet.for_project(project_name, unbilled=True)
     for timesheet in timesheets:
         timesheet.invoice = invoice.id
         timesheet.store()
     return redirect(url(controller="invoice", action="summary", id=invoice.id))
Example #8
0
 def list(self):
     c.invoices = Invoice.all_invoices()
     return render("/invoice/invoice_list.html")