From 0b5a394fa465c7bd2f94efeaaa2e5c03652b16dc Mon Sep 17 00:00:00 2001 From: rvpsolution Date: Sat, 31 Aug 2024 16:30:40 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Tilf=C3=B8jet=20finanskonto=20til=20forenin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- members/admin/union_admin.py | 1 + members/migrations/0048_union_gl_account.py | 23 +++++++++++++++++++ .../migrations/0049_alter_union_gl_account.py | 23 +++++++++++++++++++ members/models/union.py | 6 +++++ members/schema.py | 2 +- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 members/migrations/0048_union_gl_account.py create mode 100644 members/migrations/0049_alter_union_gl_account.py diff --git a/members/admin/union_admin.py b/members/admin/union_admin.py index 186d8fc9..d16ca8b9 100644 --- a/members/admin/union_admin.py +++ b/members/admin/union_admin.py @@ -166,6 +166,7 @@ def get_queryset(self, request): "statues", "founded_at", "closed_at", + "gl_account", ), "description": "Indsæt et link til jeres vedtægter, hvornår I er stiftet (har holdt stiftende \ generalforsamling) og jeres bankkonto hvis I har sådan en til foreningen.", diff --git a/members/migrations/0048_union_gl_account.py b/members/migrations/0048_union_gl_account.py new file mode 100644 index 00000000..a94ec4e1 --- /dev/null +++ b/members/migrations/0048_union_gl_account.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-08-31 13:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("members", "0047_department_has_waiting_list"), + ] + + operations = [ + migrations.AddField( + model_name="union", + name="gl_account", + field=models.CharField( + blank=True, + help_text="Finanskontonummer i formatet 1234", + max_length=4, + verbose_name="Finanskonto:", + ), + ), + ] diff --git a/members/migrations/0049_alter_union_gl_account.py b/members/migrations/0049_alter_union_gl_account.py new file mode 100644 index 00000000..d2e4274a --- /dev/null +++ b/members/migrations/0049_alter_union_gl_account.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-08-31 13:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("members", "0048_union_gl_account"), + ] + + operations = [ + migrations.AlterField( + model_name="union", + name="gl_account", + field=models.CharField( + blank=True, + help_text="Kontonummer i formatet 1234", + max_length=4, + verbose_name="Finanskonto:", + ), + ), + ] diff --git a/members/models/union.py b/members/models/union.py index 76c76568..13fcbb77 100644 --- a/members/models/union.py +++ b/members/models/union.py @@ -88,6 +88,12 @@ class Meta: ) ], ) + gl_account = models.CharField( + "Finanskonto:", + max_length=4, + blank=True, + help_text="Kontonummer i formatet 1234", + ) def __str__(self): return self.name diff --git a/members/schema.py b/members/schema.py index f6b84130..7633b6fb 100644 --- a/members/schema.py +++ b/members/schema.py @@ -36,7 +36,7 @@ class Meta: class UnionType(DjangoObjectType): class Meta: model = Union - exclude = ("bank_main_org", "bank_account") + exclude = ("bank_main_org", "bank_account", "gl_account") class DepartmentType(DjangoObjectType): From aea582add3c7c7b0b47eab6d7dfc629b631feda7 Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:03:56 +0100 Subject: [PATCH 2/4] Added permission check for new gl_account field --- members/admin/union_admin.py | 129 ++++++++++-------- members/migrations/0048_union_gl_account.py | 23 ---- .../migrations/0049_alter_union_gl_account.py | 23 ---- ...58_alter_union_options_union_gl_account.py | 42 ++++++ members/models/union.py | 11 +- 5 files changed, 127 insertions(+), 101 deletions(-) delete mode 100644 members/migrations/0048_union_gl_account.py delete mode 100644 members/migrations/0049_alter_union_gl_account.py create mode 100644 members/migrations/0058_alter_union_options_union_gl_account.py diff --git a/members/admin/union_admin.py b/members/admin/union_admin.py index 5441e058..f6db8986 100644 --- a/members/admin/union_admin.py +++ b/members/admin/union_admin.py @@ -99,6 +99,81 @@ class UnionAdmin(admin.ModelAdmin): actions = ["export_csv_union_info"] + def get_fieldsets(self, request, obj=None): + # 20241113: https://stackoverflow.com/questions/16102222/djangoremove-superuser-checkbox-from-django-admin-panel-when-login-staff-users + + if not obj: + print("not obj") + return self.add_fieldsets + + info_fields = ( + "bank_main_org", + "bank_account", + "statues", + "founded_at", + "closed_at", + "gl_account", + ) + + if not request.user.has_perm("members.showledgeraccount"): + print("no perm") + info_fields = ( + "bank_main_org", + "bank_account", + "statues", + "founded_at", + "closed_at", + ) + + print(f"info:{info_fields}") + + return [ + ( + "Navn og Adresse", + { + "fields": ("name", "email", "address"), + "description": "

Udfyld navnet på foreningen (f.eks København, \ + vestjylland) og adressen

", + }, + ), + ( + "Bestyrelsen nye felter", + { + "fields": ( + "chairman", + "second_chair", + "cashier", + "secretary", + "board_members", + ) + }, + ), + ( + "Bestyrelsen gamle felter", + { + "fields": ( + "chairman_old", + "chairman_email_old", + "second_chair_old", + "second_chair_email_old", + "cashier_old", + "cashier_email_old", + "secretary_old", + "secretary_email_old", + "board_members_old", + ) + }, + ), + ( + "Info", + { + "fields": info_fields, + "description": "Indsæt et link til jeres vedtægter, hvornår I er stiftet (har holdt stiftende \ + generalforsamling) og jeres bankkonto hvis I har sådan en til foreningen.", + }, + ), + ] + # Solution found on https://stackoverflow.com/questions/57056994/django-model-form-with-only-view-permission-puts-all-fields-on-exclude # formfield_for_foreignkey described in documentation here: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey def formfield_for_foreignkey(self, db_field, request, **kwargs): @@ -121,60 +196,6 @@ def get_queryset(self, request): return qs return qs.filter(adminuserinformation__user=request.user) - fieldsets = [ - ( - "Navn og Adresse", - { - "fields": ("name", "email", "address"), - "description": "

Udfyld navnet på foreningen (f.eks København, \ - vestjylland) og adressen

", - }, - ), - ( - "Bestyrelsen nye felter", - { - "fields": ( - "chairman", - "second_chair", - "cashier", - "secretary", - "board_members", - ) - }, - ), - ( - "Bestyrelsen gamle felter", - { - "fields": ( - "chairman_old", - "chairman_email_old", - "second_chair_old", - "second_chair_email_old", - "cashier_old", - "cashier_email_old", - "secretary_old", - "secretary_email_old", - "board_members_old", - ) - }, - ), - ( - "Info", - { - "fields": ( - "bank_main_org", - "bank_account", - "statues", - "founded_at", - "closed_at", - "gl_account", - ), - "description": "Indsæt et link til jeres vedtægter, hvornår I er stiftet (har holdt stiftende \ - generalforsamling) og jeres bankkonto hvis I har sådan en til foreningen.", - }, - ), - ] - def union_link(self, item): url = reverse("admin:members_union_change", args=[item.id]) link = '%s' % (url, escape(item.name)) diff --git a/members/migrations/0048_union_gl_account.py b/members/migrations/0048_union_gl_account.py deleted file mode 100644 index a94ec4e1..00000000 --- a/members/migrations/0048_union_gl_account.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 4.2.11 on 2024-08-31 13:36 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("members", "0047_department_has_waiting_list"), - ] - - operations = [ - migrations.AddField( - model_name="union", - name="gl_account", - field=models.CharField( - blank=True, - help_text="Finanskontonummer i formatet 1234", - max_length=4, - verbose_name="Finanskonto:", - ), - ), - ] diff --git a/members/migrations/0049_alter_union_gl_account.py b/members/migrations/0049_alter_union_gl_account.py deleted file mode 100644 index d2e4274a..00000000 --- a/members/migrations/0049_alter_union_gl_account.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 4.2.11 on 2024-08-31 13:58 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("members", "0048_union_gl_account"), - ] - - operations = [ - migrations.AlterField( - model_name="union", - name="gl_account", - field=models.CharField( - blank=True, - help_text="Kontonummer i formatet 1234", - max_length=4, - verbose_name="Finanskonto:", - ), - ), - ] diff --git a/members/migrations/0058_alter_union_options_union_gl_account.py b/members/migrations/0058_alter_union_options_union_gl_account.py new file mode 100644 index 00000000..ea25f9c6 --- /dev/null +++ b/members/migrations/0058_alter_union_options_union_gl_account.py @@ -0,0 +1,42 @@ +# Generated by Django 4.2.11 on 2024-11-13 19:56 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("members", "0057_municipality"), + ] + + operations = [ + migrations.AlterModelOptions( + name="union", + options={ + "ordering": ["name"], + "permissions": ( + ("view_all_unions", "Can view all Foreninger"), + ("showledgeraccount", "Show General Ledger Account"), + ), + "verbose_name": "Forening", + "verbose_name_plural": "Foreninger", + }, + ), + migrations.AddField( + model_name="union", + name="gl_account", + field=models.CharField( + blank=True, + help_text="Kontonummer i formatet 1234", + max_length=4, + validators=[ + django.core.validators.RegexValidator( + message="Indtast kontonummer i det rigtige format.", + regex="^[0-9]{4}", + ) + ], + verbose_name="Finanskonto:", + ), + ), + ] diff --git a/members/models/union.py b/members/models/union.py index 13fcbb77..b5f7968e 100644 --- a/members/models/union.py +++ b/members/models/union.py @@ -10,7 +10,10 @@ class Meta: verbose_name_plural = "Foreninger" verbose_name = "Forening" ordering = ["name"] - permissions = (("view_all_unions", "Can view all Foreninger"),) + permissions = ( + ("view_all_unions", "Can view all Foreninger"), + ("showledgeraccount", "Show General Ledger Account"), + ) help_union = """Vi tilføjer automatisk "Coding Pirates" foran navnet når vi nævner det de fleste steder på siden.""" name = models.CharField("Foreningens navn", max_length=200, help_text=help_union) @@ -93,6 +96,12 @@ class Meta: max_length=4, blank=True, help_text="Kontonummer i formatet 1234", + validators=[ + RegexValidator( + regex="^[0-9]{4}", + message="Indtast kontonummer i det rigtige format.", + ) + ], ) def __str__(self): From cbe98b358a72dc126ae4c9edcf7825e89d069e04 Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:11:48 +0100 Subject: [PATCH 3/4] Create 0059_merge_20241113_2111.py Merge migrations --- members/migrations/0059_merge_20241113_2111.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 members/migrations/0059_merge_20241113_2111.py diff --git a/members/migrations/0059_merge_20241113_2111.py b/members/migrations/0059_merge_20241113_2111.py new file mode 100644 index 00000000..470047be --- /dev/null +++ b/members/migrations/0059_merge_20241113_2111.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.11 on 2024-11-13 20:11 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "members", + "0058_alter_municipality_options_remove_municipality_email_and_more", + ), + ("members", "0058_alter_union_options_union_gl_account"), + ] + + operations = [] From bc58e938a8a0c1562523f0150cd2fa211133ad68 Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:20:42 +0100 Subject: [PATCH 4/4] remove debug print. Renamed permission shortname --- members/admin/union_admin.py | 4 --- .../migrations/0060_alter_union_options.py | 25 +++++++++++++++++++ members/models/union.py | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 members/migrations/0060_alter_union_options.py diff --git a/members/admin/union_admin.py b/members/admin/union_admin.py index f6db8986..35f27ef3 100644 --- a/members/admin/union_admin.py +++ b/members/admin/union_admin.py @@ -103,7 +103,6 @@ def get_fieldsets(self, request, obj=None): # 20241113: https://stackoverflow.com/questions/16102222/djangoremove-superuser-checkbox-from-django-admin-panel-when-login-staff-users if not obj: - print("not obj") return self.add_fieldsets info_fields = ( @@ -116,7 +115,6 @@ def get_fieldsets(self, request, obj=None): ) if not request.user.has_perm("members.showledgeraccount"): - print("no perm") info_fields = ( "bank_main_org", "bank_account", @@ -125,8 +123,6 @@ def get_fieldsets(self, request, obj=None): "closed_at", ) - print(f"info:{info_fields}") - return [ ( "Navn og Adresse", diff --git a/members/migrations/0060_alter_union_options.py b/members/migrations/0060_alter_union_options.py new file mode 100644 index 00000000..23fedeb6 --- /dev/null +++ b/members/migrations/0060_alter_union_options.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.11 on 2024-11-13 21:20 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("members", "0059_merge_20241113_2111"), + ] + + operations = [ + migrations.AlterModelOptions( + name="union", + options={ + "ordering": ["name"], + "permissions": ( + ("view_all_unions", "Can view all Foreninger"), + ("show_ledger_account", "Show General Ledger Account"), + ), + "verbose_name": "Forening", + "verbose_name_plural": "Foreninger", + }, + ), + ] diff --git a/members/models/union.py b/members/models/union.py index b5f7968e..6846a48d 100644 --- a/members/models/union.py +++ b/members/models/union.py @@ -12,7 +12,7 @@ class Meta: ordering = ["name"] permissions = ( ("view_all_unions", "Can view all Foreninger"), - ("showledgeraccount", "Show General Ledger Account"), + ("show_ledger_account", "Show General Ledger Account"), ) help_union = """Vi tilføjer automatisk "Coding Pirates" foran navnet når vi nævner det de fleste steder på siden."""