1
0
Fork 0

changed logic of generation of finId and pId, solved Travelform error, hotel variable travelmodel is not required anymore

This commit is contained in:
alpcentaur 2023-02-27 17:09:29 +00:00
parent a064b78958
commit 0b450feac9
6 changed files with 79 additions and 13 deletions

View File

@ -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):

View File

@ -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

View 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'),
),
]

View 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'),
),
]

View File

@ -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.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):

View File

@ -0,0 +1,5 @@
span.datetimeshortcuts > a:first-child {
visibility: hidden;
}