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

Implementation of the cancellation process in Tapir #495

Merged
merged 13 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
3 changes: 2 additions & 1 deletion tapir/coop/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin

from tapir.coop.models import ShareOwnership, DraftUser
from tapir.coop.models import ShareOwnership, DraftUser, ResignedMembership

admin.site.register(ShareOwnership)
admin.site.register(DraftUser)
admin.site.register(ResignedMembership)
74 changes: 71 additions & 3 deletions tapir/coop/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils import timezone
from dateutil.relativedelta import relativedelta
from django import forms
from django.core.exceptions import ValidationError
from django.forms import DateField, IntegerField
Expand All @@ -15,8 +17,10 @@
ShareOwner,
IncomingPayment,
MembershipPause,
ResignedMembership,
TapirUser,
)
from tapir.shifts.forms import ShareOwnerChoiceField
from tapir.shifts.forms import ShareOwnerChoiceField, TapirUserChoiceField
from tapir.utils.forms import DateInputTapir, TapirPhoneNumberField


Expand Down Expand Up @@ -235,8 +239,6 @@ class Meta:
"then the fields can be different."
)
)


class MembershipPauseForm(forms.ModelForm):
class Meta:
model = MembershipPause
Expand All @@ -247,3 +249,69 @@ class Meta:
}

share_owner = ShareOwnerChoiceField()

class MembershipCancelForm(forms.ModelForm):
now = timezone.now()
already_resigned = ResignedMembership.objects.all()
in_three_years = _(f"Coop buys back share(s)")
tvedeane marked this conversation as resolved.
Show resolved Hide resolved
# at 31/12/{int(now.strftime("%Y"))+3}')
tvedeane marked this conversation as resolved.
Show resolved Hide resolved
cancellation_reason = forms.CharField(max_length=1000, widget=forms.Textarea(
attrs={"rows": 2, "placeholder": _("Please not more than 1000 characters.")}
))
coop_buys_shares_back = forms.BooleanField(label=in_three_years, required=False)
share_owner = ShareOwnerChoiceField()
willing_to_gift_shares_to_coop = forms.BooleanField(label="Willing to gift shares to coop", required=False)
transfering_shares_to = TapirUserChoiceField(required=False, label=_("Transfering share(s) to"))
class Meta:
model = ResignedMembership
fields = ["share_owner",
"cancellation_reason",
"cancellation_date",
"coop_buys_shares_back",
"willing_to_gift_shares_to_coop",
"transfering_shares_to",
"paid_out",
]
widgets = {"cancellation_date": DateInputTapir()}

def clean(self):
cleaned_data = super().clean()
share_owner = cleaned_data.get("share_owner")
coop_buys_shares_back = cleaned_data.get("coop_buys_shares_back")
willing_to_gift_shares_to_coop = cleaned_data.get("willing_to_gift_shares_to_coop")
transfering_shares_to = cleaned_data.get("transfering_shares_to")
paid_out = cleaned_data.get("paid_out")
cancellation_date = cleaned_data.get("cancellation_date")
errmsg = _("Please take only one choice.")

if self.instance.pk is None:
for owner in self.already_resigned:
if owner.share_owner == share_owner:
self.add_error("share_owner", ValidationError(
_("This member is already resigned.")
))
break

if coop_buys_shares_back and willing_to_gift_shares_to_coop:
self.add_error("coop_buys_shares_back", errmsg)
self.add_error("willing_to_gift_shares_to_coop", errmsg)
elif transfering_shares_to != None and (coop_buys_shares_back or willing_to_gift_shares_to_coop):
self.add_error("transfering_shares_to", errmsg)
if coop_buys_shares_back:
self.add_error("coop_buys_shares_back", errmsg)
elif willing_to_gift_shares_to_coop:
self.add_error("willing_to_gift_shares_to_coop", errmsg)
if transfering_shares_to is not None:
if transfering_shares_to.share_owner == share_owner:
self.add_error("transfering_shares_to", ValidationError(
_("Sender and receiver of tranfering the share(s) cannot be the same.")
))
if (transfering_shares_to != None and paid_out) or (willing_to_gift_shares_to_coop and paid_out) :
self.add_error("paid_out", ValidationError(_("Cannot pay out, because shares have been gifted.")
))
if transfering_shares_to == None and not willing_to_gift_shares_to_coop and not coop_buys_shares_back:
self.add_error("transfering_shares_to", ValidationError(_("Please make a least one choice.")))
self.add_error("willing_to_gift_shares_to_coop", ValidationError(_("Please make a least one choice.")))
self.add_error("coop_buys_shares_back", ValidationError(_("Please make a least one choice.")))
if coop_buys_shares_back:
self.instance.pay_out_day = cancellation_date + relativedelta(day=31, month=12, years=3)
tvedeane marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions tapir/coop/migrations/0042_auto_20240319_1242.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.23 on 2024-03-19 11:42

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could all the migrations be merged into a single file? Or there are 9 logically separate changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure to understand how to merge migrations files into one? I make the command "make migrations" and django puts out these single files. If you could tell me how to merge migrations files ....

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, these are created automatically (mixed it with my Java project, where these files are written by hand).
Would it be possible to remove them and run make migrations afterwards? Maybe then they would become a single file. Not sure though, so we may keep it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put them in the PR, so nobody would have to make a migration on the server. And the migrations files are on GitHub also as single files in there. Also we have a bug when making a migrations as I discussed with Théo. It makes all the time a needless files in the account-app. If you want to make your own makemigrations command you'll have to delete this file first.

