From 49a0fa63ac6ec47e04ca2bc13cf61ab2249476f7 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 5 Oct 2021 10:13:19 +0200 Subject: [PATCH] added test for pid. bugfix for pid --- input/models.py | 3 ++- input/tests.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/input/models.py b/input/models.py index b047507..6f42c34 100644 --- a/input/models.py +++ b/input/models.py @@ -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}" diff --git a/input/tests.py b/input/tests.py index 4337480..86a2e1e 100644 --- a/input/tests.py +++ b/input/tests.py @@ -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")