-
Notifications
You must be signed in to change notification settings - Fork 22
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
Little resignation improvements - deleting end_dates #592
base: master
Are you sure you want to change the base?
Little resignation improvements - deleting end_dates #592
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find on the bug,
I think we should fix it a bit differently, I left comments.
for share_ownership in resignation.share_owner.share_ownerships.all(): | ||
if share_ownership.end_date >= resignation.cancellation_date: | ||
share_ownership.end_date = None | ||
share_ownership.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to be more specific about which shares end_date we remove. For the cases where the cancellation was instant, we can remove the end date of all shares that are after the cancellation date, as you did.
For ResignationType.BUY_BACK
, we should only remove the end dates of shares that are at or after the pay out day.
When updating several shares, you can do it this way:
for share_ownership in resignation.share_owner.share_ownerships.all(): | |
if share_ownership.end_date >= resignation.cancellation_date: | |
share_ownership.end_date = None | |
share_ownership.save() | |
resignation.share_owner.share_ownerships.filter( | |
end_date__gte=resignation.cancellation_date | |
).update(end_date=None) |
@@ -69,6 +69,7 @@ def test_membershipResignationDeleteView_default_sharesEndDateSetToNone( | |||
|
|||
self.assertStatusCode(response, HTTPStatus.OK) | |||
mock_on_resignation_deleted.assert_called_once_with(resignation) | |||
self.assertTrue(resignation.share_owner.share_ownerships.first().end_date, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be self.assertEqual
instead of self.assertTrue
It's a good idea to update the test, but this is not the correct test to update: this one only checks that on_resignation_deleted
gets called. Since on_resignation_deleted
is replaced with a mock function, it is not actually executed, inside the test the dates don't actually get updated.
I think we want a new test, similar to test_deleteEndDates_default_sharesEndDateSetToNone
, that instead does test_deleteEndDates_sharesEndOnPayOutDay_sharesEndDateSetToNone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is done by test_deleteEndDates_someSharesEndedBeforeCancellation_thoseSharesKeepTheirEndDate
in test_service.py
in the last line. Don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite: in test_deleteEndDates_someSharesEndedBeforeCancellation_thoseSharesKeepTheirEndDate
, we check that shares that ended before the cancellation are not affected.
In case of share buy back, we want to check that shares that end after the pay out day have their end-date set to none, and that shares that end before the pay out day are not affected.
Hi @Theophile-Madet, while checking out further your implementations for the resignation issue, I fall over (what seems to me) a little bug, after I tried to cancel and remove a resigned member from the list (with 3 years cash back) here on my local. With the former filtering in the
delete_end_dates
function checking whether the cancellation_date equals the end_date, so the end_dates of peoples with shares ending 3 years in the future don't get set to None. Hope this PR makes sense to you?!