1
0
Fork 0

finance_id now working

This commit is contained in:
Benni Bärmann 2021-10-04 14:49:18 +02:00
parent 466ce45e13
commit e28aca4313
2 changed files with 2 additions and 21 deletions

View File

@ -88,28 +88,17 @@ class Project(Volunteer):
project_of_year = models.IntegerField(default=0)
def save(self,*args,**kwargs):
# is there a way to call super().save() only once?
#print(f'1: {self.id}')
# super().save(*args,**kwargs)
#print(f'2: {self.id}')
'''we generate the autogenerated fields here'''
self.pid = str(self.account.code) + str(self.pk).zfill(3)
#print(f'3: {self.id}')
if not self.project_of_year:
# self.finance_id = "1234000"
year = self.start.year
print(f"startyear: {year}")
projects = Project.objects.filter(start__year=year)
print(projects)
if not projects:
self.project_of_year = 1
else:
projects = projects.order_by("-project_of_year")[0]
print("GEORDNET")
print(f"highest project_of_year is {projects.project_of_year}")
self.project_of_year = int(projects.project_of_year) + 1
print(f"project_of_year is {self.project_of_year}")
else:
print(f"project_of_year is {self.project_of_year}")
self.finance_id = str(self.account.code) + str(self.project_of_year).zfill(3)
super().save(*args,**kwargs)
def __str__(self):

View File

@ -46,13 +46,9 @@ class TestWithLogin(TestCase):
def test_project_of_year(self):
''' test if the finance id is resettet ad start of year'''
# self.client.login(username='vladimir', password='reiherzehe')
acc = Account.objects.create(code='1234', description='blabla')
#acc.save()
startdate = date(2022,1,1)
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
#obj.save()
print(f'p_of_year: {obj.project_of_year}')
self.assertEqual(obj.project_of_year,1)
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
@ -66,13 +62,9 @@ class TestWithLogin(TestCase):
def test_finance_id(self):
''' test if the finance id is resettet ad start of year'''
# self.client.login(username='vladimir', password='reiherzehe')
acc = Account.objects.create(code='1234', description='blabla')
#acc.save()
startdate = date(2022,1,1)
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
#obj.save()
# print(f'p_of_year: {obj.project_of_year}')
self.assertEqual(obj.finance_id,"1234001")
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)