From 2d46c868a7ac0844dbc3bd92790ea44bbb05b9d5 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 3 Aug 2022 17:33:20 +0200 Subject: [PATCH] Run black and isort --- drafthorse/models/accounting.py | 24 ++++++++-------------- drafthorse/models/delivery.py | 8 ++++++-- drafthorse/models/document.py | 9 +++------ drafthorse/models/elements.py | 13 +++++++++--- drafthorse/models/fields.py | 4 +++- drafthorse/models/party.py | 4 +++- drafthorse/models/payment.py | 9 ++------- drafthorse/models/product.py | 4 +++- drafthorse/models/references.py | 10 +++------ drafthorse/models/trade.py | 36 ++++++++++++--------------------- drafthorse/models/tradelines.py | 22 +++++++++----------- drafthorse/pdf.py | 18 ++++++++--------- setup.py | 1 - tests/test_mininal.py | 10 ++++++--- tests/test_roundtrip.py | 11 ++++++---- 15 files changed, 86 insertions(+), 97 deletions(-) diff --git a/drafthorse/models/accounting.py b/drafthorse/models/accounting.py index cfa9072..ccd2808 100644 --- a/drafthorse/models/accounting.py +++ b/drafthorse/models/accounting.py @@ -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" diff --git a/drafthorse/models/delivery.py b/drafthorse/models/delivery.py index 886a367..0bb88f4 100644 --- a/drafthorse/models/delivery.py +++ b/drafthorse/models/delivery.py @@ -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): diff --git a/drafthorse/models/document.py b/drafthorse/models/document.py index 0b110da..25ce6f0 100644 --- a/drafthorse/models/document.py +++ b/drafthorse/models/document.py @@ -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 diff --git a/drafthorse/models/elements.py b/drafthorse/models/elements.py index 3d0062c..2c60626 100644 --- a/drafthorse/models/elements.py +++ b/drafthorse/models/elements.py @@ -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): diff --git a/drafthorse/models/fields.py b/drafthorse/models/fields.py index bf238d7..77fd0be 100644 --- a/drafthorse/models/fields.py +++ b/drafthorse/models/fields.py @@ -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: diff --git a/drafthorse/models/party.py b/drafthorse/models/party.py index 6aeb6fc..9290f82 100644 --- a/drafthorse/models/party.py +++ b/drafthorse/models/party.py @@ -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: diff --git a/drafthorse/models/payment.py b/drafthorse/models/payment.py index 6c3e6c0..28a8f50 100644 --- a/drafthorse/models/payment.py +++ b/drafthorse/models/payment.py @@ -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, ) diff --git a/drafthorse/models/product.py b/drafthorse/models/product.py index 9e6ac01..440a6b7 100644 --- a/drafthorse/models/product.py +++ b/drafthorse/models/product.py @@ -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): diff --git a/drafthorse/models/references.py b/drafthorse/models/references.py index 30e4f87..e1a73a1 100644 --- a/drafthorse/models/references.py +++ b/drafthorse/models/references.py @@ -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 ) diff --git a/drafthorse/models/trade.py b/drafthorse/models/trade.py index 4840aac..6be8c3c 100644 --- a/drafthorse/models/trade.py +++ b/drafthorse/models/trade.py @@ -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 ) diff --git a/drafthorse/models/tradelines.py b/drafthorse/models/tradelines.py index 79a69ad..c941deb 100644 --- a/drafthorse/models/tradelines.py +++ b/drafthorse/models/tradelines.py @@ -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, ) diff --git a/drafthorse/pdf.py b/drafthorse/pdf.py index f70c8ae..78be49e 100644 --- a/drafthorse/pdf.py +++ b/drafthorse/pdf.py @@ -27,14 +27,10 @@ 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''.encode("utf-8") - tail = u''.encode("utf-8") + head = ''.encode("utf-8") + tail = ''.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)" ), diff --git a/setup.py b/setup.py index 00459eb..7aee4ee 100644 --- 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 diff --git a/tests/test_mininal.py b/tests/test_mininal.py index 7b4bdfc..7c399a9 100644 --- a/tests/test_mininal.py +++ b/tests/test_mininal.py @@ -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") diff --git a/tests/test_roundtrip.py b/tests/test_roundtrip.py index 47c0cc0..c6e9783 100644 --- a/tests/test_roundtrip.py +++ b/tests/test_roundtrip.py @@ -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): -- 2.47.3