Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 680: Fix FY reports to only include specific years #847

Merged
merged 10 commits into from
Nov 19, 2018

Conversation

amymok
Copy link
Member

@amymok amymok commented Nov 7, 2018

Description

See Issue #680

  • Added before parameter for get_timecards function to allow getting a list of timecards before and include a specific date. This can now be used with after parameter to get a specific date range of timecards
  • Added corresponding tests for before parameter as well as using it in conjunction with `after parameter
  • Added before parameters to the current reports so it is filtered with a range
  • Iterate through fiscal years to create reports instead of hardcoding every single year
  • user.organization shows in the output table

I also added a few static methods to figure out the actual fiscal year start and end date based on the discussion I have with Jackie.

During the week that spans two fiscal years, with the five work days, charging will happen to the year that has more days in it. So, if there are three or more September work days, the week will belong to the year September is in, else, if there are more October work days (three or more), this week will belong to the year October is in.

Additional information

Include any of the following (as necessary):

  • Relevant research and support documents
  • Screenshot images
  • Notes
    • There seems to be an inconsistency with the date in the report for FY2016. The superuser report starts with 10/1/2016, but other reports starts with 10/2/2016. 10/1/2016 is a Saturday so I am not sure if this is an exception or not for fiscal years. I changed it back to FY starts on 10/1 and ends with 9/30 unless there are exceptions, please let me know.
    • I hardcoded "2017" as the first fiscal year for reporting because that was what's already there, if I should use something else, let me know.

@codecov-io
Copy link

codecov-io commented Nov 7, 2018

Codecov Report

Merging #847 into master will increase coverage by 0.15%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #847      +/-   ##
==========================================
+ Coverage   91.32%   91.47%   +0.15%     
==========================================
  Files          39       39              
  Lines        1752     1783      +31     
==========================================
+ Hits         1600     1631      +31     
  Misses        152      152
Impacted Files Coverage Δ
hours/models.py 96.55% <0%> (-0.16%) ⬇️
api/views.py 98.58% <0%> (+0.03%) ⬆️
hours/views.py 87.85% <0%> (+0.2%) ⬆️
employees/models.py 100% <0%> (+1.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f495ea...7f51038. Read the comment docs.

tock/hours/views.py Outdated Show resolved Hide resolved
@tbaxter-18f
Copy link
Contributor

@amymok Is there anything outstanding you need to finish this up?

@amymok
Copy link
Member Author

amymok commented Nov 14, 2018

@tbaxter-18f yes, I am waiting for a conversation with Jackie about the FY, because it will alter how that is being calculated, let me ping her again.

@amymok
Copy link
Member Author

amymok commented Nov 14, 2018

Just had a conversation with @HuixianXu, here's the definition:

During the week that spans two fiscal years, with the five work days, charging will happen to the year that has more days in it. So, if there are three or more September work days, the week will belong to the year September is in, else, if there are more October work days (three or more), this week will belong to the year October is in.

So I will use this to continue with the work.

@tbaxter-18f
Copy link
Contributor

Fantastic. Thanks for following up, Amy. Will you be sure to note that in the code so we have it documented for posterity? Thanks!

@amymok amymok changed the title [WIP] Issue 680: Fix FY reports to only include specific years Issue 680: Fix FY reports to only include specific years Nov 15, 2018
@tbaxter-18f
Copy link
Contributor

Amy, I believe the last acceptance criteria was referring to https://github.com/18F/tock/blob/master/tock/tock/templates/hours/reporting_period_detail.html, which currently shows users who have and haven't tocked, with their name and email. The desire was to show their org, too, if I recall correctly. @abrouilette does that sound right to you?

first_date = datetime.date(fiscal_year - 1, 10, 1)
# converting definition of weekday for easier calculation,
# so Sun = 0, Mon = 1, ... Sat = 6
normalized_weekday = (first_date.weekday() + 1) % 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to change anything, and I'm not even sure I'm right, but I think there may be bits in the calendar module that may make some of this easier: https://docs.python.org/2/library/calendar.html

Only mentioning it in case it's helpful in the future :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about the calendar, thanks! I think still some work using the calendar method. I will leave this as-is.

year = ReportingPeriod.get_fiscal_year_from_date(today)
context['fiscal_years'] = []
for year in range(2017, year + 1):
year_dates = dict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably would have written all of this to the dict in one shot in order to (hopefully) be a bit more readable...

context['fiscal_years'].append({
     'year': year,
     'start_date': blahblahblah,
    'end_date': BobLoblaw
})

But it's fine the way you have it here too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a really confusing piece of code now that you pointed out. I also was using year as each instance in the for loop as well as a variable for the end of range. I am rewriting it now.

@tbaxter-18f
Copy link
Contributor

I think this looks really great, Amy. Thanks for really thinking it through. The only thing I want to be sure about before merging it is that organization in the table. Thanks!

@tbaxter-18f
Copy link
Contributor

Confirmed in Slack, it's that report html page. Thanks!

@amymok
Copy link
Member Author

amymok commented Nov 16, 2018

Confirmed in Slack, it's that report html page. Thanks!

Thanks I will take a look later today.

@amymok
Copy link
Member Author

amymok commented Nov 17, 2018

@tbaxter-18f This is ready for review again. Thanks!

'year': fy,
'start_date': ReportingPeriod.get_fiscal_year_start_date(fy),
'end_date': ReportingPeriod.get_fiscal_year_end_date(fy)
} for fy in range(2017, year + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting how you're building out the list of dicts in a list comprehension. I wouldn't have thought of that, but it's very readable this way!

Copy link
Contributor

@tbaxter-18f tbaxter-18f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Amy! I thought it looked great before, but even greater now.

@tbaxter-18f tbaxter-18f merged commit 279f7c3 into master Nov 19, 2018
@Jkrzy Jkrzy deleted the issue-680-report branch May 14, 2019 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants