From e28aca4313ae47261e24e5eb3af867d96b0c27d4 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 4 Oct 2021 14:49:18 +0200 Subject: [PATCH] finance_id now working --- input/models.py | 15 ++------------- input/tests.py | 8 -------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/input/models.py b/input/models.py index ed00c46..b047507 100644 --- a/input/models.py +++ b/input/models.py @@ -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): diff --git a/input/tests.py b/input/tests.py index 17fd798..4337480 100644 --- a/input/tests.py +++ b/input/tests.py @@ -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)