]> git.ipfire.org Git - thirdparty/python-drafthorse.git/commitdiff
Run black and isort
authorRaphael Michel <michel@rami.io>
Wed, 3 Aug 2022 15:33:20 +0000 (17:33 +0200)
committerRaphael Michel <michel@rami.io>
Wed, 3 Aug 2022 15:33:20 +0000 (17:33 +0200)
15 files changed:
drafthorse/models/accounting.py
drafthorse/models/delivery.py
drafthorse/models/document.py
drafthorse/models/elements.py
drafthorse/models/fields.py
drafthorse/models/party.py
drafthorse/models/payment.py
drafthorse/models/product.py
drafthorse/models/references.py
drafthorse/models/trade.py
drafthorse/models/tradelines.py
drafthorse/pdf.py
setup.py
tests/test_mininal.py
tests/test_roundtrip.py

index cfa9072a238dbc9b3a1088e2a377ba33aaace8fa..ccd2808e6fccaf7528e2b2e6db6bbcc8c6548dcd 100644 (file)
@@ -1,14 +1,8 @@
 from . import BASIC, COMFORT, EXTENDED, NS_RAM
 from .elements import Element
 from .fields import (
-    CurrencyField,
-    DateTimeField,
-    DecimalField,
-    IndicatorField,
-    MultiField,
-    QuantityField,
-    StringField,
-    MultiCurrencyField,
+    CurrencyField, DateTimeField, DecimalField, IndicatorField,
+    MultiCurrencyField, MultiField, QuantityField, StringField,
 )
 
 
@@ -91,10 +85,7 @@ class ApplicableTradeTax(Element):
         _d="Grund der Steuerbefreiung (Code)",
     )
     tax_point_date = DateTimeField(
-        NS_RAM,
-        "TaxPointDate",
-        required=False,
-        profile=COMFORT
+        NS_RAM, "TaxPointDate", required=False, profile=COMFORT
     )
     due_date_type_code = StringField(
         NS_RAM,
@@ -153,9 +144,7 @@ class ReceivableAccountingAccount(Element):
     id = StringField(
         NS_RAM, "ID", required=True, profile=EXTENDED, _d="Buchungsreferenz"
     )
-    type_code = StringField(
-        NS_RAM, "TypeCode", required=True, profile=EXTENDED
-    )
+    type_code = StringField(NS_RAM, "TypeCode", required=True, profile=EXTENDED)
 
     class Meta:
         namespace = NS_RAM
@@ -198,7 +187,10 @@ class MonetarySummation(Element):
         NS_RAM, "TaxTotalAmount", profile=EXTENDED, _d="Steuergesamtbetrag"
     )
     rounding_amount = DecimalField(
-        NS_RAM, "RoundingAmount", required=False, profile=COMFORT,
+        NS_RAM,
+        "RoundingAmount",
+        required=False,
+        profile=COMFORT,
     )
     grand_total = CurrencyField(
         NS_RAM, "GrandTotalAmount", required=True, profile=BASIC, _d="Bruttosumme"
index 886a367f94a5fcbf6dfce28db642714ac2da727c..0bb88f444abdccc4988e6b99f459bbe7c7331583 100644 (file)
@@ -1,8 +1,12 @@
 from . import BASIC, EXTENDED, NS_RAM
 from .elements import Element
 from .fields import DateTimeField, Field, StringField
-from .party import ShipFromTradeParty, ShipToTradeParty, UltimateShipToTradeParty
-from .references import DeliveryNoteReferencedDocument, DespatchAdviceReferencedDocument
+from .party import (
+    ShipFromTradeParty, ShipToTradeParty, UltimateShipToTradeParty,
+)
+from .references import (
+    DeliveryNoteReferencedDocument, DespatchAdviceReferencedDocument,
+)
 
 
 class SupplyChainEvent(Element):
index 0b110dad685fc7f3ba5a48cddb68b832ec9258a6..25ce6f0d9daf9f5890ffc52f33a89eb5ab8181b8 100644 (file)
@@ -1,14 +1,11 @@
 import xml.etree.cElementTree as ET
 
 from drafthorse.models.note import IncludedNote
-from . import BASIC, EXTENDED, NS_RAM, NS_UDT, NS_RSM, NS_QDT, NS_A
+
+from . import BASIC, EXTENDED, NS_A, NS_QDT, NS_RAM, NS_RSM, NS_UDT
 from .elements import Element
 from .fields import (
-    DateTimeField,
-    Field,
-    IndicatorField,
-    MultiField,
-    MultiStringField,
+    DateTimeField, Field, IndicatorField, MultiField, MultiStringField,
     StringField,
 )
 from .trade import TradeTransaction
index 3d0062cab51bf06c8d2d2c1d9f329c350fffe72d..2c60626ca44fe50aca3a7d41d385e0f4a9c5d995 100644 (file)
@@ -6,6 +6,7 @@ from datetime import datetime
 from decimal import Decimal
 
 from drafthorse.utils import validate_xml
+
 from . import NS_UDT
 from .container import Container
 from .fields import Field
@@ -70,10 +71,16 @@ class Element(metaclass=BaseElementMeta):
             self.to_etree(), "utf-8"
         )
         return validate_xml(xmlout=xml, schema=schema)
