def handle_dates(self, from_date, to_date, options): if options.get('sync'): UpworkLoader().sync(from_date, to_date) SMonLoader().sync(from_date, to_date) users = {} for w in (Worklog.objects.between(from_date, to_date).filter( Q.user_profile.active == True).prefetch_related('user_profile') ): if w.user_profile and not w.description: key = w.user_profile.id if key in users: users[key][1] += w.hours else: users[key] = [w.user_profile, w.hours] if users: user_list = sorted(users.values(), key=lambda x: x[0].name) t = loader.get_template('missing_memo_report.txt') context = { 'timesheet': user_list, 'title': options.get('title', '') } msg = t.render(context) return self.send_message(msg, options) else: return 'No problems found'
def test_upwork_worklogs_not_daleted(self): Worklog.objects.create( work_date=date.today(), user_id='abc', user_name='abc', hours=4, description='hello world', worklog_system=WorklogSystem.upwork, ) SMonLoader().sync(date.today(), date.today()) worklogs = Worklog.objects.all().count() assert worklogs == 4, worklogs
def handle_dates(self, from_date, to_date, options): if options.get('sync', False): UpworkLoader().sync(from_date, to_date) SMonLoader().sync(from_date, to_date) users = [] team = Team.objects.filter(default=True).first() assert team, 'Please specify default team' qs = team.user_profiles.all() work_date = Q.worklog.work_date for u in (qs.order_by('name').filter( work_date >= from_date, work_date <= to_date).prefetch_related('worklog_set').annotate( total_hours=Sum(F(Q.worklog.hours.get_path())))): users.append(u) return self.send_message(users, from_date, to_date, options)
def test_linking(self): SMonLoader().sync(date.today(), date.today()) w = Worklog.objects.filter(description='BACK-813').first() assert w.issue is not None assert w.user_profile is not None
def test_worklog_count(self): SMonLoader().sync(date.today(), date.today()) worklogs = Worklog.objects.filter( worklog_system=WorklogSystem.smon).count() assert worklogs == 3, worklogs
def handle_dates(self, from_date, to_date, options): SMonLoader().sync(from_date, to_date)