def __call__(self, parser, namespace, values, option_string): super(QualityRaw, self).__call__(parser, namespace, values, option_string) session = DBSession() with open(namespace.filename, 'wb') as ofile: writer = csv.writer(ofile, dialect='excel') writer.writerow(['CR ID', 'Customer', 'Duration in days']) for cr in session.query(CustomerRequest.id, CustomerRequest.project_id, Project.customer_id, Trac.trac_name).\ outerjoin(Project, CustomerRequest.project_id == Project.id).\ outerjoin(Trac, Project.id==Trac.project_id).distinct(): tickets, Ticket, TicketCustom = tickets_for_cr(self.metadata, session, cr.trac_name, cr.id) tids = [t.id for t in tickets] if not tids: continue entries = session.query(TimeEntry)\ .filter_by(project_id=cr.project_id)\ .filter(TimeEntry.ticket.in_(tids))\ .filter(extract('year', TimeEntry.date) == namespace.year) if entries.count(): hours = timedelta_as_work_days(sum([a.hours for a in entries], timedelta())) writer.writerow([cr.id, cr.customer_id, hours])
def __call__(self): schema = self.MyEntriesSchema(validator=validate_period).clone()\ .bind(yesterday=yesterday(), today=datetime.date.today()) limit = 1000 projects = qry_active_projects().all() form = PorInlineForm(schema, formid='my_entries', method='GET', buttons=[ SearchButton(title=u'Search'), ]) form['project_id'].widget.values = [('', '')] + sorted([(str(p.id), ' / '.join([p.customer.name, p.name])) for p in projects], key=lambda x: x[1].lower()) result_table = '' controls = self.request.GET.items() try: appstruct = form.validate(controls) except ValidationFailure as e: return { 'form': e.render(), 'saved_query_form': render_saved_query_form(self.request), 'result_table': None } current_uid = self.request.authenticated_user.id entries_by_date, entries_count = self.search(author_id=current_uid, limit=limit, **appstruct) highlight = functools.partial(webhelpers.html.tools.highlight, phrase=appstruct['searchtext']) delta0 = datetime.timedelta() delta_tot = sum([sum((e.hours for e in x[1]), delta0) for x in entries_by_date], delta0) human_tot = timedelta_as_human_str(delta_tot) days_tot = timedelta_as_work_days(delta_tot) result_table = render('por.dashboard:reports/templates/my_entries_results.pt', { 'entries_by_date': entries_by_date, 'entries_count': entries_count, 'highlight': highlight, 'human_tot': human_tot, 'days_tot': days_tot, 'datetime': datetime, 'ticket_url': ticket_url, 'timedelta_as_human_str': timedelta_as_human_str, }, request=self.request) return { 'form': form.render(appstruct=appstruct), 'saved_query_form': render_saved_query_form(self.request), 'result_table': result_table, }
def timeentries_days(self): from por.models.tp import TimeEntry, timedelta_as_work_days request = get_current_request() tickets = ticket_store.get_tickets_for_request(customer_request=self, request=request) ticket_ids = [a["id"] for a in tickets] timeentries = ( DBSession().query(TimeEntry).filter_by(project_id=self.project_id).filter(TimeEntry.ticket.in_(ticket_ids)) ) hours = sum([a.hours for a in timeentries], datetime.timedelta()) return timedelta_as_work_days(hours)
def __call__(self, parser, namespace, values, option_string): super(QualityCR, self).__call__(parser, namespace, values, option_string) session = DBSession() with open(namespace.filename, 'wb') as ofile: writer = csv.writer(ofile, dialect='excel') writer.writerow(['CR ID', 'Customer', 'CR state', 'Estimation in days', 'TE Duration in days', 'TE sistem/install in days']) for cr in session.query(CustomerRequest.id, CustomerRequest.workflow_state, CustomerRequest.project_id, Project.customer_id, Trac.trac_name).\ outerjoin(Project, CustomerRequest.project_id == Project.id).\ outerjoin(Trac, Project.id==Trac.project_id).distinct(): tickets, Ticket, TicketCustom = tickets_for_cr(self.metadata, session, cr.trac_name, cr.id) tids = [t.id for t in tickets] if not tids: continue estimations = sum([a.days for a in \ session.query(Estimation.days)\ .filter_by(customer_request_id=cr.id)]) entries = session.query(TimeEntry)\ .filter_by(project_id=cr.project_id)\ .filter(TimeEntry.ticket.in_(tids))\ .filter(extract('year', TimeEntry.date) == namespace.year) if entries.count(): total_hours = timedelta_as_work_days(sum([a.hours for a in entries], timedelta())) only_dev = entries.filter(or_(TimeEntry.description.ilike('%install%'), TimeEntry.description.ilike('%sistem%'))) only_dev_hours = timedelta_as_work_days(sum([a.hours for a in only_dev], timedelta())) writer.writerow([cr.id, cr.customer_id, cr.workflow_state, estimations, total_hours, only_dev_hours])