invoice-examples 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,1072 @@
1
+ """Target "fr": a French Factur-X EN 16931 invoice that passes EN 16931, the Factur-X EN 16931 profile rules
2
+ and BR-FR, plus one invalid variant per rule.
3
+
4
+ Each variant changes the baseline as little as possible. Its `fires` lists every rule id the official
5
+ rules report on it, so a variant documents its side effects too (for example BR-54 next to BR-FR-27).
6
+ """
7
+
8
+ import copy
9
+ from dataclasses import dataclass, field
10
+
11
+ from lxml import etree
12
+
13
+ from .. import cii
14
+ from ..cii import BUYER_SIREN, BUYER_SIRET, NS, PAYEE_SIREN, PAYEE_SIRET, SELLER_SIREN, el, gln, luhn_complete
15
+
16
+ RULES = {
17
+ "EN 16931": "1.3.17 (CII)",
18
+ "Factur-X": "1.09.2, EN 16931 profile",
19
+ "BR-FR": "1.4.0.04 (France_RFE, FNFE-MPE)",
20
+ }
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class Variant:
25
+ id: str # file stem, e.g. "BR-FR-10"
26
+ rule: str # the rule this variant is about
27
+ fires: tuple # every rule id the official rules report on it
28
+ en: str # what is wrong, in English
29
+ fr: str # the same, in French
30
+ changes: dict = field(default_factory=dict) # baseline keys to replace
31
+ edit: object = None # optional function(root) applied to the XML tree
32
+
33
+
34
+ def _ram(tag):
35
+ return f"{{{NS['ram']}}}{tag}"
36
+
37
+
38
+ def _agreement(root):
39
+ return root.find(f".//{_ram('ApplicableHeaderTradeAgreement')}")
40
+
41
+
42
+ def _add_documents(*docs):
43
+ """Add AdditionalReferencedDocument elements (BG-24, BT-18): (issuer id, type code, name or None, reference type or None)."""
44
+
45
+ def edit(root):
46
+ agreement = _agreement(root)
47
+ for issuer_id, type_code, name, reference_type in docs:
48
+ d = el(agreement, "ram:AdditionalReferencedDocument")
49
+ el(d, "ram:IssuerAssignedID", issuer_id)
50
+ el(d, "ram:TypeCode", type_code)
51
+ if name:
52
+ el(d, "ram:Name", name)
53
+ if reference_type:
54
+ el(d, "ram:ReferenceTypeCode", reference_type)
55
+
56
+ return edit
57
+
58
+
59
+ def _add_characteristic(description, value):
60
+ """Add an item attribute (BG-32) to the first line."""
61
+
62
+ def edit(root):
63
+ product = root.find(f".//{_ram('SpecifiedTradeProduct')}")
64
+ ch = el(product, "ram:ApplicableProductCharacteristic")
65
+ if description is not None:
66
+ el(ch, "ram:Description", description)
67
+ if value is not None:
68
+ el(ch, "ram:Value", value)
69
+
70
+ return edit
71
+
72
+
73
+ def _add_invoice_reference(issuer_id, date="20260915"):
74
+ """Reference a preceding invoice (BG-3: BT-25, BT-26), at the end of the header settlement."""
75
+
76
+ def edit(root):
77
+ settlement = root.find(f".//{_ram('ApplicableHeaderTradeSettlement')}")
78
+ ref = el(settlement, "ram:InvoiceReferencedDocument")
79
+ el(ref, "ram:IssuerAssignedID", issuer_id)
80
+ el(el(ref, "ram:FormattedIssueDateTime"), "qdt:DateTimeString", date, format="102")
81
+
82
+ return edit
83
+
84
+
85
+ def _drop_scheme(party_tag):
86
+ """Remove the schemeID of a party's GlobalID."""
87
+
88
+ def edit(root):
89
+ for gid in root.iter(_ram("GlobalID")):
90
+ if gid.getparent().tag == _ram(party_tag):
91
+ gid.attrib.pop("schemeID", None)
92
+
93
+ return edit
94
+
95
+
96
+ def _rewrite_amount(tag, text):
97
+ """Write a header monetary total with another notation (e.g. 3 decimals)."""
98
+
99
+ def edit(root):
100
+ for node in root.iter(_ram(tag)):
101
+ if node.getparent().tag == _ram("SpecifiedTradeSettlementHeaderMonetarySummation"):
102
+ node.text = text
103
+
104
+ return edit
105
+
106
+
107
+ def _set_amount(tag, delta):
108
+ """Add delta to a header monetary total (e.g. GrandTotalAmount)."""
109
+
110
+ def edit(root):
111
+ for node in root.iter(_ram(tag)):
112
+ if node.getparent().tag == _ram("SpecifiedTradeSettlementHeaderMonetarySummation"):
113
+ node.text = f"{float(node.text) + delta:.2f}"
114
+
115
+ return edit
116
+
117
+
118
+ def _edit_all(*edits):
119
+ def edit(root):
120
+ for e in edits:
121
+ e(root)
122
+
123
+ return edit
124
+
125
+
126
+ def _new(tag, text=None, **attrs):
127
+ prefix, name = tag.split(":")
128
+ node = etree.Element(f"{{{NS[prefix]}}}{name}", attrs)
129
+ if text is not None:
130
+ node.text = text
131
+ return node
132
+
133
+
134
+ def _sub(parent, tag, text=None, **attrs):
135
+ node = _new(tag, text, **attrs)
136
+ parent.append(node)
137
+ return node
138
+
139
+
140
+ def _first(root, *path):
141
+ """The first element at the end of a chain of ram: tags."""
142
+ return root.find(".//" + "/".join(_ram(t) for t in path))
143
+
144
+
145
+ def _insert(parent, node, before=None, after=None):
146
+ """Insert node before the first child named `before`, or after the last child named `after`, else at the end."""
147
+ if before is not None and parent.find(_ram(before)) is not None:
148
+ parent.find(_ram(before)).addprevious(node)
149
+ elif after is not None and parent.findall(_ram(after)):
150
+ parent.findall(_ram(after))[-1].addnext(node)
151
+ else:
152
+ parent.append(node)
153
+
154
+
155
+ def _party(tag, name, global_ids, legal_id=None):
156
+ node = _new(f"ram:{tag}")
157
+ for value, scheme in global_ids:
158
+ _sub(node, "ram:GlobalID", value, **({"schemeID": scheme} if scheme else {}))
159
+ _sub(node, "ram:Name", name)
160
+ if legal_id:
161
+ _sub(_sub(node, "ram:SpecifiedLegalOrganization"), "ram:ID", legal_id, schemeID="0002")
162
+ return node
163
+
164
+
165
+ def _add_payee(global_ids, legal_id=None):
166
+ """Add a payee (BG-10), a factoring company, before the payment means."""
167
+
168
+ def edit(root):
169
+ _insert(
170
+ _first(root, "ApplicableHeaderTradeSettlement"),
171
+ _party("PayeeTradeParty", "Affacturage Exemple", global_ids, legal_id),
172
+ before="SpecifiedTradeSettlementPaymentMeans",
173
+ )
174
+
175
+ return edit
176
+
177
+
178
+ def _add_ship_to(global_ids):
179
+ """Add a deliver-to party (BG-13) with location identifiers (BT-71)."""
180
+
181
+ def edit(root):
182
+ _first(root, "ApplicableHeaderTradeDelivery").insert(
183
+ 0, _party("ShipToTradeParty", "Médiathèque d'Exemple", global_ids)
184
+ )
185
+
186
+ return edit
187
+
188
+
189
+ def _add_global_id(party_tag, value, scheme):
190
+ """Add a second GlobalID to a party, after the first one."""
191
+
192
+ def edit(root):
193
+ _insert(_first(root, party_tag), _new("ram:GlobalID", value, schemeID=scheme), after="GlobalID")
194
+
195
+ return edit
196
+
197
+
198
+ def _billing_period(start, end):
199
+ """Add the invoicing period (BG-14: BT-73, BT-74) after the VAT breakdown."""
200
+
201
+ def edit(root):
202
+ period = _new("ram:BillingSpecifiedPeriod")
203
+ _sub(_sub(period, "ram:StartDateTime"), "udt:DateTimeString", start, format="102")
204
+ _sub(_sub(period, "ram:EndDateTime"), "udt:DateTimeString", end, format="102")
205
+ _insert(_first(root, "ApplicableHeaderTradeSettlement"), period, after="ApplicableTradeTax")
206
+
207
+ return edit
208
+
209
+
210
+ def _tax_point_date(value):
211
+ """Give each VAT breakdown a VAT point date (BT-7); use with due_date_type None (BT-7 and BT-8 exclude each other)."""
212
+
213
+ def edit(root):
214
+ for tax in _first(root, "ApplicableHeaderTradeSettlement").iterfind(_ram("ApplicableTradeTax")):
215
+ point = _new("ram:TaxPointDate")
216
+ _sub(point, "udt:DateString", value, format="102")
217
+ _insert(tax, point, before="RateApplicablePercent")
218
+
219
+ return edit
220
+
221
+
222
+ def _set_text(*path, text):
223
+ """Rewrite the text of the first element at the end of a ram: path."""
224
+
225
+ def edit(root):
226
+ _first(root, *path).text = text
227
+
228
+ return edit
229
+
230
+
231
+ def _add_element(path, tag, text, before=None, after=None, **attrs):
232
+ """Add a ram: element inside the first element at the end of path."""
233
+
234
+ def edit(root):
235
+ _insert(_first(root, *path), _new(f"ram:{tag}", text, **attrs), before=before, after=after)
236
+
237
+ return edit
238
+
239
+
240
+ def _prepaid(amount, due):
241
+ """Add a paid amount (BT-113) and set the amount due (BT-115)."""
242
+
243
+ def edit(root):
244
+ sums = _first(root, "SpecifiedTradeSettlementHeaderMonetarySummation")
245
+ _insert(sums, _new("ram:TotalPrepaidAmount", amount), before="DuePayableAmount")
246
+ sums.find(_ram("DuePayableAmount")).text = due
247
+
248
+ return edit
249
+
250
+
251
+ def _paid_without_due_date(root):
252
+ """Already paid: paid amount = total with VAT, nothing due, and no payment due date (BT-9)."""
253
+ sums = _first(root, "SpecifiedTradeSettlementHeaderMonetarySummation")
254
+ _prepaid(sums.find(_ram("GrandTotalAmount")).text, "0.00")(root)
255
+ terms = _first(root, "SpecifiedTradePaymentTerms")
256
+ terms.remove(terms.find(_ram("DueDateDateTime")))
257
+
258
+
259
+ def _gross_price(gross, discount):
260
+ """Give the first line a gross price (BT-148) and a price discount (BT-147); the net price stays."""
261
+
262
+ def edit(root):
263
+ price = _new("ram:GrossPriceProductTradePrice")
264
+ _sub(price, "ram:ChargeAmount", gross)
265
+ ac = _sub(price, "ram:AppliedTradeAllowanceCharge")
266
+ _sub(_sub(ac, "ram:ChargeIndicator"), "udt:Indicator", "false")
267
+ _sub(ac, "ram:ActualAmount", discount)
268
+ _insert(_first(root, "SpecifiedLineTradeAgreement"), price, before="NetPriceProductTradePrice")
269
+
270
+ return edit
271
+
272
+
273
+ NOTES = cii.FRENCH["notes"]
274
+ BAR_B2B = ("BAR", "B2B")
275
+ SELLER, BUYER = cii.FRENCH["seller"], cii.FRENCH["buyer"]
276
+ ALLOWANCE = [("10.25", "95", "Remise commerciale", "S", "20")] # 1 % of 1025.00
277
+ CHARGE = [("15.00", "FC", "Frais de port", "S", "20")]
278
+ DISCOUNTED_LINES = [
279
+ ("Atelier de formation", "2", "450.00", "S", "20", "50.00"),
280
+ ("Support de cours", "10", "12.50", "S", "20"),
281
+ ]
282
+ SELLER_SIRET_2 = luhn_complete(SELLER_SIREN + "0002")
283
+ BUYER_SIRET_2 = luhn_complete(BUYER_SIREN + "0003") # also the deliver-to establishment
284
+ SPACED_SIRET = f"{BUYER_SIRET_2[:3]} {BUYER_SIRET_2[3:6]} {BUYER_SIRET_2[6:9]} {BUYER_SIRET_2[9:]}"
285
+
286
+ VARIANTS = (
287
+ Variant(
288
+ "BR-FR-01",
289
+ "BR-FR-01",
290
+ ("BR-FR-01_BT-1",),
291
+ "The invoice number (BT-1) is longer than 35 characters.",
292
+ "Le numéro de facture (BT-1) dépasse 35 caractères.",
293
+ {"number": "F2026-" + "0" * 30},
294
+ ),
295
+ Variant(
296
+ "BR-FR-02",
297
+ "BR-FR-02",
298
+ ("BR-FR-02_BT-1",),
299
+ "The invoice number (BT-1) contains a character outside letters, digits and + - _ /.",
300
+ "Le numéro de facture (BT-1) contient un caractère autre que lettres, chiffres et + - _ /.",
301
+ {"number": "F2026.0042"},
302
+ ),
303
+ Variant(
304
+ "BR-FR-03",
305
+ "BR-FR-03",
306
+ ("BR-FR-03_BT-2",),
307
+ "The issue date (BT-2) has a year outside 2000-2099.",
308
+ "La date d'émission (BT-2) a une année hors de 2000-2099.",
309
+ {"issue_date": "19991231"},
310
+ ),
311
+ Variant(
312
+ "BR-FR-04",
313
+ "BR-FR-04",
314
+ ("BR-FR-04_BT-3",),
315
+ "The document type code (BT-3) is 326 (partial invoice), valid in EN 16931 but not in the French list.",
316
+ "Le code type de document (BT-3) est 326 (facture partielle), valide en EN 16931 mais absent de la liste française.",
317
+ {"type_code": "326"},
318
+ ),
319
+ Variant(
320
+ "BR-FR-05-PMT",
321
+ "BR-FR-05",
322
+ ("BR-FR-05_BT-22_PMT",),
323
+ "The note about the fixed recovery fee (subject code PMT) is missing.",
324
+ "La mention de l'indemnité forfaitaire pour frais de recouvrement (code PMT) est absente.",
325
+ {"notes": [n for n in NOTES if n[0] != "PMT"]},
326
+ ),
327
+ Variant(
328
+ "BR-FR-05-PMD",
329
+ "BR-FR-05",
330
+ ("BR-FR-05_BT-22_PMD",),
331
+ "The note about late payment penalties (subject code PMD) is missing.",
332
+ "La mention des pénalités de retard (code PMD) est absente.",
333
+ {"notes": [n for n in NOTES if n[0] != "PMD"]},
334
+ ),
335
+ Variant(
336
+ "BR-FR-05-AAB",
337
+ "BR-FR-05",
338
+ ("BR-FR-05_BT-22_AAB",),
339
+ "The note about early payment discount (subject code AAB) is missing.",
340
+ "La mention relative à l'escompte (code AAB) est absente.",
341
+ {"notes": [n for n in NOTES if n[0] != "AAB"]},
342
+ ),
343
+ Variant(
344
+ "BR-FR-06",
345
+ "BR-FR-06",
346
+ ("BR-FR-06_BT-21_PMT",),
347
+ "Two notes have the subject code PMT.",
348
+ "Deux mentions ont le code sujet PMT.",
349
+ {"notes": [*NOTES, ("PMT", "Indemnité forfaitaire : 40 EUR.")]},
350
+ ),
351
+ Variant(
352
+ "BR-FR-08",
353
+ "BR-FR-08",
354
+ ("BR-FR-08_BT-23",),
355
+ "The billing framework (BT-23, cadre de facturation) is missing.",
356
+ "Le cadre de facturation (BT-23) est absent.",
357
+ {"billing_frame": None},
358
+ ),
359
+ Variant(
360
+ "BR-FR-09",
361
+ "BR-FR-09",
362
+ ("BR-FR-09_BT-29",),
363
+ "The seller's SIRET (BT-29) does not start with its SIREN (BT-30).",
364
+ "Le SIRET du vendeur (BT-29) ne commence pas par son SIREN (BT-30).",
365
+ {"seller": {**SELLER, "global_id": (BUYER_SIRET, "0009")}},
366
+ ),
367
+ Variant(
368
+ "BR-FR-10",
369
+ "BR-FR-10",
370
+ ("BR-FR-10_BT-30",),
371
+ "The seller's SIREN (BT-30) is missing (and so is its SIRET, BT-29).",
372
+ "Le SIREN du vendeur (BT-30) est absent (son SIRET, BT-29, aussi).",
373
+ {"seller": {**SELLER, "legal_id": None, "global_id": None}},
374
+ ),
375
+ Variant(
376
+ "BR-FR-11",
377
+ "BR-FR-11",
378
+ ("BR-FR-11_BT-47",),
379
+ "The invoice is B2B (note BAR = B2B) but the buyer's SIREN (BT-47) is missing.",
380
+ "La facture est B2B (mention BAR = B2B) mais le SIREN de l'acheteur (BT-47) est absent.",
381
+ {"notes": [*NOTES, BAR_B2B], "buyer": {**BUYER, "legal_id": None, "global_id": None}},
382
+ ),
383
+ Variant(
384
+ "BR-FR-12",
385
+ "BR-FR-12",
386
+ ("BR-FR-12_BT-49",),
387
+ "The buyer's electronic address (BT-49) is missing.",
388
+ "L'adresse électronique de l'acheteur (BT-49) est absente.",
389
+ {"buyer": {**BUYER, "endpoint": None}},
390
+ ),
391
+ Variant(
392
+ "BR-FR-13",
393
+ "BR-FR-13",
394
+ ("BR-FR-13_BT-34",),
395
+ "The seller's electronic address (BT-34) is missing.",
396
+ "L'adresse électronique du vendeur (BT-34) est absente.",
397
+ {"seller": {**SELLER, "endpoint": None}},
398
+ ),
399
+ Variant(
400
+ "BR-FR-16",
401
+ "BR-FR-16",
402
+ ("BR-FR-16_BT-119", "BR-FR-16_BT-152"),
403
+ "The VAT rate is 21 %, which is not a French rate (lines BT-152 and breakdown BT-119).",
404
+ "Le taux de TVA est 21 %, qui n'est pas un taux français (lignes BT-152 et ventilation BT-119).",
405
+ {"lines": [("Atelier de formation", "2", "450.00", "S", "21")]},
406
+ ),
407
+ Variant(
408
+ "BR-FR-17",
409
+ "BR-FR-17",
410
+ ("BR-FR-17_BT-123",),
411
+ "An attachment (BT-123) is qualified with a code outside the French list.",
412
+ "Une pièce jointe (BT-123) est qualifiée par un code hors de la liste française.",
413
+ edit=_add_documents(("PJ-1", "916", "CONTRAT", None)),
414
+ ),
415
+ Variant(
416
+ "BR-FR-18",
417
+ "BR-FR-18",
418
+ ("BR-FR-18_BT-123",),
419
+ "Two attachments are described as LISIBLE (BT-123): only one readable copy is allowed.",
420
+ "Deux pièces jointes sont décrites LISIBLE (BT-123) : une seule version lisible est permise.",
421
+ edit=_add_documents(("PJ-1", "916", "LISIBLE", None), ("PJ-2", "916", "LISIBLE", None)),
422
+ ),
423
+ Variant(
424
+ "BR-FR-20",
425
+ "BR-FR-20",
426
+ ("BR-FR-20_BT-21",),
427
+ "The note BAR (BT-21) has a value outside B2B, B2BINT, B2C, B2CINT, OUTOFSCOPE, ARCHIVEONLY.",
428
+ "La mention BAR (BT-21) a une valeur hors de B2B, B2BINT, B2C, B2CINT, OUTOFSCOPE, ARCHIVEONLY.",
429
+ {"notes": [*NOTES, ("BAR", "B2G")]},
430
+ ),
431
+ Variant(
432
+ "BR-FR-21",
433
+ "BR-FR-21",
434
+ ("BR-FR-21_BT-49",),
435
+ "The invoice is B2B but the buyer's electronic address (BT-49) does not start with its SIREN.",
436
+ "La facture est B2B mais l'adresse électronique de l'acheteur (BT-49) ne commence pas par son SIREN.",
437
+ {"notes": [*NOTES, BAR_B2B], "buyer": {**BUYER, "endpoint": ("999999999", "0225")}},
438
+ ),
439
+ Variant(
440
+ "BR-FR-23",
441
+ "BR-FR-23",
442
+ ("BR-FR-23_BT-34",),
443
+ "The seller's electronic address (BT-34) contains a character outside letters, digits and - _ .",
444
+ "L'adresse électronique du vendeur (BT-34) contient un caractère autre que lettres, chiffres et - _ .",
445
+ {"seller": {**SELLER, "endpoint": (SELLER["legal_id"][0] + "@factures", "0225")}},
446
+ ),
447
+ Variant(
448
+ "BR-FR-25",
449
+ "BR-FR-25",
450
+ ("BR-FR-25_BT-34",),
451
+ "The seller's electronic address (BT-34) is longer than 125 characters.",
452
+ "L'adresse électronique du vendeur (BT-34) dépasse 125 caractères.",
453
+ {"seller": {**SELLER, "endpoint": (SELLER["legal_id"][0] + "_" + "x" * 120, "0225")}},
454
+ ),
455
+ Variant(
456
+ "BR-FR-27",
457
+ "BR-FR-27",
458
+ ("BR-FR-27_BT-160",),
459
+ "An item attribute (BG-32) has an empty name (BT-160).",
460
+ "Un attribut d'article (BG-32) a un nom vide (BT-160).",
461
+ edit=_add_characteristic(" ", "Bleu"),
462
+ ),
463
+ Variant(
464
+ "BR-FR-29",
465
+ "BR-FR-29",
466
+ ("BR-FR-29_BT-18",),
467
+ "Two invoiced object identifiers (BT-18) use the reference type AFL.",
468
+ "Deux identifiants d'objet facturé (BT-18) utilisent le type de référence AFL.",
469
+ edit=_add_documents(("OBJ-1", "130", None, "AFL"), ("OBJ-2", "130", None, "AFL")),
470
+ ),
471
+ Variant(
472
+ "BR-FR-31",
473
+ "BR-FR-31",
474
+ ("BR-FR-31_BT-21",),
475
+ "Two notes have the subject code BAR.",
476
+ "Deux mentions ont le code sujet BAR.",
477
+ {"notes": [*NOTES, BAR_B2B, ("BAR", "B2C")]},
478
+ ),
479
+ Variant(
480
+ "BR-FR-32",
481
+ "BR-FR-32",
482
+ ("BR-FR-32-LEGALID",),
483
+ "The buyer's identifier with scheme 0002 (SIREN, BT-47) does not have 9 digits.",
484
+ "L'identifiant de l'acheteur au schéma 0002 (SIREN, BT-47) n'a pas 9 chiffres.",
485
+ {"buyer": {**BUYER, "legal_id": (BUYER_SIREN + "0", "0002"), "global_id": None}},
486
+ ),
487
+ Variant(
488
+ "BR-FR-CO-07",
489
+ "BR-FR-CO-07",
490
+ ("BR-FR-CO-07_BT-9",),
491
+ "The payment due date (BT-9) is before the issue date (BT-2).",
492
+ "La date d'échéance (BT-9) est antérieure à la date d'émission (BT-2).",
493
+ {"due_date": "20261001"},
494
+ ),
495
+ Variant(
496
+ "BR-FR-CO-12",
497
+ "BR-FR-CO-12",
498
+ ("BR-FR-CO-12_BT-5",),
499
+ "The invoice is in USD but gives no VAT accounting currency EUR (BT-6) and no VAT total in EUR.",
500
+ "La facture est en USD mais n'indique ni devise de comptabilisation de la TVA en EUR (BT-6) ni total de TVA en EUR.",
501
+ {"currency": "USD"},
502
+ ),
503
+ Variant(
504
+ "BR-FR-DEC-02",
505
+ "BR-FR-DEC-02",
506
+ ("BR-FR-DEC-02_BT-129",),
507
+ "The invoiced quantity (BT-129) has more than 4 decimals.",
508
+ "La quantité facturée (BT-129) a plus de 4 décimales.",
509
+ {"lines": [("Atelier de formation", "2.00001", "450.00", "S", "20")]},
510
+ ),
511
+ Variant(
512
+ "BR-FR-09-buyer",
513
+ "BR-FR-09",
514
+ ("BR-FR-09_BT-46",),
515
+ "The buyer's SIRET (BT-46) does not start with its SIREN (BT-47).",
516
+ "Le SIRET de l'acheteur (BT-46) ne commence pas par son SIREN (BT-47).",
517
+ {"buyer": {**BUYER, "global_id": (SELLER["global_id"][0], "0009")}},
518
+ ),
519
+ Variant(
520
+ "BR-FR-23-buyer",
521
+ "BR-FR-23",
522
+ ("BR-FR-23_BT-49",),
523
+ "The buyer's electronic address (BT-49) contains a character outside letters, digits and - _ .",
524
+ "L'adresse électronique de l'acheteur (BT-49) contient un caractère autre que lettres, chiffres et - _ .",
525
+ {"buyer": {**BUYER, "endpoint": (BUYER["legal_id"][0] + "/compta", "0225")}},
526
+ ),
527
+ Variant(
528
+ "BR-FR-24",
529
+ "BR-FR-24",
530
+ ("BR-FR-24_BT-29",),
531
+ "The seller's private identifier (BT-29, scheme 0224) contains a space.",
532
+ "L'identifiant privé du vendeur (BT-29, schéma 0224) contient une espace.",
533
+ {"seller": {**SELLER, "global_id": ("ATELIER 42", "0224")}},
534
+ ),
535
+ Variant(
536
+ "BR-FR-26",
537
+ "BR-FR-26",
538
+ ("BR-FR-26_BT-29",),
539
+ "The seller's private identifier (BT-29, scheme 0224) is longer than 100 characters.",
540
+ "L'identifiant privé du vendeur (BT-29, schéma 0224) dépasse 100 caractères.",
541
+ {"seller": {**SELLER, "global_id": ("A" * 101, "0224")}},
542
+ ),
543
+ Variant(
544
+ "BR-FR-CO-05",
545
+ "BR-FR-CO-05",
546
+ ("BR-FR-CO-05_BT-3",),
547
+ "A credit note (BT-3 = 381) does not reference the invoice it corrects (BT-25).",
548
+ "Un avoir (BT-3 = 381) ne référence pas la facture qu'il corrige (BT-25).",
549
+ {"type_code": "381"},
550
+ ),
551
+ Variant(
552
+ "BR-FR-DEC-04",
553
+ "BR-FR-DEC-04",
554
+ ("BR-FR-DEC-04_BT-119", "BR-FR-DEC-04_BT-152", "BR-FR-16_BT-119", "BR-FR-16_BT-152"),
555
+ "The VAT rate is written with 3 decimals (20.000): more than 2, and not in the list of French rates as written.",
556
+ "Le taux de TVA est écrit avec 3 décimales (20.000) : plus de 2, et absent de la liste des taux français tel qu'écrit.",
557
+ {"lines": [("Atelier de formation", "2", "450.00", "S", "20.000")]},
558
+ ),
559
+ Variant(
560
+ "BR-FR-01-BT-25",
561
+ "BR-FR-01",
562
+ ("BR-FR-01_BT-25",),
563
+ "The preceding invoice reference (BT-25) is longer than 35 characters.",
564
+ "La référence de la facture antérieure (BT-25) dépasse 35 caractères.",
565
+ edit=_add_invoice_reference("F2026-" + "0" * 30),
566
+ ),
567
+ Variant(
568
+ "BR-FR-02-BT-25",
569
+ "BR-FR-02",
570
+ ("BR-FR-02_BT-25",),
571
+ "The preceding invoice reference (BT-25) contains a character outside letters, digits and + - _ /.",
572
+ "La référence de la facture antérieure (BT-25) contient un caractère autre que lettres, chiffres et + - _ /.",
573
+ edit=_add_invoice_reference("F2026.0001"),
574
+ ),
575
+ Variant(
576
+ "BR-FR-03-BT-9",
577
+ "BR-FR-03",
578
+ ("BR-FR-03_BT-9",),
579
+ "The payment due date (BT-9) has a year outside 2000-2099.",
580
+ "La date d'échéance (BT-9) a une année hors de 2000-2099.",
581
+ {"due_date": "21000101"},
582
+ ),
583
+ Variant(
584
+ "BR-FR-03-BT-26",
585
+ "BR-FR-03",
586
+ ("BR-FR-03_BT-26",),
587
+ "The preceding invoice issue date (BT-26) has a year outside 2000-2099.",
588
+ "La date d'émission de la facture antérieure (BT-26) a une année hors de 2000-2099.",
589
+ edit=_add_invoice_reference("F2026-0001", "19990915"),
590
+ ),
591
+ Variant(
592
+ "BR-FR-03-BT-72",
593
+ "BR-FR-03",
594
+ ("BR-FR-03_BT-72",),
595
+ "The actual delivery date (BT-72) has a year outside 2000-2099.",
596
+ "La date de livraison effective (BT-72) a une année hors de 2000-2099.",
597
+ {"delivery_date": "19991015"},
598
+ ),
599
+ Variant(
600
+ "BR-FR-06-PMD",
601
+ "BR-FR-06",
602
+ ("BR-FR-06_BT-21_PMD",),
603
+ "Two notes have the subject code PMD.",
604
+ "Deux mentions ont le code sujet PMD.",
605
+ {"notes": [*NOTES, ("PMD", "Pénalités de retard : taux légal majoré.")]},
606
+ ),
607
+ Variant(
608
+ "BR-FR-06-AAB",
609
+ "BR-FR-06",
610
+ ("BR-FR-06_BT-21_AAB",),
611
+ "Two notes have the subject code AAB.",
612
+ "Deux mentions ont le code sujet AAB.",
613
+ {"notes": [*NOTES, ("AAB", "Escompte : néant.")]},
614
+ ),
615
+ Variant(
616
+ "BR-FR-25-buyer",
617
+ "BR-FR-25",
618
+ ("BR-FR-25_BT-49",),
619
+ "The buyer's electronic address (BT-49) is longer than 125 characters.",
620
+ "L'adresse électronique de l'acheteur (BT-49) dépasse 125 caractères.",
621
+ {"buyer": {**BUYER, "endpoint": (BUYER["legal_id"][0] + "_" + "x" * 120, "0225")}},
622
+ ),
623
+ Variant(
624
+ "BR-FR-29-AFL",
625
+ "BR-FR-29",
626
+ ("BR-FR-29_AFL", "BR-52"),
627
+ "An invoiced object identifier (BT-18) of type AFL is blank (EN 16931 BR-52 fires too: a document reference is required).",
628
+ "Un identifiant d'objet facturé (BT-18) de type AFL est vide (la règle EN 16931 BR-52 se déclenche aussi : une référence est exigée).",
629
+ edit=_add_documents((" ", "130", None, "AFL")),
630
+ ),
631
+ Variant(
632
+ "BR-FR-32-GLOBALID",
633
+ "BR-FR-32",
634
+ ("BR-FR-32-GLOBALID",),
635
+ "The seller's identifier with scheme 0002 (BT-29) does not have 9 digits.",
636
+ "L'identifiant du vendeur au schéma 0002 (BT-29) n'a pas 9 chiffres.",
637
+ {"seller": {**SELLER, "global_id": (SELLER_SIREN[:8], "0002")}},
638
+ ),
639
+ Variant(
640
+ "BR-FR-CO-04",
641
+ "BR-FR-CO-04",
642
+ ("BR-FR-CO-04_BT-4",),
643
+ "A corrective invoice (BT-3 = 384) does not reference exactly one preceding invoice (BT-25).",
644
+ "Une facture rectificative (BT-3 = 384) ne référence pas exactement une facture antérieure (BT-25).",
645
+ {"type_code": "384"},
646
+ ),
647
+ Variant(
648
+ "BR-FR-CO-08",
649
+ "BR-FR-CO-08",
650
+ ("BR-FR-CO-08_BT-23",),
651
+ "A prepayment invoice (BT-3 = 386) uses a final-invoice-after-deposit framework (BT-23 = S4).",
652
+ "Une facture d'acompte (BT-3 = 386) utilise un cadre de facture définitive après acompte (BT-23 = S4).",
653
+ {"type_code": "386", "billing_frame": "S4"},
654
+ ),
655
+ Variant(
656
+ "BR-FR-CO-09",
657
+ "BR-FR-CO-09",
658
+ ("BR-FR-CO-09_BT-23-1", "BR-FR-CO-09_BT-23-2"),
659
+ "The framework says already paid (BT-23 = S2), but the paid amount (BT-113) is not the total and the amount due (BT-115) is not 0.",
660
+ "Le cadre indique une facture déjà payée (BT-23 = S2), mais le montant payé (BT-113) n'est pas le total et le net à payer (BT-115) n'est pas 0.",
661
+ {"billing_frame": "S2"},
662
+ ),
663
+ Variant(
664
+ "BR-FR-DEC-03",
665
+ "BR-FR-DEC-03",
666
+ ("BR-FR-DEC-03_BT-146",),
667
+ "The item net price (BT-146) has more than 6 decimals.",
668
+ "Le prix net de l'article (BT-146) a plus de 6 décimales.",
669
+ {"lines": [("Atelier de formation", "2", "450.0000001", "S", "20")]},
670
+ ),
671
+ Variant(
672
+ "BR-FR-15",
673
+ "BR-FR-15",
674
+ ("BR-FR-15_BT-95_BT-151", "BR-FR-15_BT-95_BT-151_LM", "BR-FR-15_BT-95_BT-118", "BR-FR-15_BT-95_BT-118_LM"),
675
+ "The line and the VAT breakdown use VAT category L (Canary Islands), which does not apply in France.",
676
+ "La ligne et la ventilation de TVA utilisent la catégorie L (îles Canaries), qui ne s'applique pas en France.",
677
+ {"lines": [("Atelier de formation", "2", "450.00", "L", "7")]},
678
+ ),
679
+ Variant(
680
+ "BR-FR-22",
681
+ "BR-FR-22",
682
+ ("BR-FR-22_BT-34",),
683
+ "A B2B self-billed invoice (BT-3 = 389): the seller's electronic address (BT-34) does not start with its SIREN.",
684
+ "Une autofacture B2B (BT-3 = 389) : l'adresse électronique du vendeur (BT-34) ne commence pas par son SIREN.",
685
+ {"type_code": "389", "notes": [*NOTES, BAR_B2B], "seller": {**SELLER, "endpoint": ("999999999", "0225")}},
686
+ ),
687
+ Variant(
688
+ "BR-FR-CO-03",
689
+ "BR-FR-CO-03",
690
+ ("BR-FR-CO-03_BT-3",),
691
+ "A document of type 262 gives no contract reference (BT-12) and no billing period (BT-73, BT-74).",
692
+ "Un document de type 262 n'indique ni référence de contrat (BT-12) ni période de facturation (BT-73, BT-74).",
693
+ {"type_code": "262"},
694
+ ),
695
+ Variant(
696
+ "BR-FR-CO-10",
697
+ "BR-FR-CO-10",
698
+ ("BR-FR-CO-10_BT-29-1", "FX-SCH-A-000440"),
699
+ "The seller's identifier (BT-29) has no scheme identifier (BT-29-1); the Factur-X profile rules reject it too.",
700
+ "L'identifiant du vendeur (BT-29) n'a pas d'identifiant de schéma (BT-29-1) ; les règles du profil Factur-X le refusent aussi.",
701
+ edit=_drop_scheme("SellerTradeParty"),
702
+ ),
703
+ Variant(
704
+ "BR-FR-DEC-01",
705
+ "BR-FR-DEC-01",
706
+ ("BR-FR-DEC-01_BT-112", "BR-FR-DEC-01_BT-115", "BR-DEC-14", "BR-DEC-18"),
707
+ "The total with VAT (BT-112) and the amount due (BT-115) are written with 3 decimals (EN 16931 BR-DEC-14 and BR-DEC-18 fire too).",
708
+ "Le total TTC (BT-112) et le net à payer (BT-115) sont écrits avec 3 décimales (les règles EN 16931 BR-DEC-14 et BR-DEC-18 se déclenchent aussi).",
709
+ edit=_edit_all(
710
+ _rewrite_amount("GrandTotalAmount", "1230.000"), _rewrite_amount("DuePayableAmount", "1230.000")
711
+ ),
712
+ ),
713
+ Variant(
714
+ "BR-CO-15",
715
+ "BR-CO-15",
716
+ ("BR-CO-15",),
717
+ "The invoice total with VAT (BT-112) is not the total without VAT (BT-109) plus the VAT total (BT-110).",
718
+ "Le total TTC (BT-112) n'est pas égal au total HT (BT-109) plus le total de TVA (BT-110).",
719
+ edit=_edit_all(_set_amount("GrandTotalAmount", 1), _set_amount("DuePayableAmount", 1)),
720
+ ),
721
+ Variant(
722
+ "BR-FR-03-BT-7",
723
+ "BR-FR-03",
724
+ ("BR-FR-03_BT-7",),
725
+ "The VAT point date (BT-7) has a year outside 2000-2099.",
726
+ "La date d'exigibilité de la TVA (BT-7) a une année hors de 2000-2099.",
727
+ {"due_date_type": None},
728
+ edit=_tax_point_date("19991020"),
729
+ ),
730
+ Variant(
731
+ "BR-FR-03-BT-73",
732
+ "BR-FR-03",
733
+ ("BR-FR-03_BT-73",),
734
+ "The invoicing period start date (BT-73) has a year outside 2000-2099.",
735
+ "La date de début de la période de facturation (BT-73) a une année hors de 2000-2099.",
736
+ edit=_billing_period("19991001", "20261031"),
737
+ ),
738
+ Variant(
739
+ "BR-FR-03-BT-74",
740
+ "BR-FR-03",
741
+ ("BR-FR-03_BT-74",),
742
+ "The invoicing period end date (BT-74) has a year outside 2000-2099.",
743
+ "La date de fin de la période de facturation (BT-74) a une année hors de 2000-2099.",
744
+ edit=_billing_period("20261001", "21001031"),
745
+ ),
746
+ Variant(
747
+ "BR-FR-06-TXD",
748
+ "BR-FR-06",
749
+ ("BR-FR-06_BT-21_TXD",),
750
+ "Two notes have the subject code TXD.",
751
+ "Deux mentions ont le code sujet TXD.",
752
+ {"notes": [*NOTES, ("TXD", "TVA acquittée sur les débits."), ("TXD", "TVA acquittée sur les débits.")]},
753
+ ),
754
+ Variant(
755
+ "BR-FR-09-payee",
756
+ "BR-FR-09",
757
+ ("BR-FR-09_BT-60",),
758
+ "The payee's SIRET (BT-60) does not start with its SIREN: it is the seller's SIRET.",
759
+ "Le SIRET du bénéficiaire (BT-60) ne commence pas par son SIREN : c'est celui du vendeur.",
760
+ edit=_add_payee([(SELLER["global_id"][0], "0009")], PAYEE_SIREN),
761
+ ),
762
+ Variant(
763
+ "BR-FR-09-ship-to",
764
+ "BR-FR-09",
765
+ ("BR-FR-09_BT-71",),
766
+ "The deliver-to location identifier with scheme 0009 (SIRET, BT-71) is not 14 digits: it has spaces.",
767
+ "L'identifiant du lieu de livraison au schéma 0009 (SIRET, BT-71) n'a pas 14 chiffres : il contient des espaces.",
768
+ edit=_add_ship_to([(SPACED_SIRET, "0009")]),
769
+ ),
770
+ Variant(
771
+ "BR-FR-15-allowance",
772
+ "BR-FR-15",
773
+ ("BR-FR-15_BT-95_BT-102", "BR-FR-15_BT-95_BT-102_LM", "BR-FR-15_BT-95_BT-118", "BR-FR-15_BT-95_BT-118_LM"),
774
+ "A document level allowance (BT-95), and so its VAT breakdown (BT-118), has the VAT category L (Canary Islands), not used in France.",
775
+ "Une remise au niveau du document (BT-95), et donc sa ventilation de TVA (BT-118), a la catégorie L (îles Canaries), non utilisée en France.",
776
+ {"allowances": [("10.25", "95", "Remise commerciale", "L", "7")]},
777
+ ),
778
+ Variant(
779
+ "BR-FR-16-allowance",
780
+ "BR-FR-16",
781
+ ("BR-FR-16_BT-96_BT-103", "BR-FR-16_BT-119"),
782
+ "A document level allowance (BT-96), and so its VAT breakdown (BT-119), has a VAT rate of 21 %, not a French rate.",
783
+ "Une remise au niveau du document (BT-96), et donc sa ventilation de TVA (BT-119), a un taux de 21 %, qui n'est pas un taux français.",
784
+ {"allowances": [("10.25", "95", "Remise commerciale", "S", "21")]},
785
+ ),
786
+ Variant(
787
+ "BR-FR-DEC-04-allowance",
788
+ "BR-FR-DEC-04",
789
+ ("BR-FR-DEC-04_BT-96_BT-103", "BR-FR-16_BT-96_BT-103"),
790
+ "A document level allowance's VAT rate (BT-96) has 3 decimals (20.000); BR-FR-16 rejects it too, as 20.000 is not in its list of rates.",
791
+ "Le taux de TVA d'une remise au niveau du document (BT-96) a 3 décimales (20.000) ; BR-FR-16 le refuse aussi, 20.000 n'étant pas dans sa liste de taux.",
792
+ {"allowances": ALLOWANCE},
793
+ edit=_set_text("SpecifiedTradeAllowanceCharge", "CategoryTradeTax", "RateApplicablePercent", text="20.000"),
794
+ ),
795
+ Variant(
796
+ "BR-FR-24-buyer",
797
+ "BR-FR-24",
798
+ ("BR-FR-24_BT-46",),
799
+ "The buyer's identifier with scheme 0224 (BT-46) contains a space.",
800
+ "L'identifiant de l'acheteur au schéma 0224 (BT-46) contient une espace.",
801
+ {"buyer": {**BUYER, "global_id": ("MAIRIE 42", "0224")}},
802
+ ),
803
+ Variant(
804
+ "BR-FR-26-buyer",
805
+ "BR-FR-26",
806
+ ("BR-FR-26_BT-46",),
807
+ "The buyer's identifier with scheme 0224 (BT-46) is longer than 100 characters.",
808
+ "L'identifiant de l'acheteur au schéma 0224 (BT-46) dépasse 100 caractères.",
809
+ {"buyer": {**BUYER, "global_id": ("M" * 101, "0224")}},
810
+ ),
811
+ Variant(
812
+ "BR-FR-29-AVV",
813
+ "BR-FR-29",
814
+ ("BR-FR-29_AVV", "BR-52"),
815
+ "An invoiced object identifier (BT-18) with reference type AVV is blank (EN 16931 rule BR-52 fires too: a reference is required).",
816
+ "Un identifiant d'objet facturé (BT-18) de type AVV est vide (la règle EN 16931 BR-52 se déclenche aussi : une référence est exigée).",
817
+ edit=_add_documents((" ", "130", None, "AVV")),
818
+ ),
819
+ Variant(
820
+ "BR-FR-CO-09-BT-9",
821
+ "BR-FR-CO-09",
822
+ ("BR-FR-CO-09_BT-23-3",),
823
+ "An already paid invoice (billing frame S2) has no payment due date (BT-9).",
824
+ "Une facture déjà payée (cadre de facturation S2) n'a pas de date d'échéance (BT-9).",
825
+ {"billing_frame": "S2"},
826
+ edit=_paid_without_due_date,
827
+ ),
828
+ Variant(
829
+ "BR-FR-CO-10-BT-29-2",
830
+ "BR-FR-CO-10",
831
+ ("BR-FR-CO-10_BT-29-2",),
832
+ "The seller has two identifiers (BT-29) with the same scheme 0009.",
833
+ "Le vendeur a deux identifiants (BT-29) au même schéma 0009.",
834
+ edit=_add_global_id("SellerTradeParty", SELLER_SIRET_2, "0009"),
835
+ ),
836
+ Variant(
837
+ "BR-FR-CO-10-BT-46-1",
838
+ "BR-FR-CO-10",
839
+ ("BR-FR-CO-10_BT-46-1", "FX-SCH-A-000420"),
840
+ "The buyer's identifier (BT-46) has no scheme identifier; the Factur-X profile rules reject it too.",
841
+ "L'identifiant de l'acheteur (BT-46) n'a pas d'identifiant de schéma ; les règles du profil Factur-X le refusent aussi.",
842
+ edit=_drop_scheme("BuyerTradeParty"),
843
+ ),
844
+ Variant(
845
+ "BR-FR-CO-10-BT-46-2",
846
+ "BR-FR-CO-10",
847
+ ("BR-FR-CO-10_BT-46-2", "FX-SCH-A-000164"),
848
+ "The buyer has two identifiers (BT-46) with the same scheme 0009; the Factur-X profile rules reject it too.",
849
+ "L'acheteur a deux identifiants (BT-46) au même schéma 0009 ; les règles du profil Factur-X le refusent aussi.",
850
+ edit=_add_global_id("BuyerTradeParty", BUYER_SIRET_2, "0009"),
851
+ ),
852
+ Variant(
853
+ "BR-FR-CO-10-BT-60-1",
854
+ "BR-FR-CO-10",
855
+ ("BR-FR-CO-10_BT-60-1", "FX-SCH-A-000470"),
856
+ "The payee's identifier (BT-60) has no scheme identifier; the Factur-X profile rules reject it too.",
857
+ "L'identifiant du bénéficiaire (BT-60) n'a pas d'identifiant de schéma ; les règles du profil Factur-X le refusent aussi.",
858
+ edit=_add_payee([(PAYEE_SIRET, None)], PAYEE_SIREN),
859
+ ),
860
+ Variant(
861
+ "BR-FR-CO-10-BT-60-2",
862
+ "BR-FR-CO-10",
863
+ ("BR-FR-CO-10_BT-60-2", "FX-SCH-A-000468"),
864
+ "The payee has two identifiers (BT-60) with the same scheme 0009; the Factur-X profile rules reject it too.",
865
+ "Le bénéficiaire a deux identifiants (BT-60) au même schéma 0009 ; les règles du profil Factur-X le refusent aussi.",
866
+ edit=_add_payee([(PAYEE_SIRET, "0009"), (luhn_complete(PAYEE_SIREN + "0002"), "0009")], PAYEE_SIREN),
867
+ ),
868
+ Variant(
869
+ "BR-FR-CO-10-BT-71-1",
870
+ "BR-FR-CO-10",
871
+ ("BR-FR-CO-10_BT-71-1", "FX-SCH-A-000453"),
872
+ "The deliver-to location identifier (BT-71) has no scheme identifier; the Factur-X profile rules reject it too.",
873
+ "L'identifiant du lieu de livraison (BT-71) n'a pas d'identifiant de schéma ; les règles du profil Factur-X le refusent aussi.",
874
+ edit=_add_ship_to([(BUYER_SIRET_2, None)]),
875
+ ),
876
+ # Two SIRETs (0009) here would stop France_RFE 1.4.0.04's BR-FR-09 rule with an error (its $siren variable calls
877
+ # substring() on both): two GLNs instead.
878
+ Variant(
879
+ "BR-FR-CO-10-BT-71-2",
880
+ "BR-FR-CO-10",
881
+ ("BR-FR-CO-10_BT-71-2", "FX-SCH-A-000452"),
882
+ "The deliver-to party has two location identifiers (BT-71) with the same scheme 0088 (GLN); the Factur-X profile rules reject it too.",
883
+ "Le lieu de livraison a deux identifiants (BT-71) au même schéma 0088 (GLN) ; les règles du profil Factur-X le refusent aussi.",
884
+ edit=_add_ship_to([(gln("200000000001"), "0088"), (gln("200000000002"), "0088")]),
885
+ ),
886
+ # Amounts with 3 decimals (BR-FR-DEC-01): the value is unchanged, only its notation.
887
+ Variant(
888
+ "BR-FR-DEC-01-BT-92",
889
+ "BR-FR-DEC-01",
890
+ ("BR-FR-DEC-01_BT-92_BT-99", "BR-DEC-01"),
891
+ "A document level allowance amount (BT-92) has 3 decimals (EN 16931 BR-DEC-01 fires too).",
892
+ "Le montant d'une remise au niveau du document (BT-92) a 3 décimales (la règle EN 16931 BR-DEC-01 se déclenche aussi).",
893
+ {"allowances": ALLOWANCE},
894
+ edit=_set_text(
895
+ "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge", "ActualAmount", text="10.250"
896
+ ),
897
+ ),
898
+ Variant(
899
+ "BR-FR-DEC-01-BT-93",
900
+ "BR-FR-DEC-01",
901
+ ("BR-FR-DEC-01_BT-93_BT-100", "BR-DEC-02"),
902
+ "A document level allowance base amount (BT-93) has 3 decimals (EN 16931 BR-DEC-02 fires too).",
903
+ "L'assiette d'une remise au niveau du document (BT-93) a 3 décimales (la règle EN 16931 BR-DEC-02 se déclenche aussi).",
904
+ {"allowances": ALLOWANCE},
905
+ edit=_edit_all(
906
+ _add_element(
907
+ ("ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge"),
908
+ "CalculationPercent",
909
+ "1.00",
910
+ before="ActualAmount",
911
+ ),
912
+ _add_element(
913
+ ("ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge"),
914
+ "BasisAmount",
915
+ "1025.000",
916
+ before="ActualAmount",
917
+ ),
918
+ ),
919
+ ),
920
+ Variant(
921
+ "BR-FR-DEC-01-BT-106",
922
+ "BR-FR-DEC-01",
923
+ ("BR-FR-DEC-01_BT-106", "BR-DEC-09"),
924
+ "The sum of the invoice line net amounts (BT-106) has 3 decimals (EN 16931 BR-DEC-09 fires too).",
925
+ "La somme des montants nets des lignes (BT-106) a 3 décimales (la règle EN 16931 BR-DEC-09 se déclenche aussi).",
926
+ edit=_rewrite_amount("LineTotalAmount", "1025.000"),
927
+ ),
928
+ Variant(
929
+ "BR-FR-DEC-01-BT-107",
930
+ "BR-FR-DEC-01",
931
+ ("BR-FR-DEC-01_BT-107", "BR-DEC-10"),
932
+ "The sum of allowances on document level (BT-107) has 3 decimals (EN 16931 BR-DEC-10 fires too).",
933
+ "La somme des remises au niveau du document (BT-107) a 3 décimales (la règle EN 16931 BR-DEC-10 se déclenche aussi).",
934
+ {"allowances": ALLOWANCE},
935
+ edit=_rewrite_amount("AllowanceTotalAmount", "10.250"),
936
+ ),
937
+ Variant(
938
+ "BR-FR-DEC-01-BT-108",
939
+ "BR-FR-DEC-01",
940
+ ("BR-FR-DEC-01_BT-108", "BR-DEC-11"),
941
+ "The sum of charges on document level (BT-108) has 3 decimals (EN 16931 BR-DEC-11 fires too).",
942
+ "La somme des frais au niveau du document (BT-108) a 3 décimales (la règle EN 16931 BR-DEC-11 se déclenche aussi).",
943
+ {"charges": CHARGE},
944
+ edit=_rewrite_amount("ChargeTotalAmount", "15.000"),
945
+ ),
946
+ Variant(
947
+ "BR-FR-DEC-01-BT-109",
948
+ "BR-FR-DEC-01",
949
+ ("BR-FR-DEC-01_BT-109", "BR-DEC-12"),
950
+ "The total without VAT (BT-109) has 3 decimals (EN 16931 BR-DEC-12 fires too).",
951
+ "Le total HT (BT-109) a 3 décimales (la règle EN 16931 BR-DEC-12 se déclenche aussi).",
952
+ edit=_rewrite_amount("TaxBasisTotalAmount", "1025.000"),
953
+ ),
954
+ Variant(
955
+ "BR-FR-DEC-01-BT-110",
956
+ "BR-FR-DEC-01",
957
+ ("BR-FR-DEC-01_BT-110",),
958
+ "The VAT total (BT-110) has 3 decimals.",
959
+ "Le total de TVA (BT-110) a 3 décimales.",
960
+ edit=_rewrite_amount("TaxTotalAmount", "205.000"),
961
+ ),
962
+ Variant(
963
+ "BR-FR-DEC-01-BT-113",
964
+ "BR-FR-DEC-01",
965
+ ("BR-FR-DEC-01_BT-113", "BR-DEC-16"),
966
+ "The paid amount (BT-113) has 3 decimals (EN 16931 BR-DEC-16 fires too).",
967
+ "Le montant déjà payé (BT-113) a 3 décimales (la règle EN 16931 BR-DEC-16 se déclenche aussi).",
968
+ edit=_prepaid("200.000", "1030.00"),
969
+ ),
970
+ Variant(
971
+ "BR-FR-DEC-01-BT-114",
972
+ "BR-FR-DEC-01",
973
+ ("BR-FR-DEC-01_BT-114", "BR-DEC-17"),
974
+ "The rounding amount (BT-114) has 3 decimals (EN 16931 BR-DEC-17 fires too).",
975
+ "Le montant d'arrondi (BT-114) a 3 décimales (la règle EN 16931 BR-DEC-17 se déclenche aussi).",
976
+ edit=_add_element(
977
+ ("SpecifiedTradeSettlementHeaderMonetarySummation",), "RoundingAmount", "0.000", before="GrandTotalAmount"
978
+ ),
979
+ ),
980
+ Variant(
981
+ "BR-FR-DEC-01-BT-116",
982
+ "BR-FR-DEC-01",
983
+ ("BR-FR-DEC-01_BT-116", "BR-DEC-19"),
984
+ "A VAT category taxable amount (BT-116) has 3 decimals (EN 16931 BR-DEC-19 fires too).",
985
+ "La base d'imposition d'une catégorie de TVA (BT-116) a 3 décimales (la règle EN 16931 BR-DEC-19 se déclenche aussi).",
986
+ edit=_set_text("ApplicableHeaderTradeSettlement", "ApplicableTradeTax", "BasisAmount", text="1025.000"),
987
+ ),
988
+ Variant(
989
+ "BR-FR-DEC-01-BT-117",
990
+ "BR-FR-DEC-01",
991
+ ("BR-FR-DEC-01_BT-117", "BR-DEC-20"),
992
+ "A VAT category tax amount (BT-117) has 3 decimals (EN 16931 BR-DEC-20 fires too).",
993
+ "Le montant de TVA d'une catégorie (BT-117) a 3 décimales (la règle EN 16931 BR-DEC-20 se déclenche aussi).",
994
+ edit=_set_text("ApplicableHeaderTradeSettlement", "ApplicableTradeTax", "CalculatedAmount", text="205.000"),
995
+ ),
996
+ Variant(
997
+ "BR-FR-DEC-01-BT-131",
998
+ "BR-FR-DEC-01",
999
+ ("BR-FR-DEC-01_BT-131", "BR-DEC-23"),
1000
+ "An invoice line net amount (BT-131) has 3 decimals (EN 16931 BR-DEC-23 fires too).",
1001
+ "Le montant net d'une ligne (BT-131) a 3 décimales (la règle EN 16931 BR-DEC-23 se déclenche aussi).",
1002
+ edit=_set_text("SpecifiedTradeSettlementLineMonetarySummation", "LineTotalAmount", text="900.000"),
1003
+ ),
1004
+ Variant(
1005
+ "BR-FR-DEC-01-BT-136",
1006
+ "BR-FR-DEC-01",
1007
+ ("BR-FR-DEC-01_BT-136_BT-141", "BR-DEC-24"),
1008
+ "An invoice line allowance amount (BT-136) has 3 decimals (EN 16931 BR-DEC-24 fires too).",
1009
+ "Le montant d'une remise de ligne (BT-136) a 3 décimales (la règle EN 16931 BR-DEC-24 se déclenche aussi).",
1010
+ {"lines": DISCOUNTED_LINES},
1011
+ edit=_set_text("SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge", "ActualAmount", text="50.000"),
1012
+ ),
1013
+ Variant(
1014
+ "BR-FR-DEC-01-BT-137",
1015
+ "BR-FR-DEC-01",
1016
+ ("BR-FR-DEC-01_BT-137_BT-142", "BR-DEC-25"),
1017
+ "An invoice line allowance base amount (BT-137) has 3 decimals (EN 16931 BR-DEC-25 fires too).",
1018
+ "L'assiette d'une remise de ligne (BT-137) a 3 décimales (la règle EN 16931 BR-DEC-25 se déclenche aussi).",
1019
+ {"lines": DISCOUNTED_LINES},
1020
+ edit=_add_element(
1021
+ ("SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge"),
1022
+ "BasisAmount",
1023
+ "900.000",
1024
+ before="ActualAmount",
1025
+ ),
1026
+ ),
1027
+ Variant(
1028
+ "BR-FR-DEC-02-BT-149",
1029
+ "BR-FR-DEC-02",
1030
+ ("BR-FR-DEC-02_BT-149",),
1031
+ "An item price base quantity (BT-149) has 5 decimals.",
1032
+ "La quantité de base du prix d'un article (BT-149) a 5 décimales.",
1033
+ edit=_add_element(
1034
+ ("SpecifiedLineTradeAgreement", "NetPriceProductTradePrice"),
1035
+ "BasisQuantity",
1036
+ "1.00000",
1037
+ after="ChargeAmount",
1038
+ unitCode="C62",
1039
+ ),
1040
+ ),
1041
+ Variant(
1042
+ "BR-FR-DEC-03-BT-147",
1043
+ "BR-FR-DEC-03",
1044
+ ("BR-FR-DEC-03_BT-147",),
1045
+ "An item price discount (BT-147) has 7 decimals.",
1046
+ "La remise sur le prix d'un article (BT-147) a 7 décimales.",
1047
+ edit=_gross_price("500.00", "50.0000000"),
1048
+ ),
1049
+ Variant(
1050
+ "BR-FR-DEC-03-BT-148",
1051
+ "BR-FR-DEC-03",
1052
+ ("BR-FR-DEC-03_BT-148",),
1053
+ "An item gross price (BT-148) has 7 decimals.",
1054
+ "Le prix brut d'un article (BT-148) a 7 décimales.",
1055
+ edit=_gross_price("500.0000000", "50.00"),
1056
+ ),
1057
+ )
1058
+
1059
+
1060
+ def baseline():
1061
+ return copy.deepcopy(cii.FRENCH)
1062
+
1063
+
1064
+ def build(variant=None):
1065
+ """The baseline, or a variant of it, as an lxml root."""
1066
+ conf = baseline()
1067
+ if variant:
1068
+ conf.update(copy.deepcopy(variant.changes))
1069
+ root = cii.build(conf)
1070
+ if variant and variant.edit:
1071
+ variant.edit(root)
1072
+ return root