From 0b450feac92b75cd42df1ee06dc9f53001db2ca4 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Mon, 27 Feb 2023 17:09:29 +0000 Subject: [PATCH] changed logic of generation of finId and pId, solved Travelform error, hotel variable travelmodel is not required anymore --- input/admin.py | 9 +++-- input/forms.py | 3 +- input/migrations/0086_project_end_quartal.py | 18 +++++++++ .../0087_travel_project_end_quartal.py | 18 +++++++++ input/models.py | 39 +++++++++++++++---- .../css/dateFieldNoNowShortcutInTravels.css | 5 +++ 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 input/migrations/0086_project_end_quartal.py create mode 100644 input/migrations/0087_travel_project_end_quartal.py create mode 100644 input/static/css/dateFieldNoNowShortcutInTravels.css diff --git a/input/admin.py b/input/admin.py index 547fc8f..59746a0 100755 --- a/input/admin.py +++ b/input/admin.py @@ -29,11 +29,11 @@ admin.site.add_action(export_as_csv) @admin.register(Project) class ProjectAdmin(admin.ModelAdmin): save_as = True - search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status') - list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status') + search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal') + list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal') # action = ['export_as_csv'] date_hierarchy = 'end' - + readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id') @admin.register(BusinessCard) class BusinessCardAdmin(admin.ModelAdmin): @@ -89,9 +89,10 @@ class IFGAdmin(admin.ModelAdmin): class TravelAdmin(admin.ModelAdmin): save_as = True search_fields = ['realname', 'granted_date'] - list_display = ('realname', 'granted', 'granted_date', 'project_end', 'project') + list_display = ('realname', 'granted', 'granted_date', 'project_end', 'project', 'project_end_quartal') list_display_links = ('realname', 'project') date_hierarchy = 'project_end' + readonly_fields = ('project_end_quartal', 'project_end') @admin.register(Email) class EmailAdmin(admin.ModelAdmin): diff --git a/input/forms.py b/input/forms.py index 8b0b898..f4bf805 100755 --- a/input/forms.py +++ b/input/forms.py @@ -65,8 +65,7 @@ class TravelForm(FdbForm): self.fields['travelcost'].required = True self.fields['checkin'].required = True self.fields['checkout'].required = True - self.fields['hotel'].required = True - self.fields['project_end'].required = False + self.fields['hotel'].required = False class Meta: model = Travel diff --git a/input/migrations/0086_project_end_quartal.py b/input/migrations/0086_project_end_quartal.py new file mode 100644 index 0000000..6eb6ed7 --- /dev/null +++ b/input/migrations/0086_project_end_quartal.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2022-12-07 09:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0085_auto_20221205_1820'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='end_quartal', + field=models.CharField(blank=True, max_length=15, null=True, verbose_name='Quartal Projekt Ende'), + ), + ] diff --git a/input/migrations/0087_travel_project_end_quartal.py b/input/migrations/0087_travel_project_end_quartal.py new file mode 100644 index 0000000..c1d8ea8 --- /dev/null +++ b/input/migrations/0087_travel_project_end_quartal.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2022-12-07 09:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0086_project_end_quartal'), + ] + + operations = [ + migrations.AddField( + model_name='travel', + name='project_end_quartal', + field=models.CharField(blank=True, max_length=15, null=True, verbose_name='Quartal Projekt Ende'), + ), + ] diff --git a/input/models.py b/input/models.py index 8ae7958..96ce900 100755 --- a/input/models.py +++ b/input/models.py @@ -95,6 +95,7 @@ class Project(Volunteer): persons = models.IntegerField(default=1) finance_id = models.CharField(max_length=15, null= True, blank=True) project_of_year = models.IntegerField(default=0) + end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende") def save(self,*args,**kwargs): '''we generate the autogenerated fields here''' @@ -103,21 +104,43 @@ class Project(Volunteer): super().save() self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3) # self.pid = str(self.account.code) + str(self.pk).zfill(3) - # generation of finance_id + + # generation of field quartals + if self.end.month in [1, 2, 3]: + self.end_quartal = 'Q1' + if self.end.month in [4, 5, 6]: + self.end_quartal = 'Q2' + if self.end.month in [7, 8, 9]: + self.end_quartal = 'Q3' + if self.end.month in [10, 11, 12]: + self.end_quartal = 'Q4' + + # generation of pid and financeID + if not self.project_of_year: - print('AAA') + #print('AAA') # we need to determine if this is a new year with its first new project... year = self.start.year - print(year) + #print(year) projects = Project.objects.filter(start__year=year) if not projects: #print('BBB') self.project_of_year = 1 + self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.project_of_year).zfill(3) else: #print('CCC') + # get the project of year number of latest entry projects = projects.order_by("-project_of_year")[0] + # add one to value of latest entry self.project_of_year = int(projects.project_of_year) + 1 - self.finance_id = str(self.account.code) + str(self.project_of_year).zfill(3) + self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.project_of_year).zfill(3) + + if str(self.account.code) == '21111': + self.finance_id = str(self.account.code) + str(self.project_of_year).zfill(3) + else: + self.finance_id = str(self.account.code) + + super().save() def __str__(self): @@ -169,7 +192,7 @@ class Travel(Volunteer): intern_notes = models.TextField(max_length=1000, blank=True, verbose_name='interne Anmerkungen') project_end = models.DateField(blank=True, null=True, verbose_name='Projektende') # use content type model to get the end date for the project foreign key - + project_end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende") from django.db.models.signals import pre_save from django.dispatch import receiver @@ -177,8 +200,10 @@ from django.dispatch import receiver @receiver(pre_save, sender=Travel, dispatch_uid="get_project_end") def getProjectEnd(sender, instance, **kwargs): #instance.project_end = instance.project.end - instance.project_end = instance.project.end - + + if instance.project: + instance.project_end = instance.project.end + instance.project_end_quartal = instance.project.end_quartal # using pre save instead # def save(self,*args,**kwargs): diff --git a/input/static/css/dateFieldNoNowShortcutInTravels.css b/input/static/css/dateFieldNoNowShortcutInTravels.css new file mode 100644 index 0000000..0c0c7f2 --- /dev/null +++ b/input/static/css/dateFieldNoNowShortcutInTravels.css @@ -0,0 +1,5 @@ + +span.datetimeshortcuts > a:first-child { + visibility: hidden; +} +