This comment was marked as resolved.


dependencies = [
('coop', '0041_auto_20231221_1403'),
]

operations = [
migrations.AddField(
model_name='shareownership',
name='cancellation_date',
field=models.DateField(blank=True, default=django.utils.timezone.now, null=True),
),
migrations.CreateModel(
name='ResignedMembership',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cancellation_date', models.DateField(blank=True, null=True)),
tvedeane marked this conversation as resolved.
Show resolved Hide resolved
('cancellation_reason', models.CharField(max_length=1000)),
('coop_buys_shares_back', models.BooleanField()),
('willing_to_gift_shares_to_coop', models.BooleanField()),
('share_owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='coop.shareowner', verbose_name='Shareowner')),
],
),
]
25 changes: 25 additions & 0 deletions tapir/coop/migrations/0043_auto_20240403_2252.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.23 on 2024-04-03 20:52

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0042_auto_20240319_1242'),
]

operations = [
migrations.AddField(
model_name='resignedmembership',
name='paid_out',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 4, 3, 20, 52, 2, 484356, tzinfo=utc), null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.23 on 2024-04-03 21:01

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0043_auto_20240403_2252'),
]

operations = [
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 4, 3, 21, 1, 45, 498750, tzinfo=utc), null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.23 on 2024-04-03 21:35

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0044_alter_resignedmembership_cancellation_date'),
]

operations = [
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 4, 3, 21, 35, 22, 494389, tzinfo=utc), null=True),
),
]
28 changes: 28 additions & 0 deletions tapir/coop/migrations/0046_auto_20240403_2350.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.23 on 2024-04-03 21:50

import datetime
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('coop', '0045_alter_resignedmembership_cancellation_date'),
]

operations = [
migrations.AddField(
model_name='resignedmembership',
name='transfering_shares_to',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='TapirUser'),
),
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 4, 3, 21, 50, 43, 829933, tzinfo=utc), null=True),
),
]
25 changes: 25 additions & 0 deletions tapir/coop/migrations/0047_auto_20240506_1146.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.23 on 2024-05-06 09:46

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0046_auto_20240403_2350'),
]

operations = [
migrations.AddField(
model_name='resignedmembership',
name='pay_out_day',
field=models.DateField(null=True),
),
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 5, 6, 9, 46, 20, 243645, tzinfo=utc), null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.23 on 2024-05-07 08:42

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0047_auto_20240506_1146'),
]

operations = [
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 5, 7, 8, 42, 36, 563930, tzinfo=utc), null=True),
),
]
46 changes: 46 additions & 0 deletions tapir/coop/migrations/0049_auto_20240515_1331.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.2.23 on 2024-05-15 11:31

import datetime
import django.contrib.postgres.fields.hstore
from django.db import migrations, models
import django.db.models.deletion
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('log', '0007_auto_20240319_1242'),
('coop', '0048_alter_resignedmembership_cancellation_date'),
]

operations = [
migrations.CreateModel(
name='ResignMembershipCreateLogEntry',
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.CreateModel(
name='ResignMembershipUpdateLogEntry',
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')),
('old_values', django.contrib.postgres.fields.hstore.HStoreField()),
('new_values', django.contrib.postgres.fields.hstore.HStoreField()),
],
options={
'abstract': False,
},
bases=('log.logentry',),
),
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 5, 15, 11, 31, 18, 181204, tzinfo=utc), null=True),
),
]
24 changes: 24 additions & 0 deletions tapir/coop/migrations/0050_auto_20240522_1950.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.23 on 2024-05-22 17:50

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('coop', '0049_auto_20240515_1331'),
]

operations = [
migrations.RemoveField(
model_name='shareownership',
name='cancellation_date',
),
migrations.AlterField(
model_name='resignedmembership',
name='cancellation_date',
field=models.DateField(blank=True, default=datetime.datetime(2024, 5, 22, 17, 50, 26, 744464, tzinfo=utc), null=True),
),
]
Loading
Loading