added test for pid. bugfix for pid

This commit is contained in:
Benni Bärmann 2021-10-05 10:13:19 +02:00
parent 35bbd4b8a7
commit 49a0fa63ac
2 changed files with 22 additions and 2 deletions

View File

@ -89,6 +89,7 @@ class Project(Volunteer):
def save(self,*args,**kwargs):
'''we generate the autogenerated fields here'''
super().save()
self.pid = str(self.account.code) + str(self.pk).zfill(3)
if not self.project_of_year:
year = self.start.year
@ -99,7 +100,7 @@ class Project(Volunteer):
projects = projects.order_by("-project_of_year")[0]
self.project_of_year = int(projects.project_of_year) + 1
self.finance_id = str(self.account.code) + str(self.project_of_year).zfill(3)
super().save(*args,**kwargs)
super().save()
def __str__(self):
return f"{self.pid} {self.name}"

View File

@ -46,7 +46,10 @@ class TestWithLogin(TestCase):
def test_project_of_year(self):
''' test if the finance id is resettet ad start of year'''
acc = Account.objects.create(code='1234', description='blabla')
acc = Account.objects.create()
acc.code='1234'
acc.description='blabla'
acc.save()
startdate = date(2022,1,1)
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
self.assertEqual(obj.project_of_year,1)
@ -75,3 +78,19 @@ class TestWithLogin(TestCase):
obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
self.assertEqual(obj3.finance_id,"1234003")
def test_pid(self):
''' test if the finance id is resettet ad start of year'''
acc = Account.objects.create(code='1234', description='blabla')
startdate = date(2022,1,1)
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
self.assertEqual(obj.pid,"1234001")
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
self.assertEqual(obj2.pid,"1234002")
olddate = date(2021,12,31)
obj4 = Project.objects.create(account= acc, name='testproject2', start=olddate)
obj3 = Project.objects.create(account= acc, name='testproject2', start=startdate)
self.assertEqual(obj3.pid,"1234004")