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.
Files changed (25) hide show
  1. {pycheval-0.3.1 → pycheval-0.3.3}/PKG-INFO +1 -1
  2. {pycheval-0.3.1 → pycheval-0.3.3}/pyproject.toml +1 -1
  3. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/const.py +1 -0
  4. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/generate.py +35 -28
  5. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/locale/de/LC_MESSAGES/pycheval.mo +0 -0
  6. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/model.py +27 -0
  7. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/money.py +7 -5
  8. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/type_codes.py +1 -0
  9. {pycheval-0.3.1 → pycheval-0.3.3}/LICENSE +0 -0
  10. {pycheval-0.3.1 → pycheval-0.3.3}/README.md +0 -0
  11. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/__init__.py +0 -0
  12. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/_locale.py +0 -0
  13. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/_test_data.py +0 -0
  14. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/countries.py +0 -0
  15. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/exc.py +0 -0
  16. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/format.py +0 -0
  17. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/locale/de/LC_MESSAGES/pycheval.po +0 -0
  18. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/parse.py +0 -0
  19. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_common.py +0 -0
  20. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_embed.py +0 -0
  21. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_extract.py +0 -0
  22. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/pdf_parse.py +0 -0
  23. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/py.typed +0 -0
  24. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/quantities.py +0 -0
  25. {pycheval-0.3.1 → pycheval-0.3.3}/src/pycheval/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyCheval
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Factur-X/ZUGFeRD parsing and generation library for Python
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyCheval"
3
- version = "0.3.1"
3
+ version = "0.3.3"
4
4
  description = "Factur-X/ZUGFeRD parsing and generation library for Python"
5
5
  authors = [{ name = "Sebastian Rittau", email = "sebastian.rittau@zfutura.de" }]
6
6
  readme = "README.md"
@@ -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, name: str, date: datetime.date
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
- date_el = ET.SubElement(el, "udt:DateTimeString", format="102")
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 is not None:
126
+ if address.post_code:
122
127
  ET.SubElement(root, "ram:PostcodeCode").text = address.post_code
123
- if address.line_one is not None:
128
+ if address.line_one:
124
129
  ET.SubElement(root, "ram:LineOne").text = address.line_one
125
- if address.line_two is not None:
130
+ if address.line_two:
126
131
  ET.SubElement(root, "ram:LineTwo").text = address.line_two
127
- if address.line_three is not None:
132
+ if address.line_three:
128
133
  ET.SubElement(root, "ram:LineThree").text = address.line_three
129
- if address.city is not None:
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 is not None:
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 is not None:
165
+ if party.name:
161
166
  ET.SubElement(el, "ram:Name").text = party.name
162
- if party.description is not None:
167
+ if party.description:
163
168
  ET.SubElement(el, "ram:Description").text = party.description
164
- if party.legal_id is not None or party.trading_business_name is not None:
169
+ if party.legal_id or party.trading_business_name:
165
170
  legal_el = ET.SubElement(el, "ram:SpecifiedLegalOrganization")
166
- if party.legal_id is not None:
171
+ if party.legal_id:
167
172
  _scheme_id_element(legal_el, "ram:ID", party.legal_id)
168
- if party.trading_business_name is not None:
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 is not None:
177
+ if party.contact:
173
178
  _generate_trade_contact(el, party.contact)
174
- if party.address is not None:
179
+ if party.address:
175
180
  _address_element(el, party.address)
176
- if party.email is not None:
181
+ if party.email:
177
182
  _email_element(el, "ram:URIUniversalCommunication", party.email)
178
- if party.tax_number is not None:
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 is not None:
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
- root = ET.Element(
228
- "rsm:CrossIndustryInvoice",
229
- {
230
- "xmlns:rsm": NS_CII,
231
- "xmlns:ram": NS_RAM,
232
- "xmlns:udt": NS_UDT,
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(doc_el, "ram:FormattedIssueDateTime", date)
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:
@@ -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(Decimal("1.00"))
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(Decimal("1.00"))
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
 
@@ -121,6 +121,7 @@ class TextSubjectCode(StrEnum):
121
121
  """
122
122
 
123
123
  GENERAL_INFORMATION = "AAI"
124
+ PRICE_CONDITIONS = "AAK"
124
125
  COMMENTS_BY_SELLER = "SUR"
125
126
  REGULATORY_INFORMATION = "REG"
126
127
  LEGAL_INFORMATION = "ABL"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes