-
Notifications
You must be signed in to change notification settings - Fork 5
Implement BO Tarif & COM TarifpreispositionProOrt & COM TarifpreisstaffelProOrt #348
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
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2033cb0
✨Implement BO Regionaltarif
hf-aschloegl 073ec87
✅ Add tests
hf-aschloegl cf05132
📦📝Generated docs
hf-aschloegl 7c45786
Implement COM TarifpreisstaffelProOrt
hf-kklein 072ce37
Imiplement COM TarifpreispositionProOrt
hf-kklein 32970e7
pylint
hf-kklein ab76f2f
Implement BO Tarif
hf-kklein 6beb6c4
Merge branch 'master' into tarif
hf-kklein 4d443e4
✅ Add test with minimal attributes
hf-krechan 7d48342
Update src/bo4e/com/tarifpreispositionproort.py
hf-kklein a0043ac
Update src/bo4e/com/tarifpreispositionproort.py
hf-kklein 85223db
Update src/bo4e/bo/tarif.py
hf-kklein 431d82d
Update src/bo4e/bo/tarif.py
hf-kklein 6a5e7e0
Update tests/test_tarifpreisstaffelproort.py
hf-kklein 6ed5e76
Update tests/test_tarifpreisstaffelproort.py
hf-kklein fd72520
Update tests/test_tarifpreispositionproort.py
hf-kklein 70d7215
Update tests/test_tarifpreisstaffelproort.py
hf-kklein 73dd6e9
Update tests/test_tarifpreispositionproort.py
hf-kklein e5ab4db
Update src/bo4e/bo/tarif.py
hf-kklein cd81da2
Update src/bo4e/bo/tarif.py
hf-kklein 13ee89a
Merge branch 'master' into tarif
hf-kklein c671ba2
use data_key
hf-kklein 231e256
Merge remote-tracking branch 'origin/tarif' into tarif
hf-kklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||
| """ | ||||||
| Contains Tarif class and corresponding marshmallow schema for de-/serialization | ||||||
| """ | ||||||
|
|
||||||
| from datetime import datetime | ||||||
| from typing import List, Optional | ||||||
|
|
||||||
| import attr | ||||||
| from marshmallow import fields | ||||||
|
|
||||||
| from bo4e.bo.tarifinfo import Tarifinfo, TarifinfoSchema | ||||||
| from bo4e.com.aufabschlagregional import AufAbschlagRegional, AufAbschlagRegionalSchema | ||||||
| from bo4e.com.preisgarantie import Preisgarantie, PreisgarantieSchema | ||||||
| from bo4e.com.tarifberechnungsparameter import Tarifberechnungsparameter, TarifberechnungsparameterSchema | ||||||
| from bo4e.com.tarifeinschraenkung import Tarifeinschraenkung, TarifeinschraenkungSchema | ||||||
| from bo4e.com.tarifpreispositionproort import TarifpreispositionProOrt, TarifpreispositionProOrtSchema | ||||||
| from bo4e.enum.botyp import BoTyp | ||||||
| from bo4e.validators import check_list_length_at_least_one | ||||||
|
|
||||||
|
|
||||||
| # pylint: disable=too-few-public-methods | ||||||
| @attr.s(auto_attribs=True, kw_only=True) | ||||||
| class Tarif(Tarifinfo): | ||||||
| """ | ||||||
| Abbildung eines Tarifs mit regionaler Zuordnung von Preisen und Auf- und Abschlägen | ||||||
| """ | ||||||
|
|
||||||
| bo_typ: BoTyp = attr.ib(default=BoTyp.TARIF) | ||||||
| # required attributes | ||||||
| #: Gibt an, wann der Preis zuletzt angepasst wurde | ||||||
| preisstand: datetime = attr.ib(validator=attr.validators.instance_of(datetime)) | ||||||
| #: Für die Berechnung der Kosten sind die hier abgebildeten Parameter heranzuziehen | ||||||
| berechnungsparameter: Tarifberechnungsparameter = attr.ib( | ||||||
| validator=attr.validators.instance_of(Tarifberechnungsparameter) | ||||||
| ) | ||||||
| #: Die festgelegten Preise mit regionaler Eingrenzung z.B. für Arbeitspreis, Grundpreis etc. | ||||||
| tarifpreise: List[TarifpreispositionProOrt] = attr.ib( | ||||||
| validator=attr.validators.deep_iterable( | ||||||
| member_validator=attr.validators.instance_of(TarifpreispositionProOrt), | ||||||
| iterable_validator=check_list_length_at_least_one, | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| # optional attributes | ||||||
| #: Auf- und Abschläge auf die Preise oder Kosten mit regionaler Eingrenzung | ||||||
| tarif_auf_abschlaege: Optional[List[AufAbschlagRegional]] = attr.ib( | ||||||
| default=None, | ||||||
| validator=attr.validators.optional( | ||||||
| attr.validators.deep_iterable( | ||||||
| member_validator=attr.validators.instance_of(AufAbschlagRegional), | ||||||
| iterable_validator=attr.validators.instance_of(list), | ||||||
| ) | ||||||
| ), | ||||||
| ) | ||||||
| # todo: fix inconsistency: RegionalerAufAbschlag vs. AufAbschlagRegional | ||||||
| # https://github.com/Hochfrequenz/BO4E-python/issues/345 | ||||||
|
|
||||||
| #: Preisgarantie für diesen Tarif | ||||||
| preisgarantie: Optional[Preisgarantie] = attr.ib( | ||||||
| default=None, | ||||||
| validator=attr.validators.optional( | ||||||
| attr.validators.instance_of(Preisgarantie), | ||||||
| ), | ||||||
| ) | ||||||
| # todo: fix inconsistency with regionaltarif https://github.com/Hochfrequenz/BO4E-python/issues/346 | ||||||
| #: Die Bedingungen und Einschränkungen unter denen ein Tarif angewendet werden kann | ||||||
| tarifeinschraenkung: Optional[Tarifeinschraenkung] = attr.ib( | ||||||
| default=None, validator=attr.validators.optional(attr.validators.instance_of(Tarifeinschraenkung)) | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class TarifSchema(TarifinfoSchema): | ||||||
| """ | ||||||
| Schema for de-/serialization of Tarif | ||||||
| """ | ||||||
|
|
||||||
| class_name = Tarif # type:ignore[assignment] | ||||||
|
|
||||||
| # required attributes | ||||||
| preisstand = fields.DateTime() | ||||||
| berechnungsparameter = fields.Nested(TarifberechnungsparameterSchema) | ||||||
| tarifpreise = fields.List(fields.Nested(TarifpreispositionProOrtSchema)) | ||||||
|
|
||||||
| # optional attributes | ||||||
| tarif_auf_abschlaege = fields.List( | ||||||
| fields.Nested(AufAbschlagRegionalSchema), allow_none=True, data_key="tarifAufAbschlaege" | ||||||
| ) | ||||||
| preisgarantie = fields.Nested(PreisgarantieSchema, allow_none=True) | ||||||
| tarifeinschraenkung = fields.Nested(TarifeinschraenkungSchema, allow_none=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Contains TarifpreispositionProOrt class | ||
| and corresponding marshmallow schema for de-/serialization | ||
| """ | ||
|
|
||
| from typing import List | ||
|
|
||
| import attr | ||
| from marshmallow import fields | ||
|
|
||
| from bo4e.com.com import COM, COMSchema | ||
| from bo4e.com.tarifpreisstaffelproort import TarifpreisstaffelProOrt, TarifpreisstaffelProOrtSchema | ||
| from bo4e.validators import check_list_length_at_least_one | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class TarifpreispositionProOrt(COM): | ||
| """ | ||
| Mit dieser Komponente können Tarifpreise verschiedener Typen abgebildet werden | ||
| """ | ||
|
|
||
| # required attributes | ||
| #: Postleitzahl des Ortes für den der Preis gilt | ||
| postleitzahl: str = attr.ib(validator=attr.validators.matches_re(r"^\d{5}$")) | ||
| #: Ort für den der Preis gilt | ||
| ort: str = attr.ib(validator=attr.validators.instance_of(str)) | ||
| #: ene't-Netznummer des Netzes in dem der Preis gilt | ||
| netznr: str = attr.ib(validator=attr.validators.instance_of(str)) | ||
| # Hier sind die Staffeln mit ihren Preisenangaben definiert | ||
| preisstaffeln: List[TarifpreisstaffelProOrt] = attr.ib( | ||
| validator=[ | ||
| attr.validators.deep_iterable( | ||
| member_validator=attr.validators.instance_of(TarifpreisstaffelProOrt), | ||
| iterable_validator=check_list_length_at_least_one, | ||
| ), | ||
| ] | ||
| ) | ||
| # there are no optional attributes | ||
|
|
||
|
|
||
| class TarifpreispositionProOrtSchema(COMSchema): | ||
| """ | ||
| Schema for de-/serialization of TarifpreispositionProOrt. | ||
| """ | ||
|
|
||
| class_name = TarifpreispositionProOrt | ||
| # required attributes | ||
| postleitzahl = fields.Str() | ||
| ort = fields.Str() | ||
| netznr = fields.Str() | ||
| preisstaffeln = fields.List(fields.Nested(TarifpreisstaffelProOrtSchema)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """ | ||
| Contains TarifpreisstaffelProOrt class | ||
| and corresponding marshmallow schema for de-/serialization | ||
| """ | ||
| from decimal import Decimal | ||
|
|
||
| import attr | ||
| from marshmallow import fields | ||
|
|
||
| from bo4e.com.com import COM, COMSchema | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class TarifpreisstaffelProOrt(COM): | ||
| """ | ||
| Gibt die Staffelgrenzen der jeweiligen Preise an | ||
| """ | ||
|
|
||
| # todo: decimal doesn't make sense here imo | ||
| # https://github.com/Hochfrequenz/BO4E-python/issues/344 | ||
|
|
||
| # required attributes | ||
| #: Der Arbeitspreis in ct/kWh | ||
| arbeitspreis: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal)) | ||
| #: Der Arbeitspreis für Verbräuche in der Niedertarifzeit in ct/kWh | ||
| arbeitspreis_n_t: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal)) | ||
| #: Der Grundpreis in Euro/Jahr | ||
| grundpreis: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal)) | ||
| #: Unterer Wert, ab dem die Staffel gilt (inklusive) | ||
| staffelgrenze_von: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal)) | ||
| #: Oberer Wert, bis zu dem die Staffel gilt (exklusive) | ||
| staffelgrenze_bis: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal)) | ||
|
|
||
| # there are no optional attributes | ||
|
|
||
|
|
||
| class TarifpreisstaffelProOrtSchema(COMSchema): | ||
| """ | ||
| Schema for (de)serialization of TarifpreisstaffelProOrt | ||
| """ | ||
|
|
||
| class_name = TarifpreisstaffelProOrt | ||
|
|
||
| # required attributes | ||
| arbeitspreis = fields.Decimal(as_string=True) | ||
| arbeitspreis_n_t = fields.Decimal(as_string=True, data_key="arbeitspreisNT") | ||
| grundpreis = fields.Decimal(as_string=True) | ||
| staffelgrenze_von = fields.Decimal(as_string=True, data_key="staffelgrenzeVon") | ||
| staffelgrenze_bis = fields.Decimal(as_string=True, data_key="staffelgrenzeBis") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||
| from datetime import datetime, timezone | ||||||
|
|
||||||
| import pytest # type:ignore[import] | ||||||
|
|
||||||
| from bo4e.bo.tarif import Tarif, TarifSchema | ||||||
| from bo4e.enum.kundentyp import Kundentyp | ||||||
| from bo4e.enum.sparte import Sparte | ||||||
| from bo4e.enum.tarifart import Tarifart | ||||||
| from bo4e.enum.tarifmerkmal import Tarifmerkmal | ||||||
| from bo4e.enum.tariftyp import Tariftyp | ||||||
| from tests.serialization_helper import assert_serialization_roundtrip # type:ignore[import] | ||||||
| from tests.test_aufabschlagregional import example_aufabschlagregional # type:ignore[import] | ||||||
| from tests.test_energiemix import example_energiemix # type:ignore[import] | ||||||
| from tests.test_marktteilnehmer import example_marktteilnehmer # type:ignore[import] | ||||||
| from tests.test_preisgarantie import example_preisgarantie # type:ignore[import] | ||||||
| from tests.test_regionaletarifpreisposition import example_regionale_tarifpreisposition # type:ignore[import] | ||||||
| from tests.test_tarifberechnungsparameter import example_tarifberechnungsparameter # type:ignore[import] | ||||||
| from tests.test_tarifeinschraenkung import example_tarifeinschraenkung # type:ignore[import] | ||||||
| from tests.test_tarifpreispositionproort import example_tarifpreispositionproort # type:ignore[import] | ||||||
| from tests.test_vertragskonditionen import example_vertragskonditionen # type:ignore[import] | ||||||
| from tests.test_zeitraum import example_zeitraum # type:ignore[import] | ||||||
|
|
||||||
|
|
||||||
| class TestTarif: | ||||||
| @pytest.mark.parametrize( | ||||||
| "tarif", | ||||||
| [ | ||||||
| pytest.param( | ||||||
| Tarif( | ||||||
| preisstand=datetime(2022, 2, 1, 0, 0, 0, tzinfo=timezone.utc), | ||||||
| berechnungsparameter=example_tarifberechnungsparameter, | ||||||
| tarif_auf_abschlaege=[example_aufabschlagregional], | ||||||
| tarifpreise=[example_tarifpreispositionproort], | ||||||
| preisgarantie=example_preisgarantie, | ||||||
| tarifeinschraenkung=example_tarifeinschraenkung, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # below are the attributes of tarifinfo | ||||||
| bezeichnung="foo", | ||||||
| anbietername="der beste stromanbieter", | ||||||
| sparte=Sparte.STROM, | ||||||
| kundentypen=[Kundentyp.PRIVAT, Kundentyp.GEWERBE], | ||||||
| tarifart=Tarifart.MEHRTARIF, | ||||||
| tariftyp=Tariftyp.GRUND_ERSATZVERSORGUNG, | ||||||
| tarifmerkmale=[Tarifmerkmal.HEIZSTROM], | ||||||
| website="https://foo.inv", | ||||||
| bemerkung="super billig aber auch super dreckig", | ||||||
| vertragskonditionen=example_vertragskonditionen, | ||||||
| zeitliche_gueltigkeit=example_zeitraum, | ||||||
| energiemix=example_energiemix, | ||||||
| anbieter=example_marktteilnehmer, | ||||||
| ), | ||||||
| id="required and optional attributes", | ||||||
| ), | ||||||
| pytest.param( | ||||||
| Tarif( | ||||||
| preisstand=datetime(2022, 2, 1, 0, 0, 0, tzinfo=timezone.utc), | ||||||
| berechnungsparameter=example_tarifberechnungsparameter, | ||||||
| tarifpreise=[example_tarifpreispositionproort], | ||||||
| # below are the attributes of tarifinfo | ||||||
| bezeichnung="foo", | ||||||
| anbietername="der beste stromanbieter", | ||||||
| sparte=Sparte.STROM, | ||||||
| kundentypen=[Kundentyp.PRIVAT, Kundentyp.GEWERBE], | ||||||
| tarifart=Tarifart.MEHRTARIF, | ||||||
| tariftyp=Tariftyp.GRUND_ERSATZVERSORGUNG, | ||||||
| tarifmerkmale=[Tarifmerkmal.HEIZSTROM], | ||||||
| anbieter=example_marktteilnehmer, | ||||||
| ), | ||||||
| id="only required attributes", | ||||||
| ), | ||||||
| ], | ||||||
| ) | ||||||
| def test_serialization_roundtrip(self, tarif: Tarif): | ||||||
| """ | ||||||
| Test de-/serialisation | ||||||
| """ | ||||||
| assert_serialization_roundtrip(tarif, TarifSchema()) | ||||||
|
|
||||||
| def test_missing_required_attribute(self): | ||||||
| with pytest.raises(TypeError) as excinfo: | ||||||
| _ = Tarif() | ||||||
| assert "missing 11 required" in str(excinfo.value) # 3 from Tarif + 8 from tarifinfo | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das ist absicht. Da ist die bestehende Doku glaube ich Quatsch. Wir sollten nichts als Plural benennen, was kein Plural ist.