From 86d08db26286b79914bfea800c743a5d8a1e2dc1 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 4 Oct 2021 12:39:09 +0200 Subject: [PATCH] new field project_of_year --- .../migrations/0067_project_project_of_year.py | 18 ++++++++++++++++++ input/models.py | 13 ++++++++++--- input/tests.py | 12 +++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 input/migrations/0067_project_project_of_year.py diff --git a/input/migrations/0067_project_project_of_year.py b/input/migrations/0067_project_project_of_year.py new file mode 100644 index 0000000..8bde852 --- /dev/null +++ b/input/migrations/0067_project_project_of_year.py @@ -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), + ), + ] diff --git a/input/models.py b/input/models.py index c4cec25..2909653 100644 --- a/input/models.py +++ b/input/models.py @@ -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): diff --git a/input/tests.py b/input/tests.py index 3e643e2..b08b620 100644 --- a/input/tests.py +++ b/input/tests.py @@ -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)