Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Erreichbarkeit #885

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bo4e/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"TechnischeRessourceVerbrauchsart",
"Themengebiet",
"Titel",
"Erreichbarkeit",
"Typ",
"Verbrauchsart",
"Vertragsart",
Expand All @@ -192,6 +193,7 @@
"Zaehlergroesse",
"Zaehlertyp",
"ZaehlertypSpezifikation",
"Zeitfenster",
"ZusatzAttribut",
"__version__",
"__gh_version__",
Expand Down Expand Up @@ -252,6 +254,7 @@
from .com.dienstleistung import Dienstleistung
from .com.energieherkunft import Energieherkunft
from .com.energiemix import Energiemix
from .com.erreichbarkeit import Erreichbarkeit
from .com.fremdkostenblock import Fremdkostenblock
from .com.fremdkostenposition import Fremdkostenposition
from .com.geokoordinaten import Geokoordinaten
Expand Down Expand Up @@ -293,6 +296,7 @@
from .com.verwendungszweckpromarktrolle import VerwendungszweckProMarktrolle
from .com.zaehlwerk import Zaehlwerk
from .com.zaehlzeitregister import Zaehlzeitregister
from .com.zeitfenster import Zeitfenster
from .com.zeitraum import Zeitraum
from .com.zeitreihenwert import Zeitreihenwert
from .com.zeitspanne import Zeitspanne
Expand Down
2 changes: 2 additions & 0 deletions src/bo4e/bo/geschaeftspartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pydantic import Field

from ..com.erreichbarkeit import Erreichbarkeit
from ..enum.typ import Typ
from ..utils import postprocess_docstring
from .geschaeftsobjekt import Geschaeftsobjekt
Expand Down Expand Up @@ -82,3 +83,4 @@ class Geschaeftspartner(Geschaeftsobjekt):
#: Todo: Add optional connection to marktteilnehmer as discussed in workshop
#: not clear what is the best solution here - circular import marktteilnehmer?
#: discussed in workshop on Feb 6 2024: yes we need the bidirectional option, let's figure out a solution somehow.
erreichbarkeit: Optional[Erreichbarkeit] = None
Copy link
Contributor

@hf-fvesely hf-fvesely Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Erreichbarkeit und auch auch die Bankverbindung und Steuernummer gerne noch im Geschäftspartner-Test ergänzen. Fällt nur nicht auf, weil alles optional ist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

39 changes: 39 additions & 0 deletions src/bo4e/com/erreichbarkeit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Contains Erreichbarkeit class and corresponding marshmallow schema for de-/serialization
"""

# pylint: disable=too-few-public-methods, too-many-instance-attributes
# pylint: disable=no-name-in-module

from typing import Optional

from ..com.zeitfenster import Zeitfenster
from ..utils import postprocess_docstring
from .com import COM


@postprocess_docstring
class Erreichbarkeit(COM):
"""
Eine Komponente zur Abbildung der Erreichbarkeit

.. raw:: html

<object data="../_static/images/bo4e/com/Erreichbarkeit.svg" type="image/svg+xml"></object>

.. HINT::
`Erreichbarkeit JSON Schema <https://json-schema.app/view/%23?url=https://raw.githubusercontent.com/BO4E/BO4E-Schemas/{__gh_version__}/src/bo4e_schemas/com/Erreichbarkeit.json>`_

"""

montag_erreichbarkeit: Optional[Zeitfenster] = None

dienstag_erreichbarkeit: Optional[Zeitfenster] = None

mittwoch_erreichbarkeit: Optional[Zeitfenster] = None

donnerstag_erreichbarkeit: Optional[Zeitfenster] = None

freitag_erreichbarkeit: Optional[Zeitfenster] = None

mittagspause: Optional[Zeitfenster] = None
30 changes: 30 additions & 0 deletions src/bo4e/com/zeitfenster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Contains Zeitfenster class and corresponding marshmallow schema for de-/serialization
"""

# pylint: disable=too-few-public-methods, too-many-instance-attributes
# pylint: disable=no-name-in-module

from datetime import time
from typing import Optional

from ..utils import postprocess_docstring
from .com import COM


@postprocess_docstring
class Zeitfenster(COM):
"""
Eine Komponente zur Abbildung des Zeitfensters für die Erreichbarkeit

.. raw:: html

<object data="../_static/images/bo4e/com/Zeitfenster.svg" type="image/svg+xml"></object>

.. HINT::
`Zeitfenster JSON Schema <https://json-schema.app/view/%23?url=https://raw.githubusercontent.com/BO4E/BO4E-Schemas/{__gh_version__}/src/bo4e_schemas/com/Zeitfenster.json>`_

"""

