Skip to content

Commit

Permalink
Allow mulitple active runs, allow only attendences within an active run
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Jul 12, 2024
1 parent 3d77657 commit ed57c51
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 46 deletions.
12 changes: 1 addition & 11 deletions src/onegov/pas/collections/settlement_run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from datetime import date
from onegov.core.collection import GenericCollection
from onegov.pas.models import SettlementRun
from sqlalchemy import or_

from typing import TYPE_CHECKING
if TYPE_CHECKING:
Expand All @@ -28,15 +26,7 @@ def query(self) -> 'Query[SettlementRun]':
query = super().query()

if self.active is not None:
if self.active:
query = query.filter(
or_(
SettlementRun.end.is_(None),
SettlementRun.end >= date.today()
)
)
else:
query = query.filter(SettlementRun.end < date.today())
query = query.filter(SettlementRun.active.is_(self.active))

return query.order_by(SettlementRun.name)

Expand Down
54 changes: 38 additions & 16 deletions src/onegov/pas/forms/attendence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from onegov.pas import _
from onegov.pas.collections import CommissionCollection
from onegov.pas.collections import ParliamentarianCollection
from onegov.pas.models import SettlementRun
from onegov.pas.models.attendence import TYPES
from wtforms.fields import DateField
from wtforms.fields import FloatField
Expand All @@ -15,11 +16,37 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Collection
from onegov.core.request import CoreRequest
from onegov.pas.models import Attendence
from typing import Any


class AttendenceForm(Form):
class SettlementRunBoundMixin:

if TYPE_CHECKING:
# forward declaration of required attributes
date: DateField
request: 'CoreRequest'

def ensure_date(self) -> bool:
if self.date.data:
query = self.request.session.query(SettlementRun)
query = query.filter(
SettlementRun.active == True,
SettlementRun.start <= self.date.data,
SettlementRun.end >= self.date.data,
)
if not query.first():
assert isinstance(self.date.errors, list)
self.date.errors.append(
_("No within an active settlement run.")
)
return False

return True


class AttendenceForm(Form, SettlementRunBoundMixin):

date = DateField(
label=_('Date'),
Expand Down Expand Up @@ -50,18 +77,10 @@ class AttendenceForm(Form):
depends_on=('type', '!plenary'),
)

def validate(self) -> bool: # type:ignore[override]
result = super().validate()

if self.type.data != 'plenary' and not self.commission_id.data:
assert isinstance(self.commission_id.errors, list)
self.commission_id.errors.append(
_("Please select a commission.")
)
result = False

def ensure_commission(self) -> bool:
if (
self.type.data != 'plenary'
self.type.data
and self.type.data != 'plenary'
and self.commission_id.data
and self.parliamentarian_id.data
):
Expand All @@ -77,8 +96,9 @@ def validate(self) -> bool: # type:ignore[override]
self.commission_id.errors.append(
_("Parliamentarian is not in this commission.")
)
result = False
return result
return False

return True

def process_obj(self, obj: 'Attendence') -> None: # type:ignore
super().process_obj(obj)
Expand Down Expand Up @@ -129,7 +149,7 @@ def on_request(self) -> None:
]


class AttendenceAddPlenaryForm(Form):
class AttendenceAddPlenaryForm(Form, SettlementRunBoundMixin):

date = DateField(
label=_('Date'),
Expand Down Expand Up @@ -163,7 +183,7 @@ def on_request(self) -> None:
]


class AttendenceAddCommissionForm(Form):
class AttendenceAddCommissionForm(Form, SettlementRunBoundMixin):

date = DateField(
label=_('Date'),
Expand All @@ -190,6 +210,8 @@ class AttendenceAddCommissionForm(Form):
validators=[InputRequired()],
)

# todo:

def get_useful_data(self) -> dict[str, 'Any']: # type:ignore[override]
result = super().get_useful_data()
result['commission_id'] = self.model.id
Expand Down
6 changes: 6 additions & 0 deletions src/onegov/pas/forms/settlement_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from onegov.pas import _
from onegov.pas.layouts import DefaultLayout
from onegov.pas.models import SettlementRun
from wtforms.fields import BooleanField
from wtforms.fields import DateField
from wtforms.fields import StringField
from wtforms.validators import InputRequired
Expand All @@ -28,6 +29,11 @@ class SettlementRunForm(Form):
default=date.today
)

