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

Resignation tests kerstens fork #569

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c61e5e1
First suggestion for ShiftAttendance entry in contributing
kerstenkenan Sep 29, 2024
e585045
First attempt ;) for getting the shift calendar more readable.
kerstenkenan Sep 29, 2024
3e0dbaf
Collasping also for the log view
kerstenkenan Sep 29, 2024
500a694
Fixed hopefully all changes requests.
kerstenkenan Sep 30, 2024
929ef80
Fixed text for ShiftAttendance.
kerstenkenan Sep 30, 2024
9a5c7d7
Fixed collapsing list.
kerstenkenan Sep 30, 2024
ca6596d
Deleted all "filter-button" classes.
kerstenkenan Oct 1, 2024
19935cf
Set seletc2-width to 100%.
kerstenkenan Oct 1, 2024
1dce65f
Last fixes with flexbox ;)
kerstenkenan Oct 2, 2024
fd43b26
Align title to center with flexbox.
kerstenkenan Oct 2, 2024
6462633
Translations corrections (hint from Vicky).
kerstenkenan Oct 2, 2024
e57e7c6
Fixes in opening hours.
kerstenkenan Oct 4, 2024
0b4b4d5
Merge pull request #562 from kerstenkenan/calendar-readability
kerstenkenan Oct 4, 2024
059f4e9
Merge pull request #564 from kerstenkenan/collapsing-for-logs
kerstenkenan Oct 4, 2024
1e0df74
Merge pull request #563 from kerstenkenan/contributing
kerstenkenan Oct 4, 2024
96156fe
Missing po-file
kerstenkenan Oct 4, 2024
12a0eb1
Restored 24h time
kerstenkenan Oct 4, 2024
d2e057f
Sorry for fuzzied po-file. Removed.
kerstenkenan Oct 5, 2024
e0a2082
Merge pull request #565 from kerstenkenan/translation-fixes
kerstenkenan Oct 6, 2024
5f1f24b
Translations fixes
kerstenkenan Oct 7, 2024
22343ef
Merge branch 'master' into po-file
kerstenkenan Oct 7, 2024
d0ae1c1
Merge pull request #568 from kerstenkenan/po-file
kerstenkenan Oct 7, 2024
f45682e
Merge remote-tracking branch 'origin/resignation_tests' into resignat…
kerstenkenan Oct 7, 2024
1062477
Update translations.
kerstenkenan Oct 7, 2024
5b4c8be
Search for Nonetype im form test.
kerstenkenan Oct 9, 2024
f241f23
test_membershipResignationForm_is_valid & test_validate_shareOwner_fu…
kerstenkenan Oct 11, 2024
5277655
Form tests done.
kerstenkenan Oct 14, 2024
a19c55d
Form tests work, but view tests still fails.
kerstenkenan Nov 1, 2024
830d6c1
Updateview-tests ready
kerstenkenan Nov 5, 2024
f2bf799
Changed service-function update_shifts_and_shares_and_pay_out_day in …
kerstenkenan Nov 5, 2024
f8ea2e6
Several fixes for all resignation-tests.
kerstenkenan Nov 9, 2024
f28ac19
More fixes for resignation-tests.
kerstenkenan Nov 15, 2024
ef86f52
Even more fixes for resignation-tests 1.0
kerstenkenan Nov 17, 2024
e2c541b
Even more fixes for resignation-tests 1.1
kerstenkenan Nov 17, 2024
bf95461
Even more fixes for resignation-tests 1.2
kerstenkenan Nov 17, 2024
dafaad3
Even more fixes for resignation-tests 1.3
kerstenkenan Nov 17, 2024
5cffd51
Even more fixes for resignation-tests 1.4
kerstenkenan Nov 17, 2024
0e87487
Even more fixes for resignation-tests 1.5
kerstenkenan Nov 18, 2024
1cc8a1d
Even more fixes for resignation-tests 1.6
kerstenkenan Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ The class name is the convention for the word in texts, followed by how to write
| DraftUser | `draft_user` | Also called Applicant. Represents a person that expressed interest in joining but that hasn't completed the subscription process yet. Gets deleted when ShareOwner is created. |
| ShareOwner | `share_owner` | Represents a person or a company that is either currently owning at least a share, or has owned shares in the past. Therefore they are or have been a member of the cooperative. They may not be active, for example investing members or someone who sold their shares. |
| TapirUser | `tapir_user` | Represents a person with a user account. Accounts are linked between Tapir and the Wiki for example. Gets created when the member becomes active (part of the shift system etc.), but can become inactive. |
| Shift | | Represents a shift with a specific date and time (for example, 18/06/21 10:00 to 13:00). Can be a one-time activity or an instance of a ShiftTemplate |
| ShiftTemplate | | Represents the recurring aspect of a shift in the ABCD system. For example helping at the shop on Tuesday, 10:00 to 13:00, on Week C. It has a weekday (Tuesday) and a time, but no date (18/06/21) |
| Shift | | Represents a shift with a specific date and time (for example, 18/06/21 10:00 to 13:00). Can be a one-time activity or an instance of a ShiftTemplate |
| ShiftTemplate | | Represents the recurring aspect of a shift in the ABCD system. For example helping at the shop on Tuesday, 10:00 to 13:00, on Week C. It has a weekday (Tuesday) and a time, but no date (18/06/21) |
| ShiftAttendance | 'attendances', 'shift_attendances' | Represents the registration of a member to a slot. An attendance is always in one of the states defined in the state variable and the ShiftAttendance.State enum class. This is used for tracking who is coming to which shift but also if members are attending enough shifts. See ShiftAttendance.update_shift_account_entry. |

### Django Shell

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
or visit <a href="https://www.google.com/maps/place/SuperCoop+Berlin/@52.553371,13.3585897,15z/data=!4m5!3m4!1s0x0:0x72e80db955fa8d3!8m2!3d52.5533091!4d13.3586012">SuperCoop</a>.
Feel free to drop by and meet other SuperCoopies in person! Opening hours are::
<ul>
<li>Wednesday - Friday from 16:30 - 19:30 Uhr</li>
<li>Saturdays from 11.00 - 14.00 Uhr</li>
<li>Monday - Friday from 16:30 to 19:30</li>
<li>Saturdays from 11:00 to 14:00</li>
</ul>
</p>
<p>
Expand Down
19 changes: 6 additions & 13 deletions tapir/coop/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dateutil.relativedelta import relativedelta
from django import forms
from django.core.exceptions import ValidationError
from django.forms import DateField, IntegerField
Expand Down Expand Up @@ -289,7 +288,6 @@ def clean(self):
cleaned_data = super().clean()
share_owner: ShareOwner = cleaned_data.get("share_owner")
resignation_type = cleaned_data.get("resignation_type")
cancellation_date = cleaned_data.get("cancellation_date")
transferring_shares_to = cleaned_data.get("transferring_shares_to")
paid_out = cleaned_data.get("paid_out")

Expand All @@ -298,20 +296,15 @@ def clean(self):
self.validate_duplicates(share_owner, transferring_shares_to)
self.validate_if_gifted(resignation_type, paid_out)

if resignation_type == MembershipResignation.ResignationType.BUY_BACK:
self.cleaned_data["pay_out_day"] = cancellation_date + relativedelta(
day=31, month=12, years=3
)
else:
self.cleaned_data["pay_out_day"] = cancellation_date
self.cleaned_data["paid_out"] = True

return cleaned_data

def validate_share_owner(self, share_owner):
if MembershipResignation.objects.filter(
share_owner__id=share_owner.id
).exists():
if (
self.instance.pk is None
and MembershipResignation.objects.filter(
share_owner__id=share_owner.id
).exists()
):
self.add_error(
"share_owner",
ValidationError(_("This member is already resigned.")),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 5.1.1 on 2024-11-09 16:53

import django.contrib.postgres.fields.hstore
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("coop", "0046_deleteincomingpaymentlogentry"),
("log", "0007_auto_20240702_1748"),
]