startzeit: Optional[time] = None
endzeit: Optional[time] = None
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kannst du einen test hinzufügen, wie das serialisiert wird?
das wäre wichtig für die kompatabilität

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

der scheint probleme haben das auf github mit der Time funktion zu encode

Lokal läuft das durch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also was mich interessiert ist: sieht 17uhr hier in python gleich aus wie 17uhr drüben in c#?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

der scheint probleme haben das auf github mit der Time funktion zu encode

tests/test_erreichbarkeit.py:16: in TestErreichbarkeit
montag_erreichbarkeit=Zeitfenster(
E pydantic.errors.PydanticUserError: Zeitfenster is not fully defined; you should define ZusatzAttribut, then call Zeitfenster.model_rebuild().
E
E For further information visit https://errors.pydantic.dev/2.8/u/class-not-fully-defined

@lord-haffi weiß vllt mehr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die neuen Modelle müssen der init.py hinzugefügt werden

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lord-haffi es ligt nicht daraan das es nicht in der init war

42 changes: 42 additions & 0 deletions tests/test_erreichbarkeit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from datetime import time, timezone

import pytest

from bo4e.com.erreichbarkeit import Erreichbarkeit
from bo4e.com.zeitfenster import Zeitfenster
from tests.serialization_helper import assert_serialization_roundtrip


class TestErreichbarkeit:
@pytest.mark.parametrize(
"erreichbarkeit",
[
pytest.param(
Erreichbarkeit(
montag_erreichbarkeit=Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
dienstag_erreichbarkeit=Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
mittwoch_erreichbarkeit=Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
donnerstag_erreichbarkeit=Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
freitag_erreichbarkeit=Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
mittagspause=Zeitfenster(
startzeit=time(12, 00, tzinfo=timezone.utc), endzeit=time(13, 00, tzinfo=timezone.utc)
),
),
),
],
)
def test_serialization_roundtrip(self, erreichbarkeit: Erreichbarkeit) -> None:
"""
Test de-/serialisation of Erreichbarkeit.
"""
assert_serialization_roundtrip(erreichbarkeit)
18 changes: 18 additions & 0 deletions tests/test_geschaeftspartner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import time, timezone

import pytest

from bo4e import (
Expand All @@ -11,6 +13,8 @@
Person,
Titel,
)
from bo4e.com.erreichbarkeit import Erreichbarkeit
from bo4e.com.zeitfenster import Zeitfenster
from tests.serialization_helper import assert_serialization_roundtrip


Expand Down Expand Up @@ -55,6 +59,20 @@ class TestGeschaeftspartner:
adresse=Adresse(
postleitzahl="1014", ort="Wien 1", strasse="Ballhausplatz", hausnummer="2", landescode=Landescode.AT # type: ignore[attr-defined]
),
erreichbarkeit=Erreichbarkeit(
montag_erreichbarkeit=Zeitfenster(
startzeit=time(14, 00, tzinfo=timezone.utc), endzeit=time(17, 00, tzinfo=timezone.utc)
),
mittwoch_erreichbarkeit=Zeitfenster(
startzeit=time(6, 00, tzinfo=timezone.utc), endzeit=time(12, 00, tzinfo=timezone.utc)
),
freitag_erreichbarkeit=Zeitfenster(
startzeit=time(5, 00, tzinfo=timezone.utc), endzeit=time(22, 00, tzinfo=timezone.utc)
),
mittagspause=Zeitfenster(
startzeit=time(12, 00, tzinfo=timezone.utc), endzeit=time(13, 00, tzinfo=timezone.utc)
),
),
),
id="Landescode!=DE, DE is default",
),
Expand Down
25 changes: 25 additions & 0 deletions tests/test_zeitfenster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from datetime import time, timezone

import pytest

from bo4e.com.zeitfenster import Zeitfenster
from tests.serialization_helper import assert_serialization_roundtrip


class TestZeitfenster:
@pytest.mark.parametrize(
"zeitfenster",
[
pytest.param(
Zeitfenster(
startzeit=time(8, 00, tzinfo=timezone.utc),
endzeit=time(17, 00, tzinfo=timezone.utc),
),
),
],
)
def test_serialization_roundtrip(self, zeitfenster: Zeitfenster) -> None:
"""
Test de-/serialisation of Zeitfenster.
"""
assert_serialization_roundtrip(zeitfenster)
Loading