new field project_of_year

This commit is contained in:
Benni Bärmann 2021-10-04 12:39:09 +02:00
parent 6fdd04306f
commit 86d08db262
3 changed files with 35 additions and 8 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2021-10-04 10:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('input', '0066_project_finance_id'),
]
operations = [
migrations.AddField(
model_name='project',
name='project_of_year',
field=models.CharField(blank=True, max_length=4, null=True),
),
]

View File

@ -85,14 +85,21 @@ class Project(Volunteer):
status = models.CharField(max_length=3,choices=(('RUN', 'läuft'),('END','beendet')),default='RUN')
persons = models.IntegerField(default=1)
finance_id = models.CharField(max_length=15, null= True, blank=True)
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}')
#print(f'1: {self.id}')
# super().save(*args,**kwargs)
print(f'2: {self.id}')
#print(f'2: {self.id}')
self.pid = str(self.account.code) + str(self.pk).zfill(3)
print(f'3: {self.id}')
#print(f'3: {self.id}')
if not self.project_of_year:
# self.finance_id = "1234000"
year = self.start.year
print(f"startyear: {year}")
else:
print(f"project_of_year is {self.project_of_year}")
super().save(*args,**kwargs)
def __str__(self):

View File

@ -1,6 +1,7 @@
from django.test import TestCase, Client
from django.conf import settings
from django.contrib.auth.models import User
from datetime import date
from .models import HonoraryCertificate, Project, Account
@ -43,12 +44,13 @@ class TestWithLogin(TestCase):
response = self.client.get('/intern')
self.assertContains(response,'Übersicht aller Förderangebote')
def test_project_pid(self):
''' test if the project pid is resettet ad start of year'''
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()
obj = Project.objects.create(account= acc, name='testproject', start='2022-01-01')
startdate = date(2022,1,1)
obj = Project.objects.create(account= acc, name='testproject', start=startdate)
#obj.save()
print(f'pid: {obj.finance_id}')
self.assertEqual(obj.finance_id,'1234000')
print(f'pid: {obj.project_of_year}')
self.assertEqual(obj.project_of_year,1)