operations = [
migrations.CreateModel(
name="MembershipResignationDeleteLogEntry",
fields=[
(
"logentry_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="log.logentry",
),
),
("values", django.contrib.postgres.fields.hstore.HStoreField()),
],
options={
"abstract": False,
},
bases=("log.logentry",),
),
migrations.AlterField(
model_name="membershipresignation",
name="transferring_shares_to",
field=models.ForeignKey(
help_text="Leave this empty if the resignation type is not a transfer to another member",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="owner_to_transfer",
to="coop.shareowner",
verbose_name="OwnerToTransfer",
),
),
]
14 changes: 13 additions & 1 deletion tapir/coop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class ResignationType(models.TextChoices):
pay_out_day = models.DateField(null=True)
cancellation_reason = models.CharField(max_length=1000)
resignation_type = models.CharField(choices=ResignationType.choices, max_length=50)
transferring_shares_to = models.OneToOneField(
transferring_shares_to = models.ForeignKey(
ShareOwner,
on_delete=models.deletion.PROTECT,
verbose_name="OwnerToTransfer",
Expand Down Expand Up @@ -860,3 +860,15 @@ def populate(
old_frozen=old_frozen,
new_frozen=new_frozen,
)

class MembershipResignationDeleteLogEntry(ModelLogEntry):
template_name = "coop/log/delete_resignmember_log_entry.html"

def populate(
self,
actor: User,
model: MembershipResignation,
):
return super().populate_base(
actor=actor, share_owner=model.share_owner, model=model
)
38 changes: 20 additions & 18 deletions tapir/coop/services/MembershipResignationService.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from dateutil.relativedelta import relativedelta

from django.db import transaction

Expand All @@ -14,22 +15,25 @@
class MembershipResignationService:
@staticmethod
@transaction.atomic
def update_shifts_and_shares(resignation: MembershipResignation):
def update_shifts_and_shares_and_pay_out_day(resignation: MembershipResignation):
tapir_user: TapirUser = getattr(resignation.share_owner, "user", None)

shares = ShareOwnership.objects.filter(share_owner=resignation.share_owner)

match resignation.resignation_type:
case MembershipResignation.ResignationType.BUY_BACK:
new_end_date = resignation.cancellation_date.replace(day=31, month=12)
new_end_date = new_end_date.replace(year=new_end_date.year + 3)
new_end_date = resignation.cancellation_date+relativedelta(years=+3, day=31, month=12)
resignation.pay_out_day = new_end_date
resignation.save()
shares.update(end_date=new_end_date)
return
case MembershipResignation.ResignationType.GIFT_TO_COOP:
resignation.pay_out_day = resignation.cancellation_date
resignation.save()
shares.update(end_date=resignation.cancellation_date)
case MembershipResignation.ResignationType.TRANSFER:
resignation.pay_out_day = resignation.cancellation_date
resignation.save()
shares_to_create = [
ShareOwnership(
share_owner=resignation.transferring_shares_to,
Expand Down Expand Up @@ -58,9 +62,10 @@ def update_shifts(tapir_user: TapirUser, resignation: MembershipResignation):
)

for attendance_template in ShiftAttendanceTemplate.objects.filter(
user=tapir_user
user=tapir_user,
slot_template__shift_template__start_date__gte=start_date,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't filter relative to the start date of the shift template: if a member registers to a shift template that started for example on 15/06/23, then resigns on the 15/11/24, we still want to cancel that attendance template.

Copy link
Contributor

@kerstenkenan kerstenkenan Nov 16, 2024

Choose a reason for hiding this comment

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

What did you mean then by this: #569 (comment)?
I didn't get quiet well yet how the shift-system works in total.

):
attendance_template.cancel_attendances(start_date)
attendance_template.cancel_attendances(starting_from=start_date)
attendance_template.delete()

attendances = ShiftAttendance.objects.filter(
Expand All @@ -72,8 +77,8 @@ def update_shifts(tapir_user: TapirUser, resignation: MembershipResignation):

@staticmethod
@transaction.atomic
def delete_end_dates(member: MembershipResignation):
ShareOwnership.objects.filter(share_owner=member.share_owner).update(
def delete_end_dates(resignation: MembershipResignation):
ShareOwnership.objects.filter(share_owner=resignation.share_owner).update(
end_date=None
)

Expand All @@ -83,15 +88,12 @@ def delete_shareowner_membershippauses(resignation: MembershipResignation):
share_owner=resignation.share_owner
):
if pause.end_date is not None:
if resignation.pay_out_day is not None:
if resignation.pay_out_day <= pause.end_date:
pause.update(end_date=resignation.pay_out_day)
elif pause.start_date > resignation.pay_out_day:
pause.delete()
else:
if resignation.cancellation_date <= pause.end_date:
pause.update(end_date=resignation.cancellation_date)
elif pause.start_date > resignation.cancellation_date:
pause.delete()
if resignation.pay_out_day <= pause.end_date:
pause.end_date=resignation.pay_out_day
pause.save()
else:
pause.update(end_date=resignation.cancellation_date)
if pause.start_date > resignation.pay_out_day:
pause.delete()
else:
pause.end_date=resignation.cancellation_date
pause.save()
2 changes: 1 addition & 1 deletion tapir/coop/templates/coop/draftuser_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h5>{% translate "Applicants" %}</h5>
<form action="" method="get" class="form member-filter-form">
<div class="member-filter-form-filters">{% bootstrap_form filter.form %}</div>
<div class="member-filter-form-buttons">
<button class="filter-button {% tapir_button_link %}">
<button class=" {% tapir_button_link %}">
<span class="material-icons">filter_alt</span>{% translate 'Filter' %}
</button>
<a class="{% tapir_button_link %}"
Expand Down
2 changes: 1 addition & 1 deletion tapir/coop/templates/coop/incoming_payment_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h5 class="card-header d-flex justify-content-between align-items-center">
<form action="" method="get" class="form member-filter-form">
<div class="member-filter-form-filters">{% bootstrap_form filter.form %}</div>
<div class="member-filter-form-buttons">
<button class="filter-button {% tapir_button_link %}">
<button class="{% tapir_button_link %}">
<span class="material-icons">filter_alt</span>{% translate 'Filter' %}
</button>
<a class="{% tapir_button_link %}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% blocktranslate %}
Reactivated resigned member
{% endblocktranslate %}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h5>{% translate "Membership pauses" %}</h5>
<form action="" method="get" class="form member-filter-form">
<div class="member-filter-form-filters">{% bootstrap_form filter.form %}</div>
<div class="member-filter-form-buttons">
<button class="filter-button {% tapir_button_link %}">
<button class=" {% tapir_button_link %}">
<span class="material-icons">filter_alt</span>{% translate 'Filter' %}
</button>
<a class="{% tapir_button_link %}"
Expand Down
2 changes: 1 addition & 1 deletion tapir/coop/templates/coop/membership_resignation_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h5>{% translate "List of resigned members" %} ({{ total_of_resigned_members }})
<div class="px-3 mt-1">
<div class="member-filter-form-filters">{% bootstrap_form filter.form %}</div>
<div class="member-filter-form-buttons">
<button class="filter-button {% tapir_button_link %}">
<button class="{% tapir_button_link %}">
<span class="material-icons">filter_alt</span>{% translate 'Filter' %}
</button>
<a class="{% tapir_button_link %}"
Expand Down
6 changes: 2 additions & 4 deletions tapir/coop/templates/coop/membershipresignation_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
<div class="modal-header">
<h5 class="modal-title">Attention!</h5>
<button type="button"
class="close"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×;</span>
</button>
aria-label="Close"></button>
</div>
<p class="m-2">
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
<strong>Are you sure you want to
Expand Down
2 changes: 1 addition & 1 deletion tapir/coop/templates/coop/shareowner_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h5>{% translate "Cooperative Members" %}</h5>
<form action="" method="get" class="form member-filter-form">
<div class="member-filter-form-filters">{% bootstrap_form filter.form %}</div>
<div class="member-filter-form-buttons">
<button class="filter-button {% tapir_button_link %}">
<button class="{% tapir_button_link %}">
<span class="material-icons">filter_alt</span>{% translate 'Filter' %}
</button>
<a class="{% tapir_button_link %}"
Expand Down
Loading
Loading