changed logic of generation of finId and pId, solved Travelform error, hotel variable travelmodel is not required anymore
This commit is contained in:
parent
35f0dd84ab
commit
2fe292fda0
6 changed files with 79 additions and 13 deletions
|
@ -29,11 +29,11 @@ admin.site.add_action(export_as_csv)
|
||||||
@admin.register(Project)
|
@admin.register(Project)
|
||||||
class ProjectAdmin(admin.ModelAdmin):
|
class ProjectAdmin(admin.ModelAdmin):
|
||||||
save_as = True
|
save_as = True
|
||||||
search_fields = ('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')
|
list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
|
||||||
# action = ['export_as_csv']
|
# action = ['export_as_csv']
|
||||||
date_hierarchy = 'end'
|
date_hierarchy = 'end'
|
||||||
|
readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
|
||||||
|
|
||||||
@admin.register(BusinessCard)
|
@admin.register(BusinessCard)
|
||||||
class BusinessCardAdmin(admin.ModelAdmin):
|
class BusinessCardAdmin(admin.ModelAdmin):
|
||||||
|
@ -89,9 +89,10 @@ class IFGAdmin(admin.ModelAdmin):
|
||||||
class TravelAdmin(admin.ModelAdmin):
|
class TravelAdmin(admin.ModelAdmin):
|
||||||
save_as = True
|
save_as = True
|
||||||
search_fields = ['realname', 'granted_date']
|
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')
|
list_display_links = ('realname', 'project')
|
||||||
date_hierarchy = 'project_end'
|
date_hierarchy = 'project_end'
|
||||||
|
readonly_fields = ('project_end_quartal', 'project_end')
|
||||||
|
|
||||||
@admin.register(Email)
|
@admin.register(Email)
|
||||||
class EmailAdmin(admin.ModelAdmin):
|
class EmailAdmin(admin.ModelAdmin):
|
||||||
|
|
|
@ -65,8 +65,7 @@ class TravelForm(FdbForm):
|
||||||
self.fields['travelcost'].required = True
|
self.fields['travelcost'].required = True
|
||||||
self.fields['checkin'].required = True
|
self.fields['checkin'].required = True
|
||||||
self.fields['checkout'].required = True
|
self.fields['checkout'].required = True
|
||||||
self.fields['hotel'].required = True
|
self.fields['hotel'].required = False
|
||||||
self.fields['project_end'].required = False
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Travel
|
model = Travel
|
||||||
|
|
18
input/migrations/0086_project_end_quartal.py
Normal file
18
input/migrations/0086_project_end_quartal.py
Normal file
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
18
input/migrations/0087_travel_project_end_quartal.py
Normal file
18
input/migrations/0087_travel_project_end_quartal.py
Normal file
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -95,6 +95,7 @@ class Project(Volunteer):
|
||||||
persons = models.IntegerField(default=1)
|
persons = models.IntegerField(default=1)
|
||||||
finance_id = models.CharField(max_length=15, null= True, blank=True)
|
finance_id = models.CharField(max_length=15, null= True, blank=True)
|
||||||
project_of_year = models.IntegerField(default=0)
|
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):
|
def save(self,*args,**kwargs):
|
||||||
'''we generate the autogenerated fields here'''
|
'''we generate the autogenerated fields here'''
|
||||||
|
@ -103,21 +104,43 @@ class Project(Volunteer):
|
||||||
super().save()
|
super().save()
|
||||||
self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3)
|
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)
|
# 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:
|
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...
|
# we need to determine if this is a new year with its first new project...
|
||||||
year = self.start.year
|
year = self.start.year
|
||||||
print(year)
|
#print(year)
|
||||||
projects = Project.objects.filter(start__year=year)
|
projects = Project.objects.filter(start__year=year)
|
||||||
if not projects:
|
if not projects:
|
||||||
#print('BBB')
|
#print('BBB')
|
||||||
self.project_of_year = 1
|
self.project_of_year = 1
|
||||||
|
self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.project_of_year).zfill(3)
|
||||||
else:
|
else:
|
||||||
#print('CCC')
|
#print('CCC')
|
||||||
|
# get the project of year number of latest entry
|
||||||
projects = projects.order_by("-project_of_year")[0]
|
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.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()
|
super().save()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -169,7 +192,7 @@ class Travel(Volunteer):
|
||||||
intern_notes = models.TextField(max_length=1000, blank=True, verbose_name='interne Anmerkungen')
|
intern_notes = models.TextField(max_length=1000, blank=True, verbose_name='interne Anmerkungen')
|
||||||
project_end = models.DateField(blank=True, null=True, verbose_name='Projektende')
|
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
|
# 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.db.models.signals import pre_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
@ -177,8 +200,10 @@ from django.dispatch import receiver
|
||||||
@receiver(pre_save, sender=Travel, dispatch_uid="get_project_end")
|
@receiver(pre_save, sender=Travel, dispatch_uid="get_project_end")
|
||||||
def getProjectEnd(sender, instance, **kwargs):
|
def getProjectEnd(sender, instance, **kwargs):
|
||||||
#instance.project_end = instance.project.end
|
#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
|
# using pre save instead
|
||||||
# def save(self,*args,**kwargs):
|
# def save(self,*args,**kwargs):
|
||||||
|
|
5
input/static/css/dateFieldNoNowShortcutInTravels.css
Normal file
5
input/static/css/dateFieldNoNowShortcutInTravels.css
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
span.datetimeshortcuts > a:first-child {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue