Skip to content

Commit

Permalink
Added type hints (#36)
Browse files Browse the repository at this point in the history
* Added type hints

* Run black

---------

Co-authored-by: Raphael Michel <[email protected]>
  • Loading branch information
Ayuto and raphaelm authored Oct 4, 2024
1 parent b441c4c commit 9dac70b
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 100 deletions.
5 changes: 3 additions & 2 deletions drafthorse/models/accounting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .container import CurrencyContainer, Container
from . import BASIC, COMFORT, EXTENDED, NS_RAM
from .elements import Element
from .fields import (
Expand Down Expand Up @@ -148,7 +149,7 @@ class MonetarySummation(Element):
tax_total = CurrencyField(
NS_RAM, "TaxTotalAmount", required=True, profile=BASIC, _d="Steuergesamtbetrag"
)
tax_total_other_currency = MultiCurrencyField(
tax_total_other_currency: CurrencyContainer = MultiCurrencyField(
NS_RAM, "TaxTotalAmount", profile=EXTENDED, _d="Steuergesamtbetrag"
)
rounding_amount = DecimalField(
Expand Down Expand Up @@ -239,7 +240,7 @@ class TradeAllowanceCharge(Element):
)
reason_code = StringField(NS_RAM, "ReasonCode", required=False, profile=COMFORT)
reason = StringField(NS_RAM, "Reason", required=False, profile=COMFORT)
trade_tax = MultiField(CategoryTradeTax, required=False, profile=COMFORT)
trade_tax: Container = MultiField(CategoryTradeTax, required=False, profile=COMFORT)

class Meta:
namespace = NS_RAM
Expand Down
24 changes: 16 additions & 8 deletions drafthorse/models/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,36 @@ class Meta:


class SupplyChainConsignment(Element): # TODO: Deprecated?
movement = Field(LogisticsTransportMovement, required=False, profile=EXTENDED)
movement: LogisticsTransportMovement = Field(
LogisticsTransportMovement, required=False, profile=EXTENDED
)

class Meta:
namespace = NS_RAM
tag = "RelatedSupplyChainConsignment"


class TradeDelivery(Element):
consignment = Field(
consignment: SupplyChainConsignment = Field(
SupplyChainConsignment,
default=False,
required=False,
_d="Detailinformationen zur Konsignation oder Sendung",
)
ship_to = Field(ShipToTradeParty, required=False, profile=EXTENDED)
ultimate_ship_to = Field(UltimateShipToTradeParty, required=False, profile=EXTENDED)
ship_from = Field(ShipFromTradeParty, required=False, profile=EXTENDED)
event = Field(SupplyChainEvent, required=False, profile=BASIC)
despatch_advice = Field(
ship_to: ShipToTradeParty = Field(
ShipToTradeParty, required=False, profile=EXTENDED
)
ultimate_ship_to: UltimateShipToTradeParty = Field(
UltimateShipToTradeParty, required=False, profile=EXTENDED
)
ship_from: ShipFromTradeParty = Field(
ShipFromTradeParty, required=False, profile=EXTENDED
)
event: SupplyChainEvent = Field(SupplyChainEvent, required=False, profile=BASIC)
despatch_advice: DespatchAdviceReferencedDocument = Field(
DespatchAdviceReferencedDocument, required=False, profile=EXTENDED
)
delivery_note = Field(
delivery_note: DeliveryNoteReferencedDocument = Field(
DeliveryNoteReferencedDocument, required=False, profile=EXTENDED
)

Expand Down
19 changes: 11 additions & 8 deletions drafthorse/models/document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import xml.etree.cElementTree as ET

from drafthorse.models.note import IncludedNote
from .container import StringContainer, Container
from .note import IncludedNote

from . import BASIC, EXTENDED, NS_A, NS_QDT, NS_RAM, NS_RSM, NS_UDT
from .elements import Element
Expand Down Expand Up @@ -35,13 +36,13 @@ class DocumentContext(Element):
test_indicator = IndicatorField(
NS_RAM, "TestIndicator", required=False, profile=EXTENDED, _d="Testkennzeichen"
)
business_parameter = Field(
business_parameter: BusinessDocumentContextParameter = Field(
BusinessDocumentContextParameter,
required=False,
profile=EXTENDED,
_d="Geschäftsprozess, Wert",
)
guideline_parameter = Field(
guideline_parameter: GuidelineDocumentContextParameter = Field(
GuidelineDocumentContextParameter,
required=True,
profile=BASIC,
Expand Down Expand Up @@ -79,8 +80,10 @@ class Header(Element):
profile=EXTENDED,
_d="Indikator Original/Kopie",
)
languages = MultiStringField(NS_RAM, "LanguageID", required=False, profile=EXTENDED)
notes = MultiField(IncludedNote)
languages: StringContainer = MultiStringField(
NS_RAM, "LanguageID", required=False, profile=EXTENDED
)
notes: Container = MultiField(IncludedNote)
effective_period = Field(
EffectivePeriod,
required=False,
Expand All @@ -94,9 +97,9 @@ class Meta:


class Document(Element):
context = Field(DocumentContext, required=True)
header = Field(Header, required=True)
trade = Field(TradeTransaction, required=True)
context: DocumentContext = Field(DocumentContext, required=True)
header: Header = Field(Header, required=True)
trade: TradeTransaction = Field(TradeTransaction, required=True)

def __init__(self):
super().__init__()
Expand Down
5 changes: 4 additions & 1 deletion drafthorse/models/note.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from .container import StringContainer
from . import BASIC, COMFORT, EXTENDED, NS_RAM
from .elements import Element
from .fields import MultiStringField, StringField


class IncludedNote(Element):
content_code = StringField(NS_RAM, "ContentCode", required=False, profile=EXTENDED)
content = MultiStringField(NS_RAM, "Content", required=False, profile=BASIC)
content: StringContainer = MultiStringField(
NS_RAM, "Content", required=False, profile=BASIC
)
subject_code = StringField(NS_RAM, "SubjectCode", required=False, profile=COMFORT)

class Meta:
Expand Down
25 changes: 15 additions & 10 deletions drafthorse/models/party.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import BASIC, COMFORT, EXTENDED, NS_RAM
from .elements import Element
from .container import Container, IDContainer
from .fields import Field, IDField, MultiField, MultiIDField, StringField


Expand Down Expand Up @@ -68,7 +69,9 @@ class LegalOrganization(Element):
profile=BASIC,
_d="Firmenname, sofern abweichend vom Namen",
)
trade_address = Field(PostalTradeAddress, required=False, profile=EXTENDED)
trade_address: PostalTradeAddress = Field(
PostalTradeAddress, required=False, profile=EXTENDED
)

class Meta:
namespace = NS_RAM
Expand All @@ -80,9 +83,9 @@ class TradeContact(Element):
department_name = StringField(
NS_RAM, "DepartmentName", required=False, profile=EXTENDED
)
telephone = Field(PhoneNumber, required=False, profile=EXTENDED)
fax = Field(FaxNumber, required=False, profile=EXTENDED)
email = Field(EmailURI, required=False, profile=EXTENDED)
telephone: PhoneNumber = Field(PhoneNumber, required=False, profile=EXTENDED)
fax: FaxNumber = Field(FaxNumber, required=False, profile=EXTENDED)
email: EmailURI = Field(EmailURI, required=False, profile=EXTENDED)

class Meta:
namespace = NS_RAM
Expand All @@ -93,7 +96,7 @@ class TradeParty(Element):
id = StringField(
NS_RAM, "ID", required=False, profile=COMFORT, _d="Kennung des Handelspartners"
)
global_id = MultiIDField(
global_id: IDContainer = MultiIDField(
NS_RAM,
"GlobalID",
required=False,
Expand All @@ -108,28 +111,30 @@ class TradeParty(Element):
profile=COMFORT,
_d="Zusätzliche rechliche Informationen des Handelspartners",
)
legal_organization = Field(
legal_organization: LegalOrganization = Field(
LegalOrganization,
required=False,
profile=BASIC,
_d="Handelsinformationen des Handelspartners",
)
contact = Field(
contact: TradeContact = Field(
TradeContact,
required=False,
profile=EXTENDED,
_d="Ansprechpartner des Handelspartners",
)
address = Field(
address: PostalTradeAddress = Field(
PostalTradeAddress,
required=False,
profile=BASIC,
_d="Anschrift des Handelspartners",
)
electronic_address = MultiField(
electronic_address: Container = MultiField(
URIUniversalCommunication, required=False, profile=BASIC
)
tax_registrations = MultiField(TaxRegistration, required=False, profile=BASIC)
tax_registrations: Container = MultiField(
TaxRegistration, required=False, profile=BASIC
)


class SellerTaxRepresentativeTradeParty(TradeParty):
Expand Down
17 changes: 9 additions & 8 deletions drafthorse/models/payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import BASIC, COMFORT, EXTENDED, NS_RAM
from .elements import Element
from .container import StringContainer, CurrencyContainer
from .fields import (
DateTimeField,
DecimalField,
Expand Down Expand Up @@ -48,13 +49,13 @@ class Meta:

class PaymentMeans(Element):
type_code = StringField(NS_RAM, "TypeCode", required=True, profile=COMFORT)
information = MultiStringField(
information: StringContainer = MultiStringField(
NS_RAM, "Information", required=False, profile=COMFORT
)
financial_card = Field(FinancialCard)
payer_account = Field(PayerFinancialAccount)
payee_account = Field(PayeeFinancialAccount)
payee_institution = Field(PayeeFinancialInstitution)
financial_card: FinancialCard = Field(FinancialCard)
payer_account: PayerFinancialAccount = Field(PayerFinancialAccount)
payee_account: PayeeFinancialAccount = Field(PayeeFinancialAccount)
payee_institution: PayeeFinancialInstitution = Field(PayeeFinancialInstitution)

class Meta:
namespace = NS_RAM
Expand Down Expand Up @@ -182,20 +183,20 @@ class PaymentTerms(Element):
debit_mandate_id = StringField(
NS_RAM, "DirectDebitMandateID", required=False, profile=BASIC
)
partial_amount = MultiCurrencyField(
partial_amount: CurrencyContainer = MultiCurrencyField(
NS_RAM,
"PartialPaymentAmount",
profile=EXTENDED,
required=False,
_d="Betrag der Teilzahlung",
)
penalty_terms = Field(
penalty_terms: PaymentPenaltyTerms = Field(
PaymentPenaltyTerms,
required=False,
profile=EXTENDED,
_d="Detailinformationen zu Zahlungszuschlägen",
)
discount_terms = Field(
discount_terms: PaymentDiscountTerms = Field(
PaymentDiscountTerms,
required=False,
profile=EXTENDED,
Expand Down
17 changes: 12 additions & 5 deletions drafthorse/models/product.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import COMFORT, EXTENDED, NS_RAM
from .container import Container
from .elements import Element
from .fields import (
ClassificationField,
Expand Down Expand Up @@ -94,11 +95,17 @@ class TradeProduct(Element):
)
name = StringField(NS_RAM, "Name", required=False)
description = StringField(NS_RAM, "Description", required=False, profile=COMFORT)
characteristics = MultiField(ProductCharacteristic, required=False, profile=COMFORT)
classifications = MultiField(ProductClassification, required=False, profile=COMFORT)
instance = MultiField(ProductInstance, required=False, profile=EXTENDED)
origins = MultiField(OriginCountry, required=False, profile=COMFORT)
included_products = MultiField(ReferencedProduct, required=False, profile=EXTENDED)
characteristics: Container = MultiField(
ProductCharacteristic, required=False, profile=COMFORT
)
classifications: Container = MultiField(
ProductClassification, required=False, profile=COMFORT
)
instance: Container = MultiField(ProductInstance, required=False, profile=EXTENDED)
origins: Container = MultiField(OriginCountry, required=False, profile=COMFORT)
included_products: Container = MultiField(
ReferencedProduct, required=False, profile=EXTENDED
)

class Meta:
namespace = NS_RAM
Expand Down
Loading

0 comments on commit 9dac70b

Please sign in to comment.