PyCheval 0.3.1__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pycheval-0.3.1 → pycheval-0.3.3}/PKG-INFO +1 -1
- {pycheval-0.3.1 → pycheval-0.3.3}/pyproject.toml +1 -1
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/const.py +1 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/generate.py +35 -28
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/locale/de/LC_MESSAGES/pycheval.mo +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/model.py +27 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/money.py +7 -5
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/type_codes.py +1 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/LICENSE +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/README.md +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/__init__.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/_locale.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/_test_data.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/countries.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/exc.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/format.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/locale/de/LC_MESSAGES/pycheval.po +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/parse.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_common.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_embed.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_extract.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_parse.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/py.typed +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/quantities.py +0 -0
- {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/types.py +0 -0
|
@@ -16,6 +16,7 @@ URN_XRECHNUNG_PROFILE = "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:sta
|
|
|
16
16
|
NS_CII = "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
|
|
17
17
|
NS_RAM = "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" # noqa: E501
|
|
18
18
|
NS_UDT = "urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
|
|
19
|
+
NS_QDT = "urn:un:unece:uncefact:data:standard:QualifiedDataType:100"
|
|
19
20
|
|
|
20
21
|
ALLOWED_ATTACHMENT_MIME_TYPES = (
|
|
21
22
|
"application/pdf",
|
|
@@ -9,7 +9,7 @@ import datetime
|
|
|
9
9
|
import xml.etree.ElementTree as ET
|
|
10
10
|
from base64 import b64encode
|
|
11
11
|
|
|
12
|
-
from .const import NS_CII, NS_RAM, NS_UDT
|
|
12
|
+
from .const import NS_CII, NS_QDT, NS_RAM, NS_UDT
|
|
13
13
|
from .model import (
|
|
14
14
|
BasicInvoice,
|
|
15
15
|
BasicWLInvoice,
|
|
@@ -57,10 +57,15 @@ def xml_date(date: datetime.date) -> str:
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def _date_element(
|
|
60
|
-
parent: ET.Element,
|
|
60
|
+
parent: ET.Element,
|
|
61
|
+
name: str,
|
|
62
|
+
date: datetime.date,
|
|
63
|
+
*,
|
|
64
|
+
qualified: bool = False,
|
|
61
65
|
) -> ET.Element:
|
|
62
66
|
el = ET.SubElement(parent, name)
|
|
63
|
-
|
|
67
|
+
prefix = "qdt" if qualified else "udt"
|
|
68
|
+
date_el = ET.SubElement(el, f"{prefix}:DateTimeString", format="102")
|
|
64
69
|
date_el.text = "{:04d}{:02d}{:02d}".format(date.year, date.month, date.day)
|
|
65
70
|
return el
|
|
66
71
|
|
|
@@ -118,18 +123,18 @@ def _email_element(
|
|
|
118
123
|
|
|
119
124
|
def _address_element(parent: ET.Element, address: PostalAddress) -> None:
|
|
120
125
|
root = ET.SubElement(parent, "ram:PostalTradeAddress")
|
|
121
|
-
if address.post_code
|
|
126
|
+
if address.post_code:
|
|
122
127
|
ET.SubElement(root, "ram:PostcodeCode").text = address.post_code
|
|
123
|
-
if address.line_one
|
|
128
|
+
if address.line_one:
|
|
124
129
|
ET.SubElement(root, "ram:LineOne").text = address.line_one
|
|
125
|
-
if address.line_two
|
|
130
|
+
if address.line_two:
|
|
126
131
|
ET.SubElement(root, "ram:LineTwo").text = address.line_two
|
|
127
|
-
if address.line_three
|
|
132
|
+
if address.line_three:
|
|
128
133
|
ET.SubElement(root, "ram:LineThree").text = address.line_three
|
|
129
|
-
if address.city
|
|
134
|
+
if address.city:
|
|
130
135
|
ET.SubElement(root, "ram:CityName").text = address.city
|
|
131
136
|
ET.SubElement(root, "ram:CountryID").text = address.country_code
|
|
132
|
-
if address.country_subdivision
|
|
137
|
+
if address.country_subdivision:
|
|
133
138
|
ET.SubElement(
|
|
134
139
|
root, "ram:CountrySubDivisionName"
|
|
135
140
|
).text = address.country_subdivision
|
|
@@ -157,28 +162,28 @@ def _generate_trade_party(
|
|
|
157
162
|
ET.SubElement(el, "ram:ID").text = id
|
|
158
163
|
for global_id in party.global_ids:
|
|
159
164
|
_scheme_id_element(el, "ram:GlobalID", global_id)
|
|
160
|
-
if party.name
|
|
165
|
+
if party.name:
|
|
161
166
|
ET.SubElement(el, "ram:Name").text = party.name
|
|
162
|
-
if party.description
|
|
167
|
+
if party.description:
|
|
163
168
|
ET.SubElement(el, "ram:Description").text = party.description
|
|
164
|
-
if party.legal_id
|
|
169
|
+
if party.legal_id or party.trading_business_name:
|
|
165
170
|
legal_el = ET.SubElement(el, "ram:SpecifiedLegalOrganization")
|
|
166
|
-
if party.legal_id
|
|
171
|
+
if party.legal_id:
|
|
167
172
|
_scheme_id_element(legal_el, "ram:ID", party.legal_id)
|
|
168
|
-
if party.trading_business_name
|
|
173
|
+
if party.trading_business_name:
|
|
169
174
|
ET.SubElement(
|
|
170
175
|
legal_el, "ram:TradingBusinessName"
|
|
171
176
|
).text = party.trading_business_name
|
|
172
|
-
if party.contact
|
|
177
|
+
if party.contact:
|
|
173
178
|
_generate_trade_contact(el, party.contact)
|
|
174
|
-
if party.address
|
|
179
|
+
if party.address:
|
|
175
180
|
_address_element(el, party.address)
|
|
176
|
-
if party.email
|
|
181
|
+
if party.email:
|
|
177
182
|
_email_element(el, "ram:URIUniversalCommunication", party.email)
|
|
178
|
-
if party.tax_number
|
|
183
|
+
if party.tax_number:
|
|
179
184
|
tax = ET.SubElement(el, "ram:SpecifiedTaxRegistration")
|
|
180
185
|
ET.SubElement(tax, "ram:ID", schemeID="FC").text = party.tax_number
|
|
181
|
-
if party.vat_id
|
|
186
|
+
if party.vat_id:
|
|
182
187
|
tax = ET.SubElement(el, "ram:SpecifiedTaxRegistration")
|
|
183
188
|
ET.SubElement(tax, "ram:ID", schemeID="VA").text = party.vat_id
|
|
184
189
|
|
|
@@ -224,14 +229,14 @@ def generate_et(invoice: MinimumInvoice) -> ET.Element:
|
|
|
224
229
|
>>> root = generate_et(invoice)
|
|
225
230
|
"""
|
|
226
231
|
|
|
227
|
-
|
|
228
|
-
"rsm:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
)
|
|
232
|
+
ns = {
|
|
233
|
+
"xmlns:rsm": NS_CII,
|
|
234
|
+
"xmlns:ram": NS_RAM,
|
|
235
|
+
"xmlns:udt": NS_UDT,
|
|
236
|
+
}
|
|
237
|
+
if invoice.has_preceding_invoice_with_date:
|
|
238
|
+
ns["xmlns:qdt"] = NS_QDT
|
|
239
|
+
root = ET.Element("rsm:CrossIndustryInvoice", ns)
|
|
235
240
|
|
|
236
241
|
_generate_doc_context(root, invoice)
|
|
237
242
|
_generate_doc(root, invoice)
|
|
@@ -485,7 +490,9 @@ def _generate_preceding_invoice(
|
|
|
485
490
|
doc_el = ET.SubElement(parent, "ram:InvoiceReferencedDocument")
|
|
486
491
|
ET.SubElement(doc_el, "ram:IssuerAssignedID").text = id
|
|
487
492
|
if date is not None:
|
|
488
|
-
_date_element(
|
|
493
|
+
_date_element(
|
|
494
|
+
doc_el, "ram:FormattedIssueDateTime", date, qualified=True
|
|
495
|
+
)
|
|
489
496
|
|
|
490
497
|
|
|
491
498
|
def _generate_referenced_document(parent: ET.Element, doc: DocRef) -> None:
|
|
Binary file
|
|
@@ -321,6 +321,19 @@ class PostalAddress:
|
|
|
321
321
|
line_three: str | None = None
|
|
322
322
|
|
|
323
323
|
def __post_init__(self) -> None:
|
|
324
|
+
if not self.country_subdivision:
|
|
325
|
+
self.country_subdivision = None
|
|
326
|
+
if not self.post_code:
|
|
327
|
+
self.post_code = None
|
|
328
|
+
if not self.city:
|
|
329
|
+
self.city = None
|
|
330
|
+
if not self.line_one:
|
|
331
|
+
self.line_one = None
|
|
332
|
+
if not self.line_two:
|
|
333
|
+
self.line_two = None
|
|
334
|
+
if not self.line_three:
|
|
335
|
+
self.line_three = None
|
|
336
|
+
|
|
324
337
|
if not validate_iso_3166_1_alpha_2(self.country_code):
|
|
325
338
|
raise ModelError("Invalid ISO 3166-1 alpha-2 country code.")
|
|
326
339
|
|
|
@@ -385,6 +398,15 @@ class MinimumInvoice:
|
|
|
385
398
|
"MINIMUM profile."
|
|
386
399
|
)
|
|
387
400
|
|
|
401
|
+
@property
|
|
402
|
+
def has_preceding_invoice_with_date(self) -> bool:
|
|
403
|
+
"""Whether the invoice has a preceding invoice with a date.
|
|
404
|
+
|
|
405
|
+
This is used to determine whether we need to add the QualifiedDataType
|
|
406
|
+
namespace for the date in the XML.
|
|
407
|
+
"""
|
|
408
|
+
return False
|
|
409
|
+
|
|
388
410
|
|
|
389
411
|
@dataclass
|
|
390
412
|
class BasicWLInvoice(MinimumInvoice):
|
|
@@ -449,6 +471,11 @@ class BasicWLInvoice(MinimumInvoice):
|
|
|
449
471
|
f"{self.PROFILE_NAME} profile."
|
|
450
472
|
)
|
|
451
473
|
|
|
474
|
+
@property
|
|
475
|
+
def has_preceding_invoice_with_date(self) -> bool:
|
|
476
|
+
"""Whether the invoice has a preceding invoice with a date."""
|
|
477
|
+
return any(date is not None for _, date in self.preceding_invoices)
|
|
478
|
+
|
|
452
479
|
|
|
453
480
|
@dataclass
|
|
454
481
|
class BasicInvoice(BasicWLInvoice):
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import locale
|
|
4
4
|
import re
|
|
5
|
-
from decimal import Decimal
|
|
5
|
+
from decimal import ROUND_HALF_UP, Decimal
|
|
6
6
|
from typing import Literal, cast
|
|
7
7
|
|
|
8
8
|
|
|
@@ -42,8 +42,6 @@ class Money:
|
|
|
42
42
|
value.currency,
|
|
43
43
|
):
|
|
44
44
|
return False
|
|
45
|
-
if self.amount.as_tuple().exponent != value.amount.as_tuple().exponent:
|
|
46
|
-
return False
|
|
47
45
|
return True
|
|
48
46
|
|
|
49
47
|
def __repr__(self) -> str:
|
|
@@ -79,11 +77,15 @@ class Money:
|
|
|
79
77
|
return formatted_amount + (separated and " " or "") + currency
|
|
80
78
|
|
|
81
79
|
def __mul__(self, other: Decimal) -> Money:
|
|
82
|
-
value = (self.amount * other).quantize(
|
|
80
|
+
value = (self.amount * other).quantize(
|
|
81
|
+
Decimal("1.00"), rounding=ROUND_HALF_UP
|
|
82
|
+
)
|
|
83
83
|
return Money(value, self.currency)
|
|
84
84
|
|
|
85
85
|
def __truediv__(self, other: Decimal) -> Money:
|
|
86
|
-
value = (self.amount / other).quantize(
|
|
86
|
+
value = (self.amount / other).quantize(
|
|
87
|
+
Decimal("1.00"), rounding=ROUND_HALF_UP
|
|
88
|
+
)
|
|
87
89
|
return Money(value, self.currency)
|
|
88
90
|
|
|
89
91
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|