Skip to content

Commit 1cb0579

Browse files
committed
Avoid user assigning unimplemented fields on containers.
Before: doc.trade.settlement.payment_means.type_code = "30" was allowed but had no effect as payemnt_means is a container. Now it gives: Traceback (most recent call last): File "/home/mdk/src/python-drafthorse/test.py", line 54, in <module> doc.trade.settlement.payment_means.type_code = "30" # Virement ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Container' object has no attribute 'type_code' and no __dict__ for setting new attributes
1 parent cee3579 commit 1cb0579

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

drafthorse/models/container.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Container:
2+
__slots__ = ("children", "child_type")
3+
24
def __init__(self, child_type):
35
super().__init__()
46
self.children = []
@@ -26,6 +28,8 @@ def add_from_etree(self, root, strict=True):
2628

2729

2830
class SimpleContainer(Container):
31+
__slots__ = ("children", "child_type", "namespace", "tag")
32+
2933
def __init__(self, child_type, namespace, tag):
3034
super().__init__(child_type)
3135
self.namespace = namespace
@@ -51,6 +55,8 @@ def add_from_etree(self, root, strict=True):
5155

5256

5357
class CurrencyContainer(SimpleContainer):
58+
__slots__ = ("children", "child_type", "namespace", "tag")
59+
5460
def empty_element(self):
5561
from .elements import CurrencyElement
5662

@@ -65,6 +71,8 @@ def add_from_etree(self, root, strict=True):
6571

6672

6773
class IDContainer(SimpleContainer):
74+
__slots__ = ("children", "child_type", "namespace", "tag")
75+
6876
def empty_element(self):
6977
from .elements import IDElement
7078

@@ -79,6 +87,8 @@ def add_from_etree(self, root, strict=True):
7987

8088

8189
class StringContainer(SimpleContainer):
90+
__slots__ = ("children", "child_type", "namespace", "tag")
91+
8292
def empty_element(self):
8393
from .elements import StringElement
8494

tests/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from drafthorse.models.document import Document
88
from drafthorse.models.note import IncludedNote
99
from drafthorse.models.party import TaxRegistration
10+
from drafthorse.models.payment import PaymentMeans
11+
from drafthorse.models.trade import AdvancePayment, IncludedTradeTax
1012
from drafthorse.models.tradelines import LineItem
1113

1214

@@ -31,7 +33,7 @@ def invoice_document(request):
3133
doc.trade.settlement.invoicee.name = "Kunde GmbH"
3234

3335
doc.trade.settlement.currency_code = "EUR"
34-
doc.trade.settlement.payment_means.type_code = "ZZZ"
36+
doc.trade.settlement.payment_means.add(PaymentMeans(type_code="ZZZ"))
3537

3638
doc.trade.agreement.seller.address.country_id = "DE"
3739
doc.trade.agreement.seller.address.country_subdivision = "Bayern"
@@ -41,7 +43,18 @@ def invoice_document(request):
4143

4244
doc.trade.agreement.seller_order.issue_date_time = datetime.now(timezone.utc)
4345
doc.trade.agreement.buyer_order.issue_date_time = datetime.now(timezone.utc)
44-
doc.trade.settlement.advance_payment.received_date = datetime.now(timezone.utc)
46+
advance = AdvancePayment(
47+
received_date=datetime.now(timezone.utc), paid_amount=Decimal(42)
48+
)
49+
advance.included_trade_tax.add(
50+
IncludedTradeTax(
51+
calculated_amount=Decimal(0),
52+
type_code="VAT",
53+
category_code="E",
54+
rate_applicable_percent=Decimal(0),
55+
)
56+
)
57+
doc.trade.settlement.advance_payment.add(advance)
4558
doc.trade.agreement.customer_order.issue_date_time = datetime.now(timezone.utc)
4659

4760
li = LineItem()

0 commit comments

Comments
 (0)