Skip to content

Commit 4cc06c1

Browse files
committed
Pas: Allow decimal places in rate sets.
TYPE: Bugfix LINK: OGC-3242
1 parent 3ff298f commit 4cc06c1

5 files changed

Lines changed: 52 additions & 16 deletions

File tree

src/onegov/pas/forms/rate_set.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RateSetForm(Form):
6363
validators=[InputRequired()],
6464
)
6565

66-
study_normal_president_halfhour = IntegerField(
66+
study_normal_president_halfhour = DecimalField(
6767
label=_('President: File study'),
6868
render_kw={
6969
'long_description': _('per 1/2h'),
@@ -95,7 +95,7 @@ class RateSetForm(Form):
9595
validators=[InputRequired()],
9696
)
9797

98-
study_normal_member_halfhour = IntegerField(
98+
study_normal_member_halfhour = DecimalField(
9999
label=_('Member: File study'),
100100
render_kw={
101101
'long_description': _('per 1/2h'),
@@ -116,7 +116,7 @@ class RateSetForm(Form):
116116
validators=[InputRequired()],
117117
)
118118

119-
study_intercantonal_president_hour = IntegerField(
119+
study_intercantonal_president_hour = DecimalField(
120120
label=_('President: File study'),
121121
render_kw={
122122
'long_description': _('per 1h'),
@@ -137,7 +137,7 @@ class RateSetForm(Form):
137137
validators=[InputRequired()],
138138
)
139139

140-
study_intercantonal_member_hour = IntegerField(
140+
study_intercantonal_member_hour = DecimalField(
141141
label=_('Member: File study'),
142142
render_kw={
143143
'long_description': _('per 1h'),

src/onegov/pas/layouts/rate_set.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from decimal import Decimal
34
from functools import cached_property
45
from onegov.core.elements import Confirm
56
from onegov.core.elements import Intercooler
@@ -52,6 +53,12 @@ class RateSetLayout(DefaultLayout):
5253
def collection(self) -> RateSetCollection:
5354
return RateSetCollection(self.request.session)
5455

56+
def format_rate(self, amount: float | int | Decimal) -> str:
57+
value = Decimal(str(amount))
58+
if value == value.to_integral_value():
59+
return f'CHF {int(value)}.-'
60+
return f'CHF {value:.2f}'
61+
5562
@cached_property
5663
def title(self) -> str:
5764
return '{} {}'.format(

src/onegov/pas/models/rate_set.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ class RateSet(Base, ContentMixin, TimestampMixin):
7777

7878
)
7979

80-
study_normal_president_halfhour: dict_property[int] = (
81-
content_property(default=0)
80+
study_normal_president_halfhour: dict_property[float] = content_property(
81+
default=0.0
8282
)
8383

84-
study_normal_member_halfhour: dict_property[int] = (
85-
content_property(default=0)
84+
study_normal_member_halfhour: dict_property[float] = content_property(
85+
default=0.0
8686
)
8787

88-
study_intercantonal_president_hour: dict_property[int] = (
89-
content_property(default=0)
88+
study_intercantonal_president_hour: dict_property[float] = (
89+
content_property(default=0.0)
9090
)
9191

92-
study_intercantonal_member_hour: dict_property[int] = (
93-
content_property(default=0)
92+
study_intercantonal_member_hour: dict_property[float] = content_property(
93+
default=0.0
9494
)

src/onegov/pas/templates/rate_set.pt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@
3737
<td i18n:translate="">President</td>
3838
<td>CHF ${rate_set.commission_normal_president_initial}.- <span i18n:translate="">first 2h</span></td>
3939
<td>CHF ${rate_set.commission_normal_president_additional}.- <span i18n:translate="">per additional 1/2h</span></td>
40-
<td>CHF ${rate_set.study_normal_president_halfhour}.- <span i18n:translate="">per 1/2h</span></td>
40+
<td>${layout.format_rate(rate_set.study_normal_president_halfhour)} <span i18n:translate="">per 1/2h</span></td>
4141
</tr>
4242
<tr>
4343
<td i18n:translate="">Member</td>
4444
<td>CHF ${rate_set.commission_normal_member_initial}.- <span i18n:translate="">first 2h</span></td>
4545
<td>CHF ${rate_set.commission_normal_member_additional}.- <span i18n:translate="">per additional 1/2h</span></td>
46-
<td>CHF ${rate_set.study_normal_member_halfhour}.- <span i18n:translate="">per 1/2h</span></td>
46+
<td>${layout.format_rate(rate_set.study_normal_member_halfhour)} <span i18n:translate="">per 1/2h</span></td>
4747
</tr>
4848
<tr>
4949
<th rowspan="2" i18n:translate="">intercantonal commission</th>
5050
<td i18n:translate="">President</td>
5151
<td colspan="2">CHF ${rate_set.commission_intercantonal_president_halfday}.- <span i18n:translate="">half-day</span></td>
52-
<td>CHF ${rate_set.study_intercantonal_president_hour}.- <span i18n:translate="">per 1h</span></td>
52+
<td>${layout.format_rate(rate_set.study_intercantonal_president_hour)} <span i18n:translate="">per 1h</span></td>
5353
</tr>
5454
<tr>
5555
<td i18n:translate="">Member</td>
5656
<td colspan="2">CHF ${rate_set.commission_intercantonal_member_halfday}.- <span i18n:translate="">half-day</span></td>
57-
<td>CHF ${rate_set.study_intercantonal_member_hour}.- <span i18n:translate="">per 1h</span></td>
57+
<td>${layout.format_rate(rate_set.study_intercantonal_member_hour)} <span i18n:translate="">per 1h</span></td>
5858
</tr>
5959
<tr>
6060
<th rowspan="2" i18n:translate="">Shortest meeting</th>

tests/onegov/pas/test_forms.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,35 @@ def test_rate_set_form(session: Session, dummy_request: Any) -> None:
423423
assert not form.validate()
424424
assert 'year' not in form.errors
425425

426+
# study rates may have decimal places (e.g. 52.45 / 31.70)
427+
data = {
428+
'year': 2026,
429+
'cost_of_living_adjustment': '1.5',
430+
'plenary_none_president_halfday': '1000',
431+
'plenary_none_member_halfday': '900',
432+
'commission_normal_president_initial': '300',
433+
'commission_normal_president_additional': '100',
434+
'study_normal_president_halfhour': '52.45',
435+
'commission_normal_member_initial': '250',
436+
'commission_normal_member_additional': '80',
437+
'study_normal_member_halfhour': '31.70',
438+
'commission_intercantonal_president_halfday': '500',
439+
'study_intercantonal_president_hour': '52.45',
440+
'commission_intercantonal_member_halfday': '450',
441+
'study_intercantonal_member_hour': '31.70',
442+
'shortest_all_president_halfhour': '60',
443+
'shortest_all_member_halfhour': '50',
444+
}
445+
form = RateSetForm(DummyPostData(data))
446+
form.model = collection
447+
form.request = dummy_request
448+
assert form.validate(), form.errors
449+
450+
new_set = collection.add(year=2026)
451+
form.populate_obj(new_set)
452+
assert float(new_set.study_normal_president_halfhour) == 52.45
453+
assert float(new_set.study_normal_member_halfhour) == 31.70
454+
426455

427456
def test_settlement_run_form(session: Session, dummy_request: Any) -> None:
428457
collection = SettlementRunCollection(session)

0 commit comments

Comments
 (0)