Skip to content

Commit

Permalink
Merge pull request #2164 from City-of-Helsinki/hl-862
Browse files Browse the repository at this point in the history
HL-862 | Allow two decimals for working hours
  • Loading branch information
sirtawast authored Aug 11, 2023
2 parents bb7c79b + 15eee56 commit 1c955cb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("applications", "0035_alter_applicationbatch_handler"),
]

operations = [
migrations.AlterField(
model_name="employee",
name="working_hours",
field=models.DecimalField(
blank=True,
decimal_places=2,
max_digits=5,
null=True,
verbose_name="working hour",
),
),
]
4 changes: 2 additions & 2 deletions backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ class Employee(UUIDModel, TimeStampedModel):
)
working_hours = models.DecimalField(
verbose_name=_("working hour"),
decimal_places=1,
max_digits=4,
decimal_places=2,
max_digits=5,
blank=True,
null=True,
)
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@
"number": {
"invalid": "Virheellinen arvo, ilmoita vain numeroita",
"max": "Arvon tulee olla enintään {{max}}",
"min": "Arvon tulee olla vähintään {{min}}"
"min": "Arvon tulee olla vähintään {{min}}",
"twoDecimals": "Arvon tulee sisältää enintään kaksi desimaalia"
},
"string": {
"max": "Tämä kenttä voi olla korkeintaan {{max}} merkkiä pitkä",
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@
"number": {
"invalid": "Virheellinen arvo, ilmoita vain numeroita",
"max": "Arvon tulee olla enintään {{max}}",
"min": "Arvon tulee olla vähintään {{min}}"
"min": "Arvon tulee olla vähintään {{min}}",
"twoDecimals": "Arvon tulee sisältää enintään kaksi desimaalia"
},
"string": {
"max": "Tämä kenttä voi olla korkeintaan {{max}} merkkiä pitkä",
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@
"number": {
"invalid": "Virheellinen arvo, ilmoita vain numeroita",
"max": "Arvon tulee olla enintään {{max}}",
"min": "Arvon tulee olla vähintään {{min}}"
"min": "Arvon tulee olla vähintään {{min}}",
"twoDecimals": "Arvon tulee sisältää enintään kaksi desimaalia"
},
"string": {
"max": "Tämä kenttä voi olla korkeintaan {{max}} merkkiä pitkä",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ export const getValidationSchema = (
.nullable()
.required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)),
[EMPLOYEE_KEYS.WORKING_HOURS]: Yup.number()
.test(
'is-decimal',
t(VALIDATION_MESSAGE_KEYS.NUMBER_TWO_DECIMALS),
(value: number): boolean =>
value ? /^\d+.?\d{1,2}$/.test(String(value)) : false
)
.transform((_value, originalValue) =>
Number(getNumberValue(originalValue))
)
Expand Down
1 change: 1 addition & 0 deletions frontend/benefit/shared/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum VALIDATION_MESSAGE_KEYS {
NUMBER_INVALID = 'common:form.validation.number.invalid',
NUMBER_MIN = 'common:form.validation.number.min',
NUMBER_MAX = 'common:form.validation.number.max',
NUMBER_TWO_DECIMALS = 'common:form.validation.number.twoDecimals',
PHONE_INVALID = 'common:form.validation.phone.invalid',
STRING_POSITIVENUMBER = 'common:form.validation.string.positiveNumber',
STRING_MIN = 'common:form.validation.string.min',
Expand Down

0 comments on commit 1c955cb

Please sign in to comment.