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.objects.get(name=project_name) invoice = Invoice(project=project, number=self.form_result['invoice_number'], bill_to=self.form_result['bill_to'], tax=self.form_result['tax'], date=datetime.datetime( self.form_result['date'].year, self.form_result['date'].month, self.form_result['date'].day, ), rate=project.rate) invoice.save() timesheets = Timesheet.objects(project=project, __raw__={'invoice': None}) for timesheet in timesheets: timesheet.archived_rate = timesheet.rate timesheet.invoice = invoice timesheet.save() return redirect( url(controller="invoice", action="summary", id=invoice.number))
def summary(self, id): c.invoice = Invoice.objects.get(number=int(id)) c.timesheets = Timesheet.objects(invoice=c.invoice) 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.taxes = c.total_fee * c.invoice.tax * Decimal("0.01") c.after_taxes = c.total_fee + c.taxes return render('/invoice/invoice_summary.html')
def summary(self, id): c.invoice = Invoice.objects.get(number=int(id)) c.timesheets = Timesheet.objects(invoice=c.invoice) 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.taxes = c.total_fee * c.invoice.tax * Decimal("0.01") c.after_taxes = c.total_fee + c.taxes return render("/invoice/invoice_summary.html")
def create_form(self, id): project_name = id c.date = datetime.date.today() c.project = Project.objects.get(name=project_name) c.timesheets = Timesheet.objects(project=c.project, __raw__={"invoice": None}) 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.objects(project=c.project) if previous_invoices.count(): c.bill_to = previous_invoices[previous_invoices.count() - 1].bill_to return render("/invoice/invoice_form.html")
def index(self): today = datetime.date.today() c.title = "Log Time" c.entry_title = "Uninvoiced Entries" # FIXME: Surely mongoengine knows how to get References by not set? c.timesheets = Timesheet.objects(__raw__={'invoice': None}).order_by( "-date") c.total_time = sum(Decimal(t.duration) for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.project_list = Project.objects() c.date = datetime.date.today() c.delete_column = True return render('/timesheet/timeform.html')
def index(self): today = datetime.date.today() c.title = "Log Time" c.entry_title = "Uninvoiced Entries" # FIXME: Surely mongoengine knows how to get References by not set? c.timesheets = Timesheet.objects(__raw__={ 'invoice': None }).order_by("-date") c.total_time = sum(Decimal(t.duration) for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.project_list = Project.objects() c.date = datetime.date.today() c.delete_column = True return render('/timesheet/timeform.html')
def project(self, id): c.project = Project.objects.get(name=id) c.timesheets = Timesheet.objects(project=c.project, __raw__={'invoice': None}).order_by("-date") 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.objects(project=c.project) c.invoice_totals = {'duration': 0, 'fee': 0, 'total': 0} for i in c.invoices: c.invoice_totals['duration'] += i.total_duration() c.invoice_totals['fee'] += i.total_fee() c.invoice_totals['total'] += i.total() return render('/timesheet/project_summary.html')
def create_form(self, id): project_name = id c.date = datetime.date.today() c.project = Project.objects.get(name=project_name) c.timesheets = Timesheet.objects(project=c.project, __raw__={'invoice': None}) 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.objects(project=c.project) if previous_invoices.count(): c.bill_to = previous_invoices[previous_invoices.count() - 1].bill_to return render("/invoice/invoice_form.html")
def project(self, id): c.project = Project.objects.get(name=id) c.timesheets = Timesheet.objects(project=c.project, __raw__={ 'invoice': None }).order_by("-date") 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.objects(project=c.project) c.invoice_totals = {'duration': 0, 'fee': 0, 'total': 0} for i in c.invoices: c.invoice_totals['duration'] += i.total_duration() c.invoice_totals['fee'] += i.total_fee() c.invoice_totals['total'] += i.total() return render('/timesheet/project_summary.html')
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 project, cr = Project.objects.get_or_create(name=project_name) invoice, cr = Invoice.objects.get_or_create(number=-1) timesheets = Timesheet.objects(project=project, __raw__={"invoice": None}) for timesheet in timesheets: print timesheet timesheet.invoice = invoice timesheet.save() return redirect(url(controller="timesheet", action="index"))
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 project, cr = Project.objects.get_or_create(name=project_name) invoice, cr = Invoice.objects.get_or_create(number=-1) timesheets = Timesheet.objects(project=project, __raw__={'invoice': None}) for timesheet in timesheets: print timesheet timesheet.invoice = invoice timesheet.save() return redirect(url(controller="timesheet", action="index"))
def view(self, id): c.invoice = Invoice.objects.get(number=int(id)) c.project = c.invoice.project c.timesheets = Timesheet.objects(invoice=c.invoice) types = defaultdict(int) rates = {} for timesheet in c.timesheets: if timesheet.type: types[timesheet.type.type] += timesheet.duration rates[timesheet.type.type] = timesheet.rate else: types[''] += timesheet.duration rates[''] = timesheet.rate c.types = {} for type, hours in types.items(): c.types[type] = (hours, rates[type], hours * rates[type]) c.total_time = sum(t.duration for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.taxes = c.total_fee * c.invoice.tax * Decimal("0.01") c.after_taxes = c.total_fee + c.taxes return render("/invoice/invoice.html")
def view(self, id): c.invoice = Invoice.objects.get(number=int(id)) c.project = c.invoice.project c.timesheets = Timesheet.objects(invoice=c.invoice) types = defaultdict(int) rates = {} for timesheet in c.timesheets: if timesheet.type: types[timesheet.type.type] += timesheet.duration rates[timesheet.type.type] = timesheet.rate else: types[""] += timesheet.duration rates[""] = timesheet.rate c.types = {} for type, hours in types.items(): c.types[type] = (hours, rates[type], hours * rates[type]) c.total_time = sum(t.duration for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.taxes = c.total_fee * c.invoice.tax * Decimal("0.01") c.after_taxes = c.total_fee + c.taxes return render("/invoice/invoice.html")
def month(self, year, month): month_start = datetime.datetime(int(year), int(month), 1) month_end = month_start + relativedelta(months=1) - relativedelta(days=1) c.date = month_start.date() c.title = "Timesheet summary for %s" % c.date.strftime("%B, %Y") c.timesheets = Timesheet.objects(date__gte=month_start, date__lte=month_end).order_by("-date") c.total_time = sum(t.duration for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.invoice_column = True #FIXME: I'm really tired and suspect this is not the right way to do this project_summary = defaultdict(dict) for timesheet in c.timesheets: project_summary[timesheet.project.name]['duration'] = \ project_summary[timesheet.project.name].setdefault( 'duration', 0) + timesheet.duration project_summary[timesheet.project.name]['fee'] = \ project_summary[timesheet.project.name].setdefault( 'fee', 0) + timesheet.fee c.project_summary = project_summary return render('/timesheet/month_summary.html')
def month(self, year, month): month_start = datetime.datetime(int(year), int(month), 1) month_end = month_start + relativedelta(months=1) - relativedelta( days=1) c.date = month_start.date() c.title = "Timesheet summary for %s" % c.date.strftime("%B, %Y") c.timesheets = Timesheet.objects(date__gte=month_start, date__lte=month_end).order_by("-date") c.total_time = sum(t.duration for t in c.timesheets) c.total_fee = sum(t.fee for t in c.timesheets) c.invoice_column = True #FIXME: I'm really tired and suspect this is not the right way to do this project_summary = defaultdict(dict) for timesheet in c.timesheets: project_summary[timesheet.project.name]['duration'] = \ project_summary[timesheet.project.name].setdefault( 'duration', 0) + timesheet.duration project_summary[timesheet.project.name]['fee'] = \ project_summary[timesheet.project.name].setdefault( 'fee', 0) + timesheet.fee c.project_summary = project_summary return render('/timesheet/month_summary.html')
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.objects.get(name=project_name) invoice = Invoice( project=project, number=self.form_result["invoice_number"], bill_to=self.form_result["bill_to"], tax=self.form_result["tax"], date=datetime.datetime( self.form_result["date"].year, self.form_result["date"].month, self.form_result["date"].day ), rate=project.rate, ) invoice.save() timesheets = Timesheet.objects(project=project, __raw__={"invoice": None}) for timesheet in timesheets: timesheet.archived_rate = timesheet.rate timesheet.invoice = invoice timesheet.save() return redirect(url(controller="invoice", action="summary", id=invoice.number))