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"))
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))