active = BooleanField(
label=_('Active'),
validators=[InputRequired()],
)

description = HtmlField(
label=_('Description'),
)
Expand Down
30 changes: 13 additions & 17 deletions src/onegov/pas/locale/de_CH/LC_MESSAGES/onegov.pas.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: OneGov Cloud 1.0\n"
"POT-Creation-Date: 2024-07-12 09:24+0200\n"
"POT-Creation-Date: 2024-07-12 10:45+0200\n"
"PO-Revision-Date: 2021-03-03 16:24+0100\n"
"Language-Team: German\n"
"Language: de_CH\n"
Expand Down Expand Up @@ -32,6 +32,9 @@ msgstr "PAS Einstellungen"
msgid "More settings"
msgstr "Weitere Einstellungen"

msgid "No within an active settlement run."
msgstr "Nicht in einem aktiven Abrechungslauf"

msgid "Date"
msgstr "Datum"

Expand All @@ -47,9 +50,6 @@ msgstr "Parlamentarier:in"
msgid "Commission"
msgstr "Kommission"

msgid "Please select a commission."
msgstr "Bitte eine Kommission auswählen."

msgid "Parliamentarian is not in this commission."
msgstr "Parlamentarier:in ist nicht in dieser Kommission."

Expand Down Expand Up @@ -243,6 +243,9 @@ msgstr "Kürzestsitzung"
msgid "Rate set for ${year} alredy exists"
msgstr "Sätze für ${year} bereits erfasst"

msgid "Active"
msgstr "Aktiv"

msgid "End must be after start"
msgstr "Ende muss nach dem Start liegen"

Expand Down Expand Up @@ -501,6 +504,12 @@ msgstr "Betrag"
msgid "No rate sets defined yet."
msgstr "Noch keine Sätze erfasst."

msgid "Yes"
msgstr "Ja"

msgid "No"
msgstr "Nein"

msgid "No settlement runs defined yet."
msgstr "Noch keine Abrechnungsläufe erfasst"

Expand All @@ -522,9 +531,6 @@ msgstr "Neue Plenarsitzung"
msgid "Your changes were saved"
msgstr "Änderungen gespeichert"

msgid "Active"
msgstr "Aktiv"

msgid "Inactive"
msgstr "Inaktiv"

Expand Down Expand Up @@ -587,13 +593,3 @@ msgstr "Neuer Abrechnungslauf hinzugefügt"

msgid "New settlement run"
msgstr "Neuer Abrechnungslauf"

#~ msgid ""
#~ "This is only a temporary view and will be possibly removed or changed in "
#~ "a future release."
#~ msgstr ""
#~ "Dies ist nur eine vorübergehende Ansicht und wird möglicherweise in einer "
#~ "zukünftigen Version entfernt oder geändert werden."

#~ msgid "Details"
#~ msgstr "Details"
7 changes: 7 additions & 0 deletions src/onegov/pas/models/settlement_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import Text
from sqlalchemy import Boolean
from uuid import uuid4

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -44,5 +45,11 @@ class SettlementRun(Base, ContentMixin, TimestampMixin):
nullable=False
)

#: The end date
active: 'Column[bool]' = Column(
Boolean,
nullable=False
)

#: The description
description: 'dict_property[str | None]' = content_property()
9 changes: 7 additions & 2 deletions src/onegov/pas/templates/settlement_run.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

<tal:b metal:fill-slot="content">
<dl class="field-display">
<div tal:condition="settlement_run.start">
<div>
<dt i18n:translate>Start</dt>
<dd>${layout.format_date(settlement_run.start, 'date')}</dd>
</div>
<div tal:condition="settlement_run.end">
<div>
<dt i18n:translate>End</dt>
<dd>${layout.format_date(settlement_run.end, 'date')}</dd>
</div>
<div>
<dt i18n:translate>Active</dt>
<dd tal:condition="settlement_run.active" i18n:translate>Yes</dd>
<dd tal:condition="not settlement_run.active" i18n:translate>No</dd>
</div>
</dl>
</tal:b>
</div>

0 comments on commit ed57c51

Please sign in to comment.