-    
+
     def __setattr__(self, key, value):
-        if not hasattr(self, key) and not key.startswith("_") and not key in ("required",):
-            raise AttributeError(f"Element {type(self)} has no attribute '{key}'. If you set it, it would not be included in the output.")
+        if (
+            not hasattr(self, key)
+            and not key.startswith("_")
+            and not key in ("required",)
+        ):
+            raise AttributeError(
+                f"Element {type(self)} has no attribute '{key}'. If you set it, it would not be included in the output."
+            )
         return super().__setattr__(key, value)
 
     def from_etree(self, root):
index bf238d7fc026314f6d1d836088e72fb5f6aa6571..77fd0bea6d058360e27493856e8926776de88c28 100644 (file)
@@ -1,7 +1,9 @@
 from decimal import Decimal
 
 from . import BASIC
-from .container import Container, CurrencyContainer, IDContainer, StringContainer
+from .container import (
+    Container, CurrencyContainer, IDContainer, StringContainer,
+)
 
 
 class Field:
index 6aeb6fc8e0ab0bc9cf1daf7c069e0a4fea99e000..9290f8223477bbe3b1ba314f60e51b900123917e 100644 (file)
@@ -9,7 +9,9 @@ class PostalTradeAddress(Element):
     line_two = StringField(NS_RAM, "LineTwo", required=False, profile=BASIC)
     line_three = StringField(NS_RAM, "LineThree", required=False, profile=BASIC)
     city_name = StringField(NS_RAM, "CityName", required=False, profile=BASIC)
-    country_subdivision = StringField(NS_RAM, "CountrySubDivisionName", required=False, profile=EXTENDED)
+    country_subdivision = StringField(
+        NS_RAM, "CountrySubDivisionName", required=False, profile=EXTENDED
+    )
     country_id = StringField(NS_RAM, "CountryID", required=False, profile=BASIC)
 
     class Meta:
index 6c3e6c00b94e4b67926f91b317d51534475c74b2..28a8f50d332421e813764bf56602fa1027e9f1ac 100644 (file)
@@ -1,13 +1,8 @@
 from . import BASIC, COMFORT, EXTENDED, NS_RAM
 from .elements import Element
 from .fields import (
-    DateTimeField,
-    DecimalField,
-    Field,
-    MultiStringField,
-    QuantityField,
-    StringField,
-    MultiCurrencyField,
+    DateTimeField, DecimalField, Field, MultiCurrencyField, MultiStringField,
+    QuantityField, StringField,
 )
 
 
index 9e6ac018a6f89ea79c02a1238a275e70f4549043..440a6b778b44fd40018af589c708dc81d4e76c89 100644 (file)
@@ -1,6 +1,8 @@
 from . import COMFORT, EXTENDED, NS_RAM
 from .elements import Element
-from .fields import ClassificationField, IDField, MultiField, QuantityField, StringField
+from .fields import (
+    ClassificationField, IDField, MultiField, QuantityField, StringField,
+)
 
 
 class ProductCharacteristic(Element):
index 30e4f877619f4a06d7b21e4a626f43254d3deafe..e1a73a1eca2396030a01ee39bb77f5ac21f123e8 100644 (file)
@@ -1,6 +1,6 @@
 from . import COMFORT, EXTENDED, NS_RAM
 from .elements import Element
-from .fields import DirectDateTimeField, StringField, BinaryObjectField
+from .fields import BinaryObjectField, DirectDateTimeField, StringField
 
 
 class ProcuringProjectType(Element):
@@ -125,12 +125,8 @@ class LineAdditionalReferencedDocument(Element):
     )
     uri_id = StringField(NS_RAM, "URIID", required=False, profile=EXTENDED)
     line_id = StringField(NS_RAM, "LineID", required=False, profile=EXTENDED)
-    type_code = StringField(
-        NS_RAM, "TypeCode", required=False, profile=EXTENDED
-    )
-    name = StringField(
-        NS_RAM, "Name", required=False, profile=EXTENDED
-    )
+    type_code = StringField(NS_RAM, "TypeCode", required=False, profile=EXTENDED)
+    name = StringField(NS_RAM, "Name", required=False, profile=EXTENDED)
     date_time_string = DirectDateTimeField(
         NS_RAM, "FormattedIssueDateTime", required=False, profile=COMFORT
     )
