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