Skip to content

Commit

Permalink
Add COMs (#5)
Browse files Browse the repository at this point in the history
* Ordner struktur

* Add enums

* 1

* 1

* Add enums

* add COM

* add docstring

* Update requirements.in

Co-authored-by: konstantin <[email protected]>

* Update src/ibims/com/zaehlpunkt.py

Co-authored-by: konstantin <[email protected]>

* Update src/ibims/com/vertragskonto.py

Co-authored-by: konstantin <[email protected]>

* Update src/ibims/com/sepa_info.py

Co-authored-by: konstantin <[email protected]>

* Update src/ibims/com/vertragskonto.py

Co-authored-by: konstantin <[email protected]>

* Update src/ibims/com/concessionfee.py

Co-authored-by: konstantin <[email protected]>

---------

Co-authored-by: konstantin <[email protected]>
  • Loading branch information
FreddyFox892 and hf-kklein authored Sep 15, 2023
1 parent 88824c7 commit 7e3fcdc
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ibims/com/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Bundles extended and new COMs
"""
from ibims.com.adresse import AdresseErweitert
from ibims.com.bankverbindung import Bankverbindung
from ibims.com.concessionfee import ConcessionFee
from ibims.com.preisgarantie import PreisgarantieErweitert
from ibims.com.preisposition import PreispositionErweitert
from ibims.com.rechnungsposition import RechnungspositionErweitert
from ibims.com.sepa_info import SepaInfo
from ibims.com.steuerbetrag import SteuerbetragErweitert
from ibims.com.verbrauch import VerbrauchErweitert
from ibims.com.zaehlpunkt import Zaehlpunkt
from ibims.com.zaehlwerk import ZaehlwerkErweitert
15 changes: 15 additions & 0 deletions src/ibims/com/adresse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
extension for the official bo4e adresse
"""

from typing import Optional

from bo4e.com.adresse import Adresse


class AdresseErweitert(Adresse):
"""
Extend Adresse with attribute ortsteil
"""

ortsteil: Optional[str] = None
87 changes: 87 additions & 0 deletions src/ibims/com/bankverbindung.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
New COM to hold information about banking data
"""
from datetime import datetime
from typing import Optional

from bo4e.com.com import COM
from pydantic import constr, field_validator

from ibims.com import SepaInfo


class Bankverbindung(COM):
"""
This component contains bank connection information.
"""

# required attributes

iban: Optional[constr(min_length=15, max_length=34)] = None # type:ignore[valid-type]
"""
The IBAN (International Bank Account Number) is structured as follows:
# 2-digit: country code
# 2-digit: check digits
# up to 30-digit: account identification
"""
# international variiert die Länge, länge(DE) = 22

bic: Optional[str] = None
"""
The BIC (Business Identifier Code) consists 8 or 11 alphanumeric characters, structured as follows:
# 4-digit: bank code
# 2-digit: country code
# 2-digit: location code
# 3-digit: branch office (optional)
"""

# optional attributes
gueltig_seit: Optional[datetime] = None
"""
Inclusive date from which on the account information is valid
"""
gueltig_bis: Optional[datetime] = None
"""
Inclusive date till which on the account information is valid
"""
bankname: Optional[str] = None #: Name der Bank, z.b. 'Sparkasse Bremen'
"""
Consists the name of the Bank.
"""
sepa_info: Optional[SepaInfo] = None #: Informationen über das SEPA-Mandant
"""
contains an object of the SepaInfo class that contains details about the sepa mandates.
"""
kontoinhaber: Optional[str] = None
"""
contains the name of the account holder in the format 'firstname lastname'
"""
ouid: int
"""
contains the ouid that is need for the paymentMeans in the Customer Loader
"""

# pylint:disable=unused-argument, no-self-argument
@field_validator("iban")
@classmethod
def validate_iban_laenge(cls, iban: str) -> str:
"""
validate the length of the iban.
"""
return iban
# validierung auf ländercod und sonst nur zahlen noch bauen.
# vlaidierung der iban nach https://ibanvalidieren.de/verifikation.html noch einbauen
# bzw. https://de.wikipedia.org/wiki/Internationale_Bankkontonummer#Zusammensetzung international.

@field_validator("bic")
@classmethod
def validate_bic_laenge(cls, bic: str) -> str:
"""
validate the length of the bic.
"""
if len(bic) == 8 or len(bic) == 11:
return bic
raise ValueError("bic has not 8 or 11 characters.")

# validierung auf alphanumerisch noch bauen
28 changes: 28 additions & 0 deletions src/ibims/com/concessionfee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Custom bo4e object, that was created for a migration project
"""

from datetime import datetime

from bo4e.com.com import COM


class ConcessionFee(COM):
# https://github.com/Hochfrequenz/integrated-bo4e-migration-models/issues/7
"""
The Concession Fee object was created during a migration project.
It contains attributes needed for metering mapping.
"""

market_location_id: str
"""market location id of powercloud db"""
group: str | None = None
"""group of the concession fee (e.g. "TA")"""
obis: str
"""obis code"""
active_from: datetime
"""inclusive active_from"""
active_until: datetime | None = None
"""exclusive active_until, None means it is still active"""
ka: str | None = None
"""amount of concession fee"""
18 changes: 18 additions & 0 deletions src/ibims/com/preisgarantie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
A Preisgarantie with MetaData added
"""
from typing import Optional

from bo4e.com.preisgarantie import Preisgarantie
from bo4e.enum.preisgarantietyp import Preisgarantietyp

from ibims.meta import MetaDataMixin


class PreisgarantieErweitert(Preisgarantie, MetaDataMixin):
"""
eine Preisgarantie mit Metadaten
"""

preisgarantietyp: Optional[Preisgarantietyp] = None # type:ignore[assignment]
"""overrides the original preisgarantietyp with a nullable"""
17 changes: 17 additions & 0 deletions src/ibims/com/preisposition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
New COM to hold information about different variations and reasons for account locks
"""

from bo4e.com.preisposition import Preisposition
from bo4e.enum.steuerkennzeichen import Steuerkennzeichen


class PreispositionErweitert(Preisposition):
"""
Extesion of the bo4e Preisposition with taxrate
"""

steuersatz: Steuerkennzeichen
"""
The taxrate is given as a enum
"""
18 changes: 18 additions & 0 deletions src/ibims/com/rechnungsposition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
extension of the official BO4E Rechnungsposition
"""

from typing import Optional

from bo4e.com.rechnungsposition import Rechnungsposition

from ibims.enum import BDEWArtikelnummerErweitert


class RechnungspositionErweitert(Rechnungsposition):
"""
This class extend the com Rechnungsposition by replacing the enum BDEWArtikelnummer
with BDEWArtikelNummerErweitert
"""

artikelnummer: Optional[BDEWArtikelnummerErweitert] = None # type: ignore[assignment]
38 changes: 38 additions & 0 deletions src/ibims/com/sepa_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
New COM for holding information about sepa mandates
"""
from datetime import datetime
from typing import Optional

from bo4e.com.com import COM


class SepaInfo(COM):
"""
This class includes details about the sepa mandates.
"""

# required attributes

sepa_id: str
"""
System internal id of the SEPA mandate.
"""
# muss noch überprüft werden wie es allgemeingültig umzusetzen ist.

sepa_zahler: bool
"""
there may be sepa information regardless of whether it is used or not. this field
confirms the use case e.g. it is false if the customer pays for himself
"""

# optional attributes
creditor_identifier: Optional[str] = None
"""
Creditor Identifier is a number that identify the creditor of the sepa transaction
"""

gueltig_seit: Optional[datetime] = None
"""
Inklusiver Zeitpunkt ab dem das SEPA Mandat gültig ist.
"""
17 changes: 17 additions & 0 deletions src/ibims/com/steuerbetrag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Extension of the official steuerbetrag
"""
from decimal import Decimal
from typing import Optional

from bo4e.com.steuerbetrag import Steuerbetrag


class SteuerbetragErweitert(Steuerbetrag):
"""
This class extends the com Steuerbetrag with the attribute steuerwert_vorausgezahlt, which can also be found in the
go implementation:
https://github.com/Hochfrequenz/go-bo4e/blob/8dda93f8eda51557bb355a93e94c379111f0242b/com/steuerbetrag.go
"""

steuerwert_vorausgezahlt: Optional[Decimal] = None #: tax amount of the prepaid amounts
107 changes: 107 additions & 0 deletions src/ibims/com/verbrauch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
Extend COM Verbrauch to hold various more information
"""

from datetime import datetime
from decimal import Decimal
from typing import Optional

from bo4e.com.verbrauch import Verbrauch
from bo4e.enum.strenum import StrEnum

from ibims.enum import Messwertstatus


class AblesendeRolle(StrEnum):
"""
Eine (Markt)Rolle, die Verbräuche abliest.
"""

VNB = "VNB" #: der verteilnetzbetreiber
ENDKUNDE = "ENDKUNDE" #: der Endkunde selbst
VORIGER_LIEFERANT = "VORIGER_LIEFERANT" #: der vorherige Lieferant hat einen Verbrauch mitgeteilt)
MSB = "MSB" #: der messstellenbetreiber
SYSTEM = "SYSTEM" #: wert ist eine vom system erstellte schätzung


class Ablesungsstatus(StrEnum):
"""
State of the reading
"""

GUELTIG = "GUELTIG"
UNGUELTIG = "UNGUELTIG"
ABGERECHNET = "ABGERECHNET"


class VerbrauchErweitert(Verbrauch):
"""
enhance the consumption object
"""

# see https://github.com/bo4e/BO4E-python/issues/443

# optional attributes
ablesegrund: Optional[str] = None
"""
Reason why the counter is read
"""
ablesebeschreibung: Optional[str] = None
"""
Details to the reading
"""
periodenverbrauch: Optional[Decimal] = None

periodenverbrauch_ursprung: Optional[str] = None

ableser: Optional[AblesendeRolle] = None
"""
from whom is thew reading coming from
"""
status: Optional[Ablesungsstatus] = None
"""
reading status
"""
energiegehalt_gas: Optional[Decimal] = None

energiegehalt_gas_gueltig_von: Optional[datetime] = None
"""
valid from date for the calorific amount (inclusive start)
"""
energiegehalt_gas_gueltig_bis: Optional[datetime] = None
"""
valid to date for the calorific amount (exclusive end)
"""

umwandlungsfaktor_gas: Optional[Decimal] = None

umwandlungsfaktor_gas_gueltig_von: Optional[datetime] = None
"""
valid from date for the conversion factor (inclusive start)
"""
umwandlungsfaktor_gas_gueltig_bis: Optional[datetime] = None
"""
valid to date for the conversion factor (exclusive end)
"""
messwertstatus: Optional[Messwertstatus] = None
"""
the messwertstatus is the status of meter reading
"""

def is_single_tariff(self) -> bool:
"""
Returns true if the consumption is single tariff ("Eintarif")
"""
return "1.8.0" in self.obis_kennzahl

def is_high_tariff(self) -> bool:
"""
Returns true if the consumption is high tariff (HT, "Hochtarif")
"""
return "1.8.1" in self.obis_kennzahl

def is_low_tariff(self) -> bool:
"""
Returns true if the consumption is low tariff (NT, "Niedertarif")
"""
return "1.8.2" in self.obis_kennzahl
Loading

0 comments on commit 7e3fcdc

Please sign in to comment.