forked from beba/foerderbarometer
finance_id now working
This commit is contained in:
parent
466ce45e13
commit
e28aca4313
|
@ -88,28 +88,17 @@ class Project(Volunteer):
|
||||||
project_of_year = models.IntegerField(default=0)
|
project_of_year = models.IntegerField(default=0)
|
||||||
|
|
||||||
def save(self,*args,**kwargs):
|
def save(self,*args,**kwargs):
|
||||||
# is there a way to call super().save() only once?
|
'''we generate the autogenerated fields here'''
|
||||||
#print(f'1: {self.id}')
|
|
||||||
# super().save(*args,**kwargs)
|
|
||||||
#print(f'2: {self.id}')
|
|
||||||
self.pid = str(self.account.code) + str(self.pk).zfill(3)
|
self.pid = str(self.account.code) + str(self.pk).zfill(3)
|
||||||
#print(f'3: {self.id}')
|
|
||||||
if not self.project_of_year:
|
if not self.project_of_year:
|
||||||
# self.finance_id = "1234000"
|
|
||||||
year = self.start.year
|
year = self.start.year
|
||||||
print(f"startyear: {year}")
|
|
||||||
projects = Project.objects.filter(start__year=year)
|
projects = Project.objects.filter(start__year=year)
|
||||||
print(projects)
|
|
||||||
if not projects:
|
if not projects:
|
||||||
self.project_of_year = 1
|
self.project_of_year = 1
|
||||||
else:
|
else:
|
||||||
projects = projects.order_by("-project_of_year")[0]
|
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
|
self.project_of_year = int(projects.project_of_year) + 1
|
||||||
print(f"project_of_year is {self.project_of_year}")
|
self.finance_id = str(self.account.code) + str(self.project_of_year).zfill(3)
|
||||||
else:
|
|
||||||
print(f"project_of_year is {self.project_of_year}")
|
|
||||||
super().save(*args,**kwargs)
|
super().save(*args,**kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -46,13 +46,9 @@ class TestWithLogin(TestCase):
|
||||||
|
|
||||||
def test_project_of_year(self):
|
def test_project_of_year(self):
|
||||||
''' test if the finance id is resettet ad start of year'''
|
''' 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 = Account.objects.create(code='1234', description='blabla')
|
||||||
#acc.save()
|
|
||||||
startdate = date(2022,1,1)
|
startdate = date(2022,1,1)
|
||||||
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
|
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)
|
self.assertEqual(obj.project_of_year,1)
|
||||||
|
|
||||||
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
||||||
|
@ -66,13 +62,9 @@ class TestWithLogin(TestCase):
|
||||||
|
|
||||||
def test_finance_id(self):
|
def test_finance_id(self):
|
||||||
''' test if the finance id is resettet ad start of year'''
|
''' 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 = Account.objects.create(code='1234', description='blabla')
|
||||||
#acc.save()
|
|
||||||
startdate = date(2022,1,1)
|
startdate = date(2022,1,1)
|
||||||
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
|
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")
|
self.assertEqual(obj.finance_id,"1234001")
|
||||||
|
|
||||||
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
obj2 = Project.objects.create(account= acc, name='testproject2', start=startdate)
|
||||||
|
|
Loading…
Reference in New Issue