index 4840aaca11c2e47299b7e112662d353a4b9a0e2d..6be8c3c6aebe1ba3820836956b973e759277dca9 100644 (file)
@@ -1,31 +1,23 @@
 from . import BASIC, COMFORT, EXTENDED, NS_RAM, NS_RSM
 from .accounting import (
-    ApplicableTradeTax,
-    AppliedTradeTax,
-    MonetarySummation,
-    ReceivableAccountingAccount,
-    TradeAllowanceCharge,
-    BillingSpecifiedPeriod,
-    SellerOrderReferencedDocument,
+    ApplicableTradeTax, AppliedTradeTax, BillingSpecifiedPeriod,
+    MonetarySummation, ReceivableAccountingAccount,
+    SellerOrderReferencedDocument, TradeAllowanceCharge,
 )
 from .delivery import TradeDelivery
 from .elements import Element
-from .fields import DecimalField, Field, MultiField, StringField, DateTimeField
+from .fields import DateTimeField, DecimalField, Field, MultiField, StringField
 from .party import (
-    BuyerTradeParty,
-    EndUserTradeParty,
-    InvoiceeTradeParty,
-    PayeeTradeParty,
-    SellerTradeParty,
-    SellerTaxRepresentativeTradeParty, InvoicerTradeParty,
+    BuyerTradeParty, EndUserTradeParty, InvoiceeTradeParty, InvoicerTradeParty,
+    PayeeTradeParty, SellerTaxRepresentativeTradeParty, SellerTradeParty,
+)
+from .payment import (
+    PaymentMeans, PaymentTerms, TaxApplicableTradeCurrencyExchange,
 )
-from .payment import PaymentMeans, PaymentTerms, TaxApplicableTradeCurrencyExchange
 from .references import (
-    AdditionalReferencedDocument,
-    ContractReferencedDocument,
-    UltimateCustomerOrderReferencedDocument,
-    ProcuringProjectType,
-    InvoiceReferencedDocument, BuyerOrderReferencedDocument,
+    AdditionalReferencedDocument, BuyerOrderReferencedDocument,
+    ContractReferencedDocument, InvoiceReferencedDocument,
+    ProcuringProjectType, UltimateCustomerOrderReferencedDocument,
 )
 from .tradelines import LineItem
 
@@ -190,9 +182,7 @@ class TradeSettlement(Element):
         profile=EXTENDED,
         _d="Detailinformationen zur Buchungsreferenz",
     )
-    advance_payment = MultiField(
-        AdvancePayment, required=False, profile=EXTENDED
-    )
+    advance_payment = MultiField(AdvancePayment, required=False, profile=EXTENDED)
     invoice_referenced_document = Field(
         InvoiceReferencedDocument, required=False, profile=BASIC
     )
index 79a69ad2ae2190f860ad980cd8184c66cad4fdab..c941debfc736519a03d9590be212a1ec29721623 100644 (file)
@@ -1,26 +1,22 @@
 from . import BASIC, COMFORT, EXTENDED, NS_RAM
 from .accounting import (
-    AccountingAccount,
-    ApplicableTradeTax,
-    BillingSpecifiedPeriod,
-    TradeAllowanceCharge,
-    ReceivableAccountingAccount,
+    AccountingAccount, ApplicableTradeTax, BillingSpecifiedPeriod,
+    ReceivableAccountingAccount, TradeAllowanceCharge,
 )
 from .delivery import SupplyChainEvent
 from .elements import Element
-from .fields import DecimalField, Field, MultiField, QuantityField, StringField, DateTimeField
+from .fields import (
+    DateTimeField, DecimalField, Field, MultiField, QuantityField, StringField,
+)
 from .note import IncludedNote
 from .party import ShipToTradeParty, UltimateShipToTradeParty
 from .product import TradeProduct
 from .references import (
-    LineAdditionalReferencedDocument,
-    LineBuyerOrderReferencedDocument,
-    LineContractReferencedDocument,
-    LineUltimateCustomerOrderReferencedDocument,
-    LineDeliveryNoteReferencedDocument,
-    LineDespatchAdviceReferencedDocument,
+    InvoiceReferencedDocument, LineAdditionalReferencedDocument,
+    LineBuyerOrderReferencedDocument, LineContractReferencedDocument,
+    LineDeliveryNoteReferencedDocument, LineDespatchAdviceReferencedDocument,
     LineReceivingAdviceReferencedDocument,
-    InvoiceReferencedDocument,
+    LineUltimateCustomerOrderReferencedDocument,
 )
 
 
index f70c8ae743bcb39b72a02d3b4d8169acba7e86af..78be49e28abef2658f3568c53360f2b4c25f73d1 100644 (file)
 import datetime
 import os
 from io import BytesIO
-
 from lxml import etree
 from PyPDF2 import PdfReader, PdfWriter
 from PyPDF2.generic import (
-    ArrayObject,
-    DecodedStreamObject,
-    DictionaryObject,
-    NameObject,
+    ArrayObject, DecodedStreamObject, DictionaryObject, NameObject,
     createStringObject,
 )
 
@@ -165,7 +161,9 @@ def _prepare_pdf_metadata_xml(level, pdf_metadata):
     fx_conformance_level.text = level
 
     xmp_file = os.path.join(
-        os.path.dirname(__file__), "schema", "ZUGFeRD2p2_extension_schema.xmp".format(level)
+        os.path.dirname(__file__),
+        "schema",
+        "ZUGFeRD2p2_extension_schema.xmp".format(level),
     )
     # Reason for defining a parser below:
     # http://lxml.de/FAQ.html#why-doesn-t-the-pretty-print-option-reformat-my-xml-output
@@ -181,8 +179,8 @@ def _prepare_pdf_metadata_xml(level, pdf_metadata):
     xml_str = etree.tostring(
         root, pretty_print=True, encoding="UTF-8", xml_declaration=False
     )
-    head = u'<?xpacket begin="\ufeff" id="W5M0MpCehiHzreSzNTczkc9d"?>'.encode("utf-8")
-    tail = u'<?xpacket end="w"?>'.encode("utf-8")
+    head = '<?xpacket begin="\ufeff" id="W5M0MpCehiHzreSzNTczkc9d"?>'.encode("utf-8")
+    tail = '<?xpacket end="w"?>'.encode("utf-8")
     xml_final_str = head + xml_str + tail
     return xml_final_str
 
@@ -220,7 +218,9 @@ def _facturx_update_metadata_add_attachment(
     fname_obj = createStringObject("factur-x.xml")
     filespec_dict = DictionaryObject(
         {
-            NameObject("/AFRelationship"): NameObject("/Data" if facturx_level in ("BASIC-WL", "MINIMUM") else "/Alternative"),
+            NameObject("/AFRelationship"): NameObject(
+                "/Data" if facturx_level in ("BASIC-WL", "MINIMUM") else "/Alternative"
+            ),
             NameObject("/Desc"): createStringObject(
                 "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)"
             ),
index 00459eb644d70837bdce29b034f1e6d19a90679a..7aee4ee3f6cb329b0b6a74bb268fcdd10a9057b1 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,6 @@
 import sys
 from codecs import open
 from os import path
-
 from setuptools import find_packages, setup
 
 from drafthorse import version
index 7b4bdfc6979a0c1eebc5a8138ca1f2a34f48121c..7c399a996b56cdd1a73293a11814d86655687e88 100644 (file)
@@ -11,7 +11,9 @@ from drafthorse.pdf import attach_xml
 
 def test_readme_construction_example():
     doc = Document()
-    doc.context.guideline_parameter.id = "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended"
+    doc.context.guideline_parameter.id = (
+        "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended"
+    )
     doc.header.id = "RE1337"
     doc.header.type_code = "380"
     doc.header.name = "RECHNUNG"
@@ -62,5 +64,7 @@ def test_readme_construction_example():
     doc.trade.settlement.monetary_summation.due_amount = Decimal("999.00")
 
     xml = doc.serialize(schema="FACTUR-X_EXTENDED")
-    with open(os.path.join(os.path.dirname(__file__), "samples", "Empty.pdf"), "rb") as original_file:
-        assert attach_xml(original_file.read(), xml, 'EXTENDED')
+    with open(
+        os.path.join(os.path.dirname(__file__), "samples", "Empty.pdf"), "rb"
+    ) as original_file:
+        assert attach_xml(original_file.read(), xml, "EXTENDED")
index 47c0cc0b9122d833f1d966d228179554a9b4fcb2..c6e978382d3ec156ea2d53727ad5bef34e197097 100644 (file)
@@ -1,13 +1,16 @@
+import lxml.etree
 import os
-from difflib import unified_diff
-
 import pytest
-import lxml.etree
+from difflib import unified_diff
 
 from drafthorse.models.document import Document
 from drafthorse.utils import prettify, validate_xml
 
-samples = [f for f in os.listdir(os.path.join(os.path.dirname(__file__), "samples")) if f.endswith(".xml")]
+samples = [
+    f
+    for f in os.listdir(os.path.join(os.path.dirname(__file__), "samples"))
+    if f.endswith(".xml")
+]
 
 
 def _diff_xml(a, b):