Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Dec 19, 2024
1 parent 3eb68a4 commit 242003d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 47 deletions.
69 changes: 53 additions & 16 deletions trs/migrations/0010_auto_20241216_1859.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,75 @@
# Generated by Django 3.2.16 on 2024-12-16 18:59

from django.db import migrations, models
from django.db import migrations
from django.db import models

import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('trs', '0009_auto_20220708_1535'),
("trs", "0009_auto_20220708_1535"),
]

operations = [
migrations.CreateModel(
name='MPC',
name="MPC",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='naam')),
('description', models.CharField(blank=True, max_length=255, verbose_name='omschrijving')),
('target', models.DecimalField(decimal_places=2, default=0, max_digits=12, verbose_name='omzetdoelstelling')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255, verbose_name="naam")),
(
"description",
models.CharField(
blank=True, max_length=255, verbose_name="omschrijving"
),
),
(
"target",
models.DecimalField(
decimal_places=2,
default=0,
max_digits=12,
verbose_name="omzetdoelstelling",
),
),
],
options={
'verbose_name': 'Markt-product-combinatie',
'verbose_name_plural': 'Markt-product-combinaties',
'ordering': ['name'],
"verbose_name": "Markt-product-combinatie",
"verbose_name_plural": "Markt-product-combinaties",
"ordering": ["name"],
},
),
migrations.AddField(
model_name='person',
name='mpc',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='persons', to='trs.mpc', verbose_name='markt-product-combinatie'),
model_name="person",
name="mpc",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="persons",
to="trs.mpc",
verbose_name="markt-product-combinatie",
),
),
migrations.AddField(
model_name='project',
name='mpc',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='trs.mpc', verbose_name='markt-product-combinatie'),
model_name="project",
name="mpc",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="projects",
to="trs.mpc",
verbose_name="markt-product-combinatie",
),
),
]
6 changes: 3 additions & 3 deletions trs/migrations/0011_remove_project_startup_meeting_done.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Migration(migrations.Migration):

dependencies = [
('trs', '0010_auto_20241216_1859'),
("trs", "0010_auto_20241216_1859"),
]

operations = [
migrations.RemoveField(
model_name='project',
name='startup_meeting_done',
model_name="project",
name="startup_meeting_done",
),
]
6 changes: 3 additions & 3 deletions trs/migrations/0012_remove_project_is_accepted.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Migration(migrations.Migration):

dependencies = [
('trs', '0011_remove_project_startup_meeting_done'),
("trs", "0011_remove_project_startup_meeting_done"),
]

operations = [
migrations.RemoveField(
model_name='project',
name='is_accepted',
model_name="project",
name="is_accepted",
),
]
6 changes: 3 additions & 3 deletions trs/migrations/0013_remove_person_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Migration(migrations.Migration):

dependencies = [
('trs', '0012_remove_project_is_accepted'),
("trs", "0012_remove_project_is_accepted"),
]

operations = [
migrations.RemoveField(
model_name='person',
name='mpc',
model_name="person",
name="mpc",
),
]
2 changes: 1 addition & 1 deletion trs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def left_to_dish_out(self):
raw = self.total_income() - self.total_costs()
# Note: a little margin around zero is allowed to account for contract
# amounts not always being rounded.
if (-1 < raw < 1):
if -1 < raw < 1:
return 0
return raw

Expand Down
66 changes: 45 additions & 21 deletions trs/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import calendar
from collections import defaultdict
from collections import OrderedDict
from copy import deepcopy
Expand Down Expand Up @@ -36,8 +35,8 @@
from trs.models import Booking
from trs.models import BudgetItem
from trs.models import Group
from trs.models import MPC
from trs.models import Invoice
from trs.models import MPC
from trs.models import Payable
from trs.models import Person
from trs.models import PersonChange
Expand All @@ -49,6 +48,7 @@
from trs.models import YearWeek
from trs.templatetags.trs_formatting import hours as format_as_hours

import calendar
import datetime
import logging
import statistics
Expand Down Expand Up @@ -766,15 +766,19 @@ def available_years(self):
@cached_property
def free_projects(self):
return self.all_projects.filter(
Q(description__icontains="verlof") | Q(description__icontains="feest")).filter(
bookings__year_week__year=self.year,
bookings__booked_by=self.active_person
)
Q(description__icontains="verlof") | Q(description__icontains="feest")
).filter(
bookings__year_week__year=self.year, bookings__booked_by=self.active_person
)

@cached_property
def lines(self):
booked_this_year_per_week_per_project = (
Booking.objects.filter(booked_by=self.person, year_week__year=self.year, booked_on__in=self.free_projects)
Booking.objects.filter(
booked_by=self.person,
year_week__year=self.year,
booked_on__in=self.free_projects,
)
.values("year_week__week", "booked_on")
.annotate(models.Sum("hours"))
)
Expand All @@ -785,10 +789,14 @@ def lines(self):
for year_week in YearWeek.objects.filter(year=self.year):
weeks[year_week.week] = deepcopy(empty_week)
for booking in booked_this_year_per_week_per_project:
weeks[booking["year_week__week"]][booking["booked_on"]] = booking["hours__sum"]
weeks[booking["year_week__week"]][booking["booked_on"]] = booking[
"hours__sum"
]
result = []
for year_week in YearWeek.objects.filter(year=self.year):
hours = [weeks[year_week.week][project.id] for project in self.free_projects]
hours = [
weeks[year_week.week][project.id] for project in self.free_projects
]
line = {"year_week": year_week, "hours": hours}
result.append(line)
return result
Expand Down Expand Up @@ -3681,12 +3689,14 @@ def dates(self):
if month == 0:
continue
for day in range(num_of_days):
result.append(datetime.date(self.YEAR, month, day+1))
result.append(datetime.date(self.YEAR, month, day + 1))
return result

@property
def header_line(self):
return ["Project", "Projectnummer"] + [day.strftime("%d %b") for day in self.dates]
return ["Project", "Projectnummer"] + [
day.strftime("%d %b") for day in self.dates
]

@cached_property
def bookings_per_week_per_wbso_project_per_person(self):
Expand All @@ -3703,17 +3713,30 @@ def bookings_per_week_per_wbso_project_per_person(self):
)
.annotate(models.Sum("hours"))
)
#RRR

# RRR

@cached_property
def relevant_wbso_projects(self):
wbso_projects = set([(item["booked_on__wbso_project"], item["booked_on__wbso_project__title"])
for item in self.bookings_per_week_per_wbso_project_per_person])
wbso_projects = set(
[
(
item["booked_on__wbso_project"],
item["booked_on__wbso_project__title"],
)
for item in self.bookings_per_week_per_wbso_project_per_person
]
)
return sorted(wbso_projects)

@cached_property
def relevant_persons(self):
persons = set([item["booked_by__name"] for item in self.bookings_per_week_per_wbso_project_per_person])
persons = set(
[
item["booked_by__name"]
for item in self.bookings_per_week_per_wbso_project_per_person
]
)
return sorted(persons)

def prepend_lines(self, person):
Expand All @@ -3731,17 +3754,18 @@ def excel_lines(self, person):

def _wbso_hours(item):
return round(
item["hours__sum"]
* (item["booked_on__wbso_percentage"] or 0)
/ 100
item["hours__sum"] * (item["booked_on__wbso_percentage"] or 0) / 100
)

for (wbso_project_id, wbso_project_name) in self.relevant_wbso_projects:
line = [wbso_project_name, wbso_project_id] # TODO: uren/dag
filled_in = {}
bookings = [item for item in self.bookings_per_week_per_wbso_project_per_person
if item["booked_on__wbso_project"] == wbso_project_id
and item["booked_by__name"] == person]
bookings = [
item
for item in self.bookings_per_week_per_wbso_project_per_person
if item["booked_on__wbso_project"] == wbso_project_id
and item["booked_by__name"] == person
]
for item in bookings:
key = item["year_week__first_day"]
existing = filled_in.get(key, 0)
Expand Down

0 comments on commit 242003d

Please sign in to comment.