PyCheval 0.3.2__tar.gz → 0.4.0__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 (27) hide show
  1. {pycheval-0.3.2 → pycheval-0.4.0}/PKG-INFO +7 -8
  2. {pycheval-0.3.2 → pycheval-0.4.0}/README.md +1 -1
  3. pycheval-0.4.0/pyproject.toml +94 -0
  4. pycheval-0.3.2/pyproject.toml → pycheval-0.4.0/pyproject.toml.orig +15 -11
  5. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/generate.py +69 -50
  6. pycheval-0.4.0/src/pycheval/locale/de/LC_MESSAGES/pycheval.mo +0 -0
  7. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/locale/de/LC_MESSAGES/pycheval.po +65 -57
  8. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/model.py +13 -11
  9. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/money.py +7 -5
  10. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/parse.py +37 -20
  11. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/pdf_embed.py +39 -6
  12. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/type_codes.py +5 -0
  13. pycheval-0.3.2/src/pycheval/locale/de/LC_MESSAGES/pycheval.mo +0 -0
  14. {pycheval-0.3.2 → pycheval-0.4.0}/LICENSE +0 -0
  15. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/__init__.py +0 -0
  16. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/_locale.py +0 -0
  17. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/_test_data.py +0 -0
  18. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/const.py +0 -0
  19. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/countries.py +0 -0
  20. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/exc.py +0 -0
  21. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/format.py +0 -0
  22. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/pdf_common.py +0 -0
  23. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/pdf_extract.py +0 -0
  24. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/pdf_parse.py +0 -0
  25. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/py.typed +0 -0
  26. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/quantities.py +0 -0
  27. {pycheval-0.3.2 → pycheval-0.4.0}/src/pycheval/types.py +0 -0
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyCheval
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: Factur-X/ZUGFeRD parsing and generation library for Python
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
5
  Keywords: factur-x,zugferd,invoice,billing
8
6
  Author: Sebastian Rittau
9
- Author-email: sebastian.rittau@zfutura.de
10
- Requires-Python: >= 3.11
7
+ Author-email: Sebastian Rittau <sebastian.rittau@zfutura.de>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
11
10
  Classifier: Development Status :: 3 - Alpha
12
11
  Classifier: Intended Audience :: Developers
13
12
  Classifier: Topic :: File Formats
14
13
  Classifier: Topic :: Office/Business :: Financial :: Accounting
15
- Requires-Dist: pypdf (>=6.1.1,<7)
14
+ Requires-Dist: pypdf>=7.0.1,<8
15
+ Requires-Python: >=3.11
16
16
  Project-URL: GitHub, https://github.com/zfutura/pycheval
17
17
  Description-Content-Type: text/markdown
18
18
 
@@ -33,7 +33,7 @@ See the [Factur-X website (French)](https://www.factur-x.org/) or
33
33
  [FeRD website (German)](https://www.ferd-net.de/) for more information.
34
34
 
35
35
  This library supports reading and writing PDF and XML files according to
36
- Factur-X Version 1.08 (aka ZUGFeRD 2.4). The following Factur-X profiles
36
+ Factur-X Version 1.09.2 (aka ZUGFeRD 2.5.2). The following Factur-X profiles
37
37
  are currently supported:
38
38
 
39
39
  - Minimum
@@ -121,4 +121,3 @@ that they are suitable for any specific purpose.
121
121
  invoices meet all legal and regulatory requirements for their jurisdiction.
122
122
 
123
123
  See the [LICENSE](LICENSE) file for the complete disclaimer and license terms.
124
-
@@ -15,7 +15,7 @@ See the [Factur-X website (French)](https://www.factur-x.org/) or
15
15
  [FeRD website (German)](https://www.ferd-net.de/) for more information.
16
16
 
17
17
  This library supports reading and writing PDF and XML files according to
18
- Factur-X Version 1.08 (aka ZUGFeRD 2.4). The following Factur-X profiles
18
+ Factur-X Version 1.09.2 (aka ZUGFeRD 2.5.2). The following Factur-X profiles
19
19
  are currently supported:
20
20
 
21
21
  - Minimum
@@ -0,0 +1,94 @@
1
+ [project]
2
+ name = "PyCheval"
3
+ version = "0.4.0"
4
+ description = "Factur-X/ZUGFeRD parsing and generation library for Python"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ keywords = [
9
+ "factur-x",
10
+ "zugferd",
11
+ "invoice",
12
+ "billing",
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Topic :: File Formats",
18
+ "Topic :: Office/Business :: Financial :: Accounting",
19
+ ]
20
+ requires-python = ">= 3.11"
21
+ dependencies = ["pypdf>=7.0.1,<8"]
22
+
23
+ [[project.authors]]
24
+ name = "Sebastian Rittau"
25
+ email = "sebastian.rittau@zfutura.de"
26
+
27
+ [project.urls]
28
+ GitHub = "https://github.com/zfutura/pycheval"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "babel >= 2.17.0, < 3",
33
+ "mypy>=2.3,<2.5",
34
+ "poethepoet >= 0.46.0",
35
+ "pytest >= 9.0.3, < 10",
36
+ "ruff>=0.15.16,<0.18.0",
37
+ ]
38
+
39
+ [tool.uv]
40
+ exclude-newer = "5 days"
41
+
42
+ [tool.uv.build-backend]
43
+ source-include = ["src/pycheval/locale/**/*.mo"]
44
+ source-exclude = ["src/pycheval/test_*"]
45
+
46
+ [tool.poe.tasks.lint]
47
+ cmd = "ruff check src"
48
+ help = "Lint the source code with ruff"
49
+
50
+ [tool.poe.tasks.test]
51
+ cmd = "pytest src"
52
+ help = "Run unit and integration tests with pytest"
53
+
54
+ [tool.poe.tasks.typecheck]
55
+ cmd = "mypy src"
56
+ help = "Type check the source code with mypy"
57
+
58
+ [tool.poe.tasks.i18n-extract]
59
+ cmd = "pybabel extract -o messages.pot src"
60
+ help = "Extract messages for translation"
61
+
62
+ [tool.poe.tasks.i18n-init]
63
+ cmd = "pybabel init -D pycheval -i messages.pot -d src/pycheval/locale -l "
64
+ help = "Initialize translation files for a new language"
65
+
66
+ [tool.poe.tasks.i18n-update]
67
+ cmd = "pybabel update -D pycheval -i messages.pot -d src/pycheval/locale"
68
+ help = "Update translation files from the template"
69
+
70
+ [tool.poe.tasks.i18n-compile]
71
+ cmd = "pybabel compile -D pycheval -d src/pycheval/locale"
72
+ help = "Compile translation files"
73
+
74
+ [tool.ruff]
75
+ target-version = "py312"
76
+ line-length = 79
77
+
78
+ [tool.ruff.lint]
79
+ select = [
80
+ "E",
81
+ "F",
82
+ "B",
83
+ "I",
84
+ ]
85
+
86
+ [tool.ruff.lint.isort]
87
+ combine-as-imports = true
88
+
89
+ [tool.mypy]
90
+ strict = true
91
+
92
+ [build-system]
93
+ requires = ["uv_build>=0.11.19,<0.14"]
94
+ build-backend = "uv_build"
@@ -1,10 +1,11 @@
1
1
  [project]
2
2
  name = "PyCheval"
3
- version = "0.3.2"
3
+ version = "0.4.0"
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"
7
7
  license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
8
9
  keywords = ["factur-x", "zugferd", "invoice", "billing"]
9
10
  classifiers = [
10
11
  "Development Status :: 3 - Alpha",
@@ -14,7 +15,7 @@ classifiers = [
14
15
  ]
15
16
  requires-python = ">= 3.11"
16
17
  dependencies = [
17
- "pypdf >= 6.1.1, < 7",
18
+ "pypdf>=7.0.1,<8",
18
19
  ]
19
20
 
20
21
  [project.urls]
@@ -23,15 +24,18 @@ GitHub = "https://github.com/zfutura/pycheval"
23
24
  [dependency-groups]
24
25
  dev = [
25
26
  "babel >= 2.17.0, < 3",
26
- "mypy ~= 1.18.2",
27
- "poethepoet ~= 0.37.0",
28
- "pytest >= 8.4.2, < 9",
29
- "ruff ~= 0.14.0",
27
+ "mypy>=2.3,<2.5",
28
+ "poethepoet >= 0.46.0",
29
+ "pytest >= 9.0.3, < 10",
30
+ "ruff>=0.15.16,<0.18.0",
30
31
  ]
31
32
 
32
- [tool.poetry]
33
- include = [{ path = "src/pycheval/locale/**/*.mo", format = ["sdist", "wheel"] }]
34
- exclude = ["src/pycheval/test_*"]
33
+ [tool.uv]
34
+ exclude-newer = "5 days"
35
+
36
+ [tool.uv.build-backend]
37
+ source-include = ["src/pycheval/locale/**/*.mo"]
38
+ source-exclude = ["src/pycheval/test_*"]
35
39
 
36
40
  [tool.poe.tasks.lint]
37
41
  cmd = "ruff check src"
@@ -75,5 +79,5 @@ combine-as-imports = true
75
79
  strict = true
76
80
 
77
81
  [build-system]
78
- requires = ["poetry-core"]
79
- build-backend = "poetry.core.masonry.api"
82
+ requires = ["uv_build>=0.11.19,<0.14"]
83
+ build-backend = "uv_build"
@@ -56,17 +56,34 @@ def xml_date(date: datetime.date) -> str:
56
56
  #
57
57
 
58
58
 
59
- def _date_element(
59
+ def _date_time_element(
60
60
  parent: ET.Element,
61
61
  name: str,
62
62
  date: datetime.date,
63
63
  *,
64
64
  qualified: bool = False,
65
65
  ) -> ET.Element:
66
- el = ET.SubElement(parent, name)
66
+ """Generate a DateTimeString element with a date.
67
+
68
+ If qualified is True, use the qualified data type namespace, otherwise
69
+ the unqualified data type namespace.
70
+ """
67
71
  prefix = "qdt" if qualified else "udt"
72
+ el = ET.SubElement(parent, name)
68
73
  date_el = ET.SubElement(el, f"{prefix}:DateTimeString", format="102")
69
- date_el.text = "{:04d}{:02d}{:02d}".format(date.year, date.month, date.day)
74
+ date_el.text = xml_date(date)
75
+ return el
76
+
77
+
78
+ def _date_element(
79
+ parent: ET.Element,
80
+ name: str,
81
+ date: datetime.date,
82
+ ) -> ET.Element:
83
+ """Generate a udt:DateString element with a date."""
84
+ el = ET.SubElement(parent, name)
85
+ date_el = ET.SubElement(el, "udt:DateString", format="102")
86
+ date_el.text = xml_date(date)
70
87
  return el
71
88
 
72
89
 
@@ -115,6 +132,7 @@ def _quantity_element(
115
132
  def _email_element(
116
133
  parent: ET.Element, name: str, email_address: str
117
134
  ) -> ET.Element:
135
+ email_address = email_address.removeprefix("mailto:")
118
136
  el = ET.SubElement(parent, name)
119
137
  sub = ET.SubElement(el, "ram:URIID", schemeID="EM")
120
138
  sub.text = f"mailto:{email_address}"
@@ -162,28 +180,28 @@ def _generate_trade_party(
162
180
  ET.SubElement(el, "ram:ID").text = id
163
181
  for global_id in party.global_ids:
164
182
  _scheme_id_element(el, "ram:GlobalID", global_id)
165
- if party.name is not None:
183
+ if party.name:
166
184
  ET.SubElement(el, "ram:Name").text = party.name
167
- if party.description is not None:
185
+ if party.description:
168
186
  ET.SubElement(el, "ram:Description").text = party.description
169
- if party.legal_id is not None or party.trading_business_name is not None:
187
+ if party.legal_id or party.trading_business_name:
170
188
  legal_el = ET.SubElement(el, "ram:SpecifiedLegalOrganization")
171
- if party.legal_id is not None:
189
+ if party.legal_id:
172
190
  _scheme_id_element(legal_el, "ram:ID", party.legal_id)
173
- if party.trading_business_name is not None:
191
+ if party.trading_business_name:
174
192
  ET.SubElement(
175
193
  legal_el, "ram:TradingBusinessName"
176
194
  ).text = party.trading_business_name
177
- if party.contact is not None:
195
+ if party.contact:
178
196
  _generate_trade_contact(el, party.contact)
179
- if party.address is not None:
197
+ if party.address:
180
198
  _address_element(el, party.address)
181
- if party.email is not None:
199
+ if party.email:
182
200
  _email_element(el, "ram:URIUniversalCommunication", party.email)
183
- if party.tax_number is not None:
201
+ if party.tax_number:
184
202
  tax = ET.SubElement(el, "ram:SpecifiedTaxRegistration")
185
203
  ET.SubElement(tax, "ram:ID", schemeID="FC").text = party.tax_number
186
- if party.vat_id is not None:
204
+ if party.vat_id:
187
205
  tax = ET.SubElement(el, "ram:SpecifiedTaxRegistration")
188
206
  ET.SubElement(tax, "ram:ID", schemeID="VA").text = party.vat_id
189
207
 
@@ -245,10 +263,13 @@ def generate_et(invoice: MinimumInvoice) -> ET.Element:
245
263
  return root
246
264
 
247
265
 
248
- def generate_xml(invoice: MinimumInvoice) -> str:
266
+ def generate_xml(invoice: MinimumInvoice, *, indent: bool = False) -> str:
249
267
  """
250
268
  Generate a Factur-X invoice as XML string.
251
269
 
270
+ If indent is True, indent the generated XML, otherwise, generate a one
271
+ line string.
272
+
252
273
  >>> from datetime import date
253
274
  >>> from decimal import Decimal
254
275
  >>> from pycheval.type_codes import DocumentTypeCode
@@ -265,10 +286,12 @@ def generate_xml(invoice: MinimumInvoice) -> str:
265
286
  ... grand_total_amount=(Decimal("11900.00"), "EUR"),
266
287
  ... due_payable_amount=(Decimal("11900.00"), "EUR"),
267
288
  ... )
268
- >>> xml_string = generate(invoice)
289
+ >>> xml_string = generate_xml(invoice)
269
290
  """
270
291
 
271
292
  root = generate_et(invoice)
293
+ if indent:
294
+ ET.indent(root)
272
295
  return ET.tostring(root, encoding="unicode", xml_declaration=True)
273
296
 
274
297
 
@@ -290,7 +313,7 @@ def _generate_doc(parent: ET.Element, invoice: MinimumInvoice) -> None:
290
313
  doc = ET.SubElement(parent, "rsm:ExchangedDocument")
291
314
  ET.SubElement(doc, "ram:ID").text = invoice.invoice_number
292
315
  ET.SubElement(doc, "ram:TypeCode").text = str(invoice.type_code)
293
- _date_element(doc, "ram:IssueDateTime", invoice.invoice_date)
316
+ _date_time_element(doc, "ram:IssueDateTime", invoice.invoice_date)
294
317
  if isinstance(invoice, BasicWLInvoice):
295
318
  for note in invoice.notes:
296
319
  _note_element(doc, note)
@@ -386,32 +409,30 @@ def _generate_line_trade_agreement(
386
409
  ET.SubElement(
387
410
  doc_el, "ram:LineID"
388
411
  ).text = line_item.buyer_order_line_id
389
- if line_item.gross_unit_price is not None:
390
- price, quantity = line_item.gross_unit_price
391
- price_el = ET.SubElement(
392
- agreement, "ram:GrossPriceProductTradePrice"
412
+ if line_item.gross_unit_price is not None:
413
+ price, quantity = line_item.gross_unit_price
414
+ price_el = ET.SubElement(agreement, "ram:GrossPriceProductTradePrice")
415
+ _currency_element(
416
+ price_el, "ram:ChargeAmount", price, invoice.currency_code
417
+ )
418
+ if quantity is not None:
419
+ _quantity_element(price_el, "ram:BasisQuantity", quantity)
420
+ if isinstance(line_item.gross_allowance_or_charge, LineAllowance):
421
+ _generate_allowance_or_charge(
422
+ price_el,
423
+ "ram:AppliedTradeAllowanceCharge",
424
+ invoice,
425
+ line_item.gross_allowance_or_charge,
426
+ False,
393
427
  )
394
- _currency_element(
395
- price_el, "ram:ChargeAmount", price, invoice.currency_code
428
+ elif isinstance(line_item.gross_allowance_or_charge, LineCharge):
429
+ _generate_allowance_or_charge(
430
+ price_el,
431
+ "ram:AppliedTradeAllowanceCharge",
432
+ invoice,
433
+ line_item.gross_allowance_or_charge,
434
+ True,
396
435
  )
397
- if quantity is not None:
398
- _quantity_element(price_el, "ram:BasisQuantity", quantity)
399
- if isinstance(line_item.gross_allowance_or_charge, LineAllowance):
400
- _generate_allowance_or_charge(
401
- price_el,
402
- "ram:AppliedTradeAllowanceCharge",
403
- invoice,
404
- line_item.gross_allowance_or_charge,
405
- False,
406
- )
407
- elif isinstance(line_item.gross_allowance_or_charge, LineCharge):
408
- _generate_allowance_or_charge(
409
- price_el,
410
- "ram:AppliedTradeAllowanceCharge",
411
- invoice,
412
- line_item.gross_allowance_or_charge,
413
- True,
414
- )
415
436
  price_el = ET.SubElement(agreement, "ram:NetPriceProductTradePrice")
416
437
  _currency_element(
417
438
  price_el,
@@ -448,8 +469,8 @@ def _generate_line_settlement(
448
469
  start, end = line_item.billing_period
449
470
  assert start <= end
450
471
  period_el = ET.SubElement(settlement, "ram:BillingSpecifiedPeriod")
451
- _date_element(period_el, "ram:StartDateTime", start)
452
- _date_element(period_el, "ram:EndDateTime", end)
472
+ _date_time_element(period_el, "ram:StartDateTime", start)
473
+ _date_time_element(period_el, "ram:EndDateTime", end)
453
474
  for allowance in line_item.allowances:
454
475
  _generate_allowance_or_charge(
455
476
  settlement,
@@ -490,7 +511,7 @@ def _generate_preceding_invoice(
490
511
  doc_el = ET.SubElement(parent, "ram:InvoiceReferencedDocument")
491
512
  ET.SubElement(doc_el, "ram:IssuerAssignedID").text = id
492
513
  if date is not None:
493
- _date_element(
514
+ _date_time_element(
494
515
  doc_el, "ram:FormattedIssueDateTime", date, qualified=True
495
516
  )
496
517
 
@@ -640,7 +661,7 @@ def _generate_delivery(parent: ET.Element, invoice: MinimumInvoice) -> None:
640
661
  supply_el = ET.SubElement(
641
662
  delivery_el, "ram:ActualDeliverySupplyChainEvent"
642
663
  )
643
- _date_element(
664
+ _date_time_element(
644
665
  supply_el, "ram:OccurrenceDateTime", invoice.delivery_date
645
666
  )
646
667
  if invoice.despatch_advice_id is not None:
@@ -694,8 +715,8 @@ def _generate_settlement(parent: ET.Element, invoice: MinimumInvoice) -> None:
694
715
  settlement_el, "ram:BillingSpecifiedPeriod"
695
716
  )
696
717
  start, end = invoice.billing_period
697
- _date_element(billing_period, "ram:StartDateTime", start)
698
- _date_element(billing_period, "ram:EndDateTime", end)
718
+ _date_time_element(billing_period, "ram:StartDateTime", start)
719
+ _date_time_element(billing_period, "ram:EndDateTime", end)
699
720
 
700
721
  for allowance in invoice.allowances:
701
722
  _generate_allowance_or_charge(
@@ -809,7 +830,7 @@ def _generate_payment_terms(parent: ET.Element, terms: PaymentTerms) -> None:
809
830
  if terms.description is not None:
810
831
  ET.SubElement(terms_el, "ram:Description").text = terms.description
811
832
  if terms.due_date is not None:
812
- _date_element(terms_el, "ram:DueDateDateTime", terms.due_date)
833
+ _date_time_element(terms_el, "ram:DueDateDateTime", terms.due_date)
813
834
  if terms.direct_debit_mandate_id is not None:
814
835
  ET.SubElement(
815
836
  terms_el, "ram:DirectDebitMandateID"
@@ -889,6 +910,4 @@ def _generate_summation(parent: ET.Element, invoice: MinimumInvoice) -> None:
889
910
  if __name__ == "__main__":
890
911
  from ._test_data import TEST_EN16931_INVOICE
891
912
 
892
- tree = generate_et(TEST_EN16931_INVOICE)
893
- ET.indent(tree)
894
- print(ET.tostring(tree, encoding="unicode", xml_declaration=True))
913
+ print(generate_xml(TEST_EN16931_INVOICE, indent=True))
@@ -4,9 +4,9 @@
4
4
  #
5
5
  msgid ""
6
6
  msgstr ""
7
- "Project-Id-Version: PyCheval-X 0.1.0\n"
7
+ "Project-Id-Version: PyCheval-X 0.4.0\n"
8
8
  "Report-Msgid-Bugs-To: https://github.com/zfutura/pycheval/issues\n"
9
- "POT-Creation-Date: 2025-07-26 19:05+0200\n"
9
+ "POT-Creation-Date: 2026-11-16 16:16+0100\n"
10
10
  "PO-Revision-Date: 2025-07-26 19:11+0200\n"
11
11
  "Last-Translator: Sebastian Rittau <sebastian.rittau@zfutura.de>\n"
12
12
  "Language: de\n"
@@ -14,7 +14,7 @@ msgstr ""
14
14
  "MIME-Version: 1.0\n"
15
15
  "Content-Type: text/plain; charset=utf-8\n"
16
16
  "Content-Transfer-Encoding: 8bit\n"
17
- "Generated-By: Babel 2.17.0\n"
17
+ "Generated-By: Babel 2.18.0\n"
18
18
 
19
19
  #: src/pycheval/format.py:53
20
20
  #, python-brace-format, python-format
@@ -295,138 +295,138 @@ msgstr "Zahlungsart"
295
295
 
296
296
  #: src/pycheval/format.py:415
297
297
  #, python-brace-format
298
- msgid "SEPA Reference: {}"
299
- msgstr "SEPA-Referenz: {}"
298
+ msgid "Seller SEPA Creditor ID: {}"
299
+ msgstr "SEPA-Gläubiger-ID des Verkäufers: {}"
300
300
 
301
- #: src/pycheval/format.py:419
301
+ #: src/pycheval/format.py:421
302
302
  #, python-brace-format
303
303
  msgid "Payment Reference: {}"
304
304
  msgstr "Zahlungsreferenz: {}"
305
305
 
306
- #: src/pycheval/format.py:423
306
+ #: src/pycheval/format.py:425
307
307
  msgid "Payment Terms"
308
308
  msgstr "Zahlungsbedingungen"
309
309
 
310
- #: src/pycheval/format.py:442
310
+ #: src/pycheval/format.py:444
311
311
  #, python-brace-format
312
312
  msgid "{quantity} {unit}"
313
313
  msgstr "{quantity} {unit}"
314
314
 
315
- #: src/pycheval/format.py:451
315
+ #: src/pycheval/format.py:453
316
316
  #, python-brace-format
317
317
  msgid "{name} ({trading_business_name})"
318
318
  msgstr "{name} ({trading_business_name})"
319
319
 
320
- #: src/pycheval/format.py:465
320
+ #: src/pycheval/format.py:467
321
321
  #, python-brace-format
322
322
  msgid "VAT ID: {}"
323
323
  msgstr "USt-ID: {}"
324
324
 
325
- #: src/pycheval/format.py:467
325
+ #: src/pycheval/format.py:469
326
326
  #, python-brace-format
327
327
  msgid "Tax Number: {}"
328
328
  msgstr "Steuernummer: {}"
329
329
 
330
- #: src/pycheval/format.py:469
330
+ #: src/pycheval/format.py:471
331
331
  #, python-brace-format
332
332
  msgid "ID: {}"
333
333
  msgstr "ID: {}"
334
334
 
335
- #: src/pycheval/format.py:471
335
+ #: src/pycheval/format.py:473
336
336
  #, python-brace-format
337
337
  msgid "IDs: {}"
338
338
  msgstr "ID: {}"
339
339
 
340
- #: src/pycheval/format.py:502
340
+ #: src/pycheval/format.py:504
341
341
  msgid "Contact:"
342
342
  msgstr "Kontakt:"
343
343
 
344
- #: src/pycheval/format.py:508
344
+ #: src/pycheval/format.py:510
345
345
  #, python-brace-format
346
346
  msgid " Phone: {phone}"
347
347
  msgstr " Telefon: {phone}"
348
348
 
349
- #: src/pycheval/format.py:517
349
+ #: src/pycheval/format.py:519
350
350
  #, python-brace-format
351
351
  msgid "{subject_code}: {content}"
352
352
  msgstr "{subject_code}: {content}"
353
353
 
354
- #: src/pycheval/format.py:527
354
+ #: src/pycheval/format.py:529
355
355
  #, python-brace-format
356
356
  msgid "Payment Means: {}"
357
357
  msgstr "Zahlungsart: {}"
358
358
 
359
- #: src/pycheval/format.py:534
359
+ #: src/pycheval/format.py:536
360
360
  #, python-brace-format
361
361
  msgid "BIC: {}"
362
362
  msgstr "BIC: {}"
363
363
 
364
- #: src/pycheval/format.py:538
364
+ #: src/pycheval/format.py:540
365
365
  #, python-brace-format
366
366
  msgid "Credit card: {} ({})"
367
367
  msgstr "Kreditkarte: {}"
368
368
 
369
- #: src/pycheval/format.py:540
369
+ #: src/pycheval/format.py:542
370
370
  #, python-brace-format
371
371
  msgid "Credit card: {}"
372
372
  msgstr "Kreditkarte: {}"
373
373
 
374
- #: src/pycheval/format.py:542
374
+ #: src/pycheval/format.py:544
375
375
  #, python-brace-format
376
376
  msgid "Payer IBAN: {}"
377
377
  msgstr "IBAN des Zahlers: {}"
378
378
 
379
- #: src/pycheval/format.py:551
379
+ #: src/pycheval/format.py:553
380
380
  #, python-brace-format
381
381
  msgid "IBAN: {}"
382
382
  msgstr "IBAN: {}"
383
383
 
384
- #: src/pycheval/format.py:553
384
+ #: src/pycheval/format.py:555
385
385
  #, python-brace-format
386
386
  msgid "Account owner: {}"
387
387
  msgstr "Kontoinhaber: {}"
388
388
 
389
- #: src/pycheval/format.py:555
389
+ #: src/pycheval/format.py:557
390
390
  #, python-brace-format
391
391
  msgid "Bank: {}"
392
392
  msgstr "Bank: {}"
393
393
 
394
- #: src/pycheval/format.py:563
394
+ #: src/pycheval/format.py:565
395
395
  #, python-brace-format, python-format
396
396
  msgid "Due Date: {due_date:%Y-%m-%d}"
397
397
  msgstr "Fälligkeitsdatum: {due_date:%d.%m.%Y}"
398
398
 
399
- #: src/pycheval/format.py:567
399
+ #: src/pycheval/format.py:569
400
400
  #, python-brace-format
401
401
  msgid "Direct Debit Mandate ID: {}"
402
402
  msgstr "Mandatsnummer für Lastschrift: {}"
403
403
 
404
- #: src/pycheval/format.py:583
404
+ #: src/pycheval/format.py:585
405
405
  #, python-brace-format
406
406
  msgid " Reference Qualifier: {}"
407
407
  msgstr " Referenzqualifizierer: {}"
408
408
 
409
- #: src/pycheval/format.py:588
409
+ #: src/pycheval/format.py:590
410
410
  #, python-brace-format
411
411
  msgid " Name: {}"
412
412
  msgstr " Name: {}"
413
413
 
414
- #: src/pycheval/format.py:590
414
+ #: src/pycheval/format.py:592
415
415
  #, python-brace-format
416
416
  msgid " URL: {}"
417
417
  msgstr " URL: {}"
418
418
 
419
- #: src/pycheval/format.py:594
419
+ #: src/pycheval/format.py:596
420
420
  #, python-brace-format
421
421
  msgid " Attachment: {filename} ({mime_type})"
422
422
  msgstr " Anhang: {filename} ({mime_type})"
423
423
 
424
- #: src/pycheval/format.py:605
424
+ #: src/pycheval/format.py:607
425
425
  #, python-brace-format
426
426
  msgid "Global ID: {}"
427
427
  msgstr "Globale ID: {}"
428
428
 
429
- #: src/pycheval/format.py:608
429
+ #: src/pycheval/format.py:610
430
430
  #, python-brace-format
431
431
  msgid "{id_type}: {id}"
432
432
  msgstr "{id_type}: {id}"
@@ -444,27 +444,27 @@ msgstr "Keine Factur-X-Rechnung in der PDF-Datei gefunden"
444
444
  msgid "Invalid relationship for Factur-X Minimum invoice"
445
445
  msgstr "Ungültige Beziehung für Factur-X-Minimum-Rechnung"
446
446
 
447
- #: src/pycheval/quantities.py:35
447
+ #: src/pycheval/quantities.py:38
448
448
  msgid "unit"
449
449
  msgstr "Einheit"
450
450
 
451
- #: src/pycheval/quantities.py:35
451
+ #: src/pycheval/quantities.py:38
452
452
  msgid "units"
453
453
  msgstr "Einheiten"
454
454
 
455
- #: src/pycheval/quantities.py:36
455
+ #: src/pycheval/quantities.py:39
456
456
  msgid "pc"
457
457
  msgstr "St."
458
458
 
459
- #: src/pycheval/quantities.py:36
459
+ #: src/pycheval/quantities.py:39
460
460
  msgid "pcs"
461
461
  msgstr "St."
462
462
 
463
- #: src/pycheval/quantities.py:38
463
+ #: src/pycheval/quantities.py:41
464
464
  msgid "day"
465
465
  msgstr "Tag"
466
466
 
467
- #: src/pycheval/quantities.py:38
467
+ #: src/pycheval/quantities.py:41
468
468
  msgid "days"
469
469
  msgstr "Tage"
470
470
 
@@ -520,79 +520,87 @@ msgstr "Lieferdatum"
520
520
  msgid "Payment Date"
521
521
  msgstr "Zahlungsdatum"
522
522
 
523
- #: src/pycheval/type_codes.py:133
523
+ #: src/pycheval/type_codes.py:134
524
524
  msgid "General Information"
525
525
  msgstr "Allgemeine Informationen"
526
526
 
527
- #: src/pycheval/type_codes.py:134
527
+ #: src/pycheval/type_codes.py:135
528
528
  msgid "Comments by Seller"
529
529
  msgstr "Bemerkungen des Verkäufers"
530
530
 
531
- #: src/pycheval/type_codes.py:135
531
+ #: src/pycheval/type_codes.py:136
532
532
  msgid "Regulatory Information"
533
533
  msgstr "Regulatorische Informationen"
534
534
 
535
- #: src/pycheval/type_codes.py:136
535
+ #: src/pycheval/type_codes.py:137
536
536
  msgid "Legal Information"
537
537
  msgstr "Rechtliche Informationen"
538
538
 
539
- #: src/pycheval/type_codes.py:137
539
+ #: src/pycheval/type_codes.py:138
540
540
  msgid "Tax Information"
541
541
  msgstr "Steuerinformationen"
542
542
 
543
- #: src/pycheval/type_codes.py:138
543
+ #: src/pycheval/type_codes.py:139
544
544
  msgid "Customs Information"
545
545
  msgstr "Zollinformationen"
546
546
 
547
- #: src/pycheval/type_codes.py:139
547
+ #: src/pycheval/type_codes.py:140
548
548
  msgid "Title"
549
549
  msgstr "Titel"
550
550
 
551
- #: src/pycheval/type_codes.py:163
551
+ #: src/pycheval/type_codes.py:168
552
552
  msgid "Instrument not defined"
553
553
  msgstr "Zahlmethode nicht definiert"
554
554
 
555
- #: src/pycheval/type_codes.py:164
555
+ #: src/pycheval/type_codes.py:169
556
556
  msgid "Species"
557
557
  msgstr "Bar"
558
558
 
559
- #: src/pycheval/type_codes.py:165
559
+ #: src/pycheval/type_codes.py:170
560
560
  msgid "Check"
561
561
  msgstr "Scheck"
562
562
 
563
- #: src/pycheval/type_codes.py:166
563
+ #: src/pycheval/type_codes.py:171
564
564
  msgid "Transfer"
565
565
  msgstr "Überweisung"
566
566
 
567
- #: src/pycheval/type_codes.py:167
567
+ #: src/pycheval/type_codes.py:172
568
568
  msgid "Bank Payment"
569
569
  msgstr "Bankeinzahlung"
570
570
 
571
- #: src/pycheval/type_codes.py:168
571
+ #: src/pycheval/type_codes.py:173
572
572
  msgid "Credit Card"
573
573
  msgstr "Kreditkarte"
574
574
 
575
- #: src/pycheval/type_codes.py:169
575
+ #: src/pycheval/type_codes.py:174
576
576
  msgid "Direct Debit"
577
577
  msgstr "Lastschrift"
578
578
 
579
- #: src/pycheval/type_codes.py:170
579
+ #: src/pycheval/type_codes.py:175
580
+ msgid "Credit Card Payment"
581
+ msgstr "Kreditkartenzahlung"
582
+
583
+ #: src/pycheval/type_codes.py:176
580
584
  msgid "Standing Agreement"
581
585
  msgstr "Dauerauftrag"
582
586
 
583
- #: src/pycheval/type_codes.py:171
587
+ #: src/pycheval/type_codes.py:177
584
588
  msgid "SEPA Credit Transfer"
585
589
  msgstr "SEPA-Überweisung"
586
590
 
587
- #: src/pycheval/type_codes.py:172
591
+ #: src/pycheval/type_codes.py:178
588
592
  msgid "SEPA Direct Debit"
589
593
  msgstr "SEPA-Lastschrift"
590
594
 
591
- #: src/pycheval/type_codes.py:173
595
+ #: src/pycheval/type_codes.py:179
596
+ msgid "Online Payment Service"
597
+ msgstr "Online-Zahlungsdienst"
598
+
599
+ #: src/pycheval/type_codes.py:180
592
600
  msgid "Report"
593
601
  msgstr "Bericht"
594
602
 
595
- #: src/pycheval/type_codes.py:174
603
+ #: src/pycheval/type_codes.py:181
596
604
  msgid "Interim Agreement"
597
605
  msgstr "Vorläufige Vereinbarung"
598
606
 
@@ -540,9 +540,21 @@ class LineItem:
540
540
 
541
541
  _: KW_ONLY
542
542
  basis_quantity: OptionalQuantity | None = None
543
+ # (Unit price, optional basis quantity)
544
+ gross_unit_price: tuple[Money, OptionalQuantity | None] | None = None
545
+ gross_allowance_or_charge: LineAllowance | LineCharge | None = None
543
546
  allowances: Sequence[LineAllowance] = field(default_factory=list)
544
547
  charges: Sequence[LineCharge] = field(default_factory=list)
545
548
 
549
+ def __post_init__(self) -> None:
550
+ if (
551
+ self.gross_allowance_or_charge is not None
552
+ and self.gross_unit_price is None
553
+ ):
554
+ raise ModelError(
555
+ "Price allowance/charge requires a gross unit price."
556
+ )
557
+
546
558
  def validate(self, profile: type[BasicInvoice]) -> None:
547
559
  """Validate the requirements for the given profile."""
548
560
  for allowance in self.allowances:
@@ -558,9 +570,6 @@ class EN16931LineItem(LineItem):
558
570
  _: KW_ONLY
559
571
  description: str | None = None
560
572
  note: IncludedNote | None = None
561
- # (Unit price, optional basis quantity)
562
- gross_unit_price: tuple[Money, OptionalQuantity | None] | None = None
563
- gross_allowance_or_charge: LineAllowance | LineCharge | None = None
564
573
  seller_assigned_id: str | None = None
565
574
  buyer_assigned_id: str | None = None
566
575
  product_characteristics: Sequence[ProductCharacteristic] = field(
@@ -576,19 +585,12 @@ class EN16931LineItem(LineItem):
576
585
  trade_account_id: str | None = None
577
586
 
578
587
  def __post_init__(self) -> None:
588
+ super().__post_init__()
579
589
  if self.note is not None and self.note.subject_code is not None:
580
590
  raise ModelError(
581
591
  "Line item note subject codes are not allowed in the "
582
592
  "EN 16931/COMFORT profile."
583
593
  )
584
- if (
585
- self.gross_allowance_or_charge is not None
586
- and self.gross_unit_price is None
587
- ):
588
- raise ModelError(
589
- "Allowance/charge requires a gross unit price in the "
590
- "EN 16931/COMFORT profile."
591
- )
592
594
  if self.origin_country is not None:
593
595
  if not validate_iso_3166_1_alpha_2(self.origin_country):
594
596
  raise ModelError("Invalid ISO 3166-1 alpha-2 country code.")
@@ -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
 
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, NamedTuple
11
11
 
12
12
  from .const import (
13
13
  NS_CII,
14
+ NS_QDT,
14
15
  NS_RAM,
15
16
  NS_UDT,
16
17
  URN_BASIC_PROFILE,
@@ -115,7 +116,7 @@ def _find_indicator(parent: ET.Element, tag: str) -> bool:
115
116
  el = parent.find(tag)
116
117
  if el is None:
117
118
  raise InvalidXMLError(f"Element {tag} not found")
118
- indicator = el.find(f"./{{{NS_RAM}}}Indicator")
119
+ indicator = el.find(f"./{{{NS_UDT}}}Indicator")
119
120
  if indicator is None:
120
121
  raise InvalidXMLError("Indicator element not found")
121
122
  if indicator.text == "true":
@@ -273,23 +274,37 @@ def _find_date(parent: ET.Element, tag: str) -> date:
273
274
  return date
274
275
 
275
276
 
276
- def _find_date_optional(parent: ET.Element, tag: str) -> date | None:
277
+ def _find_date_optional(
278
+ parent: ET.Element,
279
+ tag: str,
280
+ *,
281
+ expect_date_element: bool = False,
282
+ qualified: bool = False,
283
+ ) -> date | None:
277
284
  """Parse the text of a child element with the given tag as a date.
278
285
 
286
+ If expect_date_element is True, look for a DateString element,
287
+ otherwise look for DateTimeString. If qualified is True, look for the
288
+ element in the qualified date type namespace, otherwise look for it in
289
+ the unqualified namespace.
290
+
279
291
  Return None if the element is not found. Raise InvalidXMLError if the
280
292
  element has no valid date.
281
293
  """
294
+ prefix = NS_QDT if qualified else NS_UDT
295
+ expected_tag = "DateString" if expect_date_element else "DateTimeString"
296
+
282
297
  date_el = parent.find(tag)
283
298
  if date_el is None:
284
299
  return None
285
- dts_el = date_el.find(f"./{{{NS_UDT}}}DateTimeString")
300
+ dts_el = date_el.find(f"./{{{prefix}}}{expected_tag}")
286
301
  if dts_el is None:
287
- raise InvalidXMLError(f"DateTimeString element not found in {tag}")
302
+ raise InvalidXMLError(f"{expected_tag} element not found in {tag}")
288
303
  if dts_el.attrib.get("format") != "102":
289
- raise InvalidXMLError(f"Invalid format in DateTimeString in {tag}")
304
+ raise InvalidXMLError(f"Invalid format in {expected_tag} in {tag}")
290
305
  text = dts_el.text
291
306
  if text is None:
292
- raise InvalidXMLError(f"DateTimeString element has no text in {tag}")
307
+ raise InvalidXMLError(f"{expected_tag} element has no text in {tag}")
293
308
  if not _DATE_RE.fullmatch(text):
294
309
  raise InvalidXMLError(f"Invalid date: {text}")
295
310
  try:
@@ -820,7 +835,7 @@ def _parse_delivery(parent: ET.Element) -> _TradeDelivery:
820
835
  "ApplicableHeaderTradeDelivery element not found"
821
836
  )
822
837
  ship_to = _parse_trade_party_optional(
823
- el, f"./{{{NS_RAM}}}ShipToTradeParty"
838
+ el, f"./{{{NS_RAM}}}ShipToTradeParty", name_optional=True
824
839
  )
825
840
  delivery_date = _parse_delivery_date(el)
826
841
  despatch_advice_id = _find_ref_doc_id_optional(
@@ -1064,12 +1079,6 @@ def _parse_line_item(el: ET.Element, default_currency: str) -> LineItem:
1064
1079
  "BuyerOrderReferencedDocument element is not supported in BASIC "
1065
1080
  "profile line items",
1066
1081
  )
1067
- if agreement.gross_unit_price is not None:
1068
- raise InvalidProfileError(
1069
- "BASIC",
1070
- "GrossPriceProductTradePrice element is not supported in BASIC "
1071
- "profile line items",
1072
- )
1073
1082
  if settlement.billing_period is not None:
1074
1083
  raise InvalidProfileError(
1075
1084
  "BASIC",
@@ -1099,6 +1108,8 @@ def _parse_line_item(el: ET.Element, default_currency: str) -> LineItem:
1099
1108
  settlement.tax_category,
1100
1109
  global_id=product.global_id,
1101
1110
  basis_quantity=agreement.basis_quantity,
1111
+ gross_unit_price=agreement.gross_unit_price,
1112
+ gross_allowance_or_charge=agreement.gross_allowance_or_charge,
1102
1113
  allowances=settlement.allowances,
1103
1114
  charges=settlement.charges,
1104
1115
  )
@@ -1123,6 +1134,7 @@ def _parse_en16931_line_item(
1123
1134
  global_id=product.global_id,
1124
1135
  basis_quantity=agreement.basis_quantity,
1125
1136
  gross_unit_price=agreement.gross_unit_price,
1137
+ gross_allowance_or_charge=agreement.gross_allowance_or_charge,
1126
1138
  allowances=settlement.allowances,
1127
1139
  charges=settlement.charges,
1128
1140
  note=doc.note,
@@ -1236,8 +1248,8 @@ def _parse_product_classification(parent: ET.Element) -> ProductClassification:
1236
1248
 
1237
1249
 
1238
1250
  class _LineAgreement(NamedTuple):
1239
- gross_unit_price: tuple[Money, OptionalQuantity | None] | None # EN16931+
1240
- gross_allowance_or_charge: LineAllowance | LineCharge | None # EN16931+
1251
+ gross_unit_price: tuple[Money, OptionalQuantity | None] | None
1252
+ gross_allowance_or_charge: LineAllowance | LineCharge | None
1241
1253
  net_price: Money
1242
1254
  basis_quantity: OptionalQuantity | None
1243
1255
  buyer_order_line_id: str | None # EN16931+
@@ -1531,7 +1543,7 @@ def _parse_referenced_invoices(
1531
1543
  def _parse_referenced_invoice(el: ET.Element) -> tuple[str, date | None]:
1532
1544
  id = _find_text(el, f"./{{{NS_RAM}}}IssuerAssignedID")
1533
1545
  issue_date = _find_date_optional(
1534
- el, f"./{{{NS_RAM}}}FormattedIssueDateTime"
1546
+ el, f"./{{{NS_RAM}}}FormattedIssueDateTime", qualified=True
1535
1547
  )
1536
1548
  return id, issue_date
1537
1549
 
@@ -1547,14 +1559,17 @@ def _parse_trade_party(parent: ET.Element, tag: str) -> TradeParty:
1547
1559
 
1548
1560
 
1549
1561
  def _parse_trade_party_optional(
1550
- parent: ET.Element, tag: str
1562
+ parent: ET.Element, tag: str, *, name_optional: bool = False
1551
1563
  ) -> TradeParty | None:
1552
1564
  party_el = parent.find(tag)
1553
1565
  if party_el is None:
1554
1566
  return None
1555
1567
  ids = _find_all_texts(party_el, f"./{{{NS_RAM}}}ID")
1556
1568
  global_ids = _find_all_ids(party_el, f"./{{{NS_RAM}}}GlobalID")
1557
- name = _find_text(party_el, f"./{{{NS_RAM}}}Name")
1569
+ if name_optional:
1570
+ name = _find_text_optional(party_el, f"./{{{NS_RAM}}}Name")
1571
+ else:
1572
+ name = _find_text(party_el, f"./{{{NS_RAM}}}Name")
1558
1573
  description = _find_text_optional(party_el, f"./{{{NS_RAM}}}Description")
1559
1574
  legal_org_id, legal_org_name = _parse_legal_org(party_el)
1560
1575
  contact = _parse_trade_contact(party_el)
@@ -1679,7 +1694,7 @@ def _parse_email(parent: ET.Element) -> str | None:
1679
1694
  raise InvalidXMLError("Invalid schemeID for email")
1680
1695
  if id_el.text is None:
1681
1696
  raise InvalidXMLError("URIID element has no text")
1682
- return id_el.text
1697
+ return id_el.text.removeprefix("mailto:")
1683
1698
 
1684
1699
 
1685
1700
  def _parse_tax_simple(
@@ -1719,7 +1734,9 @@ def _parse_tax(el: ET.Element, default_currency: str) -> Tax:
1719
1734
  except ValueError as exc:
1720
1735
  raise InvalidXMLError(str(exc)) from exc
1721
1736
 
1722
- tax_point_date = _find_date_optional(el, f"./{{{NS_RAM}}}TaxPointDate")
1737
+ tax_point_date = _find_date_optional(
1738
+ el, f"./{{{NS_RAM}}}TaxPointDate", expect_date_element=True
1739
+ )
1723
1740
 
1724
1741
  due_date_type_code_s = _find_text_optional(
1725
1742
  el, f"./{{{NS_RAM}}}DueDateTypeCode"
@@ -4,7 +4,7 @@ import sys
4
4
  from io import BytesIO
5
5
  from pathlib import Path
6
6
  from typing import TYPE_CHECKING, Final
7
- from xml.dom.minidom import parseString
7
+ from xml.dom.minidom import Document, Element, parseString
8
8
 
9
9
  from pypdf import PdfWriter
10
10
  from pypdf.generic import (
@@ -27,6 +27,9 @@ if TYPE_CHECKING:
27
27
 
28
28
  RDF_NS: Final = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
29
29
  FACTURX_NS: Final = "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"
30
+ PDFA_EXTENSION_NS: Final = "http://www.aiim.org/pdfa/ns/extension/"
31
+ PDFA_SCHEMA_NS: Final = "http://www.aiim.org/pdfa/ns/schema#"
32
+ PDFA_PROPERTY_NS: Final = "http://www.aiim.org/pdfa/ns/property#"
30
33
 
31
34
  FX_EXTENSION_SCHEMA: Final = """
32
35
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#" rdf:about="">
@@ -151,13 +154,9 @@ def _set_metadata(writer: PdfWriter, profile: Profile) -> None:
151
154
  meta_o = meta_o.get_object()
152
155
  meta = XmpInformation(meta_o)
153
156
 
154
- schema = parseString(FX_EXTENSION_SCHEMA)
155
- assert schema.documentElement is not None
156
- del schema.documentElement.attributes["xmlns:rdf"]
157
-
158
157
  doc = meta.rdf_root.ownerDocument
159
158
  assert doc is not None
160
- meta.rdf_root.appendChild(schema.documentElement)
159
+ _add_extension_schema(doc, meta.rdf_root)
161
160
  root = doc.createElementNS(RDF_NS, "rdf:Description")
162
161
  root.setAttribute("rdf:about", "")
163
162
  meta.rdf_root.appendChild(root)
@@ -175,6 +174,40 @@ def _set_metadata(writer: PdfWriter, profile: Profile) -> None:
175
174
  meta_o.set_data(doc.toxml().encode("utf-8"))
176
175
 
177
176
 
177
+ def _add_extension_schema(doc: Document, rdf_root: Element) -> None:
178
+ # XMP allows each property only once per resource, so a second
179
+ # pdfaExtension:schemas makes the packet unparsable (veraPDF:
180
+ # "Duplicate property or field node 'pdfaExtension:schemas'").
181
+ # Add the Factur-X schema to an existing schema bag instead.
182
+ schema = parseString(FX_EXTENSION_SCHEMA)
183
+ assert schema.documentElement is not None
184
+ bag = _find_extension_schema_bag(doc)
185
+ if bag is None:
186
+ del schema.documentElement.attributes["xmlns:rdf"]
187
+ rdf_root.appendChild(schema.documentElement)
188
+ return
189
+ for uri in bag.getElementsByTagNameNS(PDFA_SCHEMA_NS, "namespaceURI"):
190
+ text = uri.firstChild
191
+ if text is not None and text.nodeValue == FACTURX_NS:
192
+ return # schema already declared
193
+ li = schema.getElementsByTagNameNS(RDF_NS, "li")[0]
194
+ li.setAttribute("xmlns:pdfaSchema", PDFA_SCHEMA_NS)
195
+ li.setAttribute("xmlns:pdfaProperty", PDFA_PROPERTY_NS)
196
+ bag.appendChild(doc.importNode(li, True))
197
+
198
+
199
+ def _find_extension_schema_bag(doc: Document) -> Element | None:
200
+ for schemas in doc.getElementsByTagNameNS(PDFA_EXTENSION_NS, "schemas"):
201
+ for node in schemas.childNodes:
202
+ if (
203
+ isinstance(node, Element)
204
+ and node.namespaceURI == RDF_NS
205
+ and node.localName == "Bag"
206
+ ):
207
+ return node
208
+ return None
209
+
210
+
178
211
  def _add_attachment(
179
212
  writer: PdfWriter, xml_data: str, relationship: FileRelationship
180
213
  ) -> None:
@@ -153,10 +153,13 @@ class PaymentMeansCode(StrEnum):
153
153
  TRANSFER = "30"
154
154
  BANK_PAYMENT = "42"
155
155
  CREDIT_CARD = "48"
156
+ BANK_CARD = "48" # UNTDID 4461 name of code 48
156
157
  DIRECT_DEBIT = "49"
158
+ CREDIT_CARD_PAYMENT = "54"
157
159
  STANDING_AGREEMENT = "57"
158
160
  SEPA_CREDIT_TRANSFER = "58"
159
161
  SEPA_DIRECT_DEBIT = "59"
162
+ ONLINE_PAYMENT_SERVICE = "68"
160
163
  REPORT = "97"
161
164
  INTERIM_AGREEMENT = "ZZZ"
162
165
 
@@ -169,9 +172,11 @@ PAYMENT_MEANS_NAMES = {
169
172
  PaymentMeansCode.BANK_PAYMENT: N_("Bank Payment"),
170
173
  PaymentMeansCode.CREDIT_CARD: N_("Credit Card"),
171
174
  PaymentMeansCode.DIRECT_DEBIT: N_("Direct Debit"),
175
+ PaymentMeansCode.CREDIT_CARD_PAYMENT: N_("Credit Card Payment"),
172
176
  PaymentMeansCode.STANDING_AGREEMENT: N_("Standing Agreement"),
173
177
  PaymentMeansCode.SEPA_CREDIT_TRANSFER: N_("SEPA Credit Transfer"),
174
178
  PaymentMeansCode.SEPA_DIRECT_DEBIT: N_("SEPA Direct Debit"),
179
+ PaymentMeansCode.ONLINE_PAYMENT_SERVICE: N_("Online Payment Service"),
175
180
  PaymentMeansCode.REPORT: N_("Report"),
176
181
  PaymentMeansCode.INTERIM_AGREEMENT: N_("Interim Agreement"),
177
182
  }
File without changes
File without changes
File without changes
File without changes
File without changes