|
| 1 | +from datetime import date, datetime, timedelta, timezone |
| 2 | +from decimal import Decimal |
| 3 | + |
| 4 | +from drafthorse.models.accounting import ApplicableTradeTax |
| 5 | +from drafthorse.models.document import Document |
| 6 | +from drafthorse.models.note import IncludedNote |
| 7 | +from drafthorse.models.party import TaxRegistration |
| 8 | +from drafthorse.models.payment import PaymentMeans, PaymentTerms |
| 9 | +from drafthorse.models.trade import AdvancePayment, IncludedTradeTax |
| 10 | +from drafthorse.models.tradelines import LineItem |
| 11 | +from drafthorse.pdf import attach_xml |
| 12 | + |
| 13 | +# Build data structure |
| 14 | +doc = Document() |
| 15 | +doc.context.guideline_parameter.id = "urn:cen.eu:en16931:2017" |
| 16 | +doc.header.id = "RE1337" |
| 17 | +doc.header.type_code = "380" |
| 18 | +doc.header.issue_date_time = date.today() |
| 19 | + |
| 20 | +doc.header.notes.add(IncludedNote(content="Test Note 1")) |
| 21 | + |
| 22 | +doc.trade.agreement.buyer.name = "Kunde GmbH" |
| 23 | +doc.trade.agreement.buyer.address.country_id = "DE" |
| 24 | + |
| 25 | +doc.trade.settlement.currency_code = "EUR" |
| 26 | +doc.trade.settlement.payment_means.add(PaymentMeans(type_code="ZZZ")) |
| 27 | + |
| 28 | +doc.trade.agreement.seller.name = "Lieferant GmbH" |
| 29 | +doc.trade.agreement.seller.address.country_id = "DE" |
| 30 | +doc.trade.agreement.seller.address.country_subdivision = "Bayern" |
| 31 | +doc.trade.agreement.seller.tax_registrations.add( |
| 32 | + TaxRegistration( |
| 33 | + id=("VA", "DE000000000") |
| 34 | + ) |
| 35 | +) |
| 36 | + |
| 37 | +advance = AdvancePayment( |
| 38 | + received_date=datetime.now(timezone.utc), paid_amount=Decimal(42) |
| 39 | +) |
| 40 | +advance.included_trade_tax.add( |
| 41 | + IncludedTradeTax( |
| 42 | + calculated_amount=Decimal(0), |
| 43 | + type_code="VAT", |
| 44 | + category_code="E", |
| 45 | + rate_applicable_percent=Decimal(0), |
| 46 | + ) |
| 47 | +) |
| 48 | +doc.trade.settlement.advance_payment.add(advance) |
| 49 | + |
| 50 | +li = LineItem() |
| 51 | +li.document.line_id = "1" |
| 52 | +li.product.name = "Rainbow" |
| 53 | +li.agreement.gross.amount = Decimal("1198.8") |
| 54 | +li.agreement.gross.basis_quantity = (Decimal("1.0000"), "C62") # C62 == unit |
| 55 | +li.agreement.net.amount = Decimal("999") |
| 56 | +li.agreement.net.basis_quantity = (Decimal("1.0000"), "C62") # C62 == unit |
| 57 | +li.delivery.billed_quantity = (Decimal("1.0000"), "C62") # C62 == unit |
| 58 | +li.settlement.trade_tax.type_code = "VAT" |
| 59 | +li.settlement.trade_tax.category_code = "S" |
| 60 | +li.settlement.trade_tax.rate_applicable_percent = Decimal("20.00") |
| 61 | +li.settlement.monetary_summation.total_amount = Decimal("999.00") |
| 62 | +doc.trade.items.add(li) |
| 63 | + |
| 64 | +trade_tax = ApplicableTradeTax() |
| 65 | +trade_tax.calculated_amount = Decimal("199.80") |
| 66 | +trade_tax.basis_amount = Decimal("999.00") |
| 67 | +trade_tax.type_code = "VAT" |
| 68 | +trade_tax.category_code = "S" |
| 69 | +trade_tax.rate_applicable_percent = Decimal("20.00") |
| 70 | +doc.trade.settlement.trade_tax.add(trade_tax) |
| 71 | + |
| 72 | +doc.trade.settlement.monetary_summation.line_total = Decimal("999.00") |
| 73 | +doc.trade.settlement.monetary_summation.charge_total = Decimal("0.00") |
| 74 | +doc.trade.settlement.monetary_summation.allowance_total = Decimal("0.00") |
| 75 | +doc.trade.settlement.monetary_summation.tax_basis_total = Decimal("999.00") |
| 76 | +doc.trade.settlement.monetary_summation.tax_total = (Decimal("199.80"), "EUR") |
| 77 | +doc.trade.settlement.monetary_summation.grand_total = Decimal("1198.8") |
| 78 | +doc.trade.settlement.monetary_summation.due_amount = Decimal("1198.8") |
| 79 | + |
| 80 | +terms = PaymentTerms() |
| 81 | +terms.due = datetime.now(timezone.utc) + timedelta(days=30) |
| 82 | +doc.trade.settlement.terms.add(terms) |
| 83 | + |
| 84 | +# Generate XML file |
| 85 | +xml = doc.serialize(schema="FACTUR-X_EXTENDED") |
0 commit comments