2024-12-05 14:36:07 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<rsm:CrossIndustryInvoice
xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100"
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<py:def function= "DateTime(value)" >
<udt:DateTimeString format= "102" > ${value.strftime('%Y%m%d')}</udt:DateTimeString>
</py:def>
<py:def function= "TradeParty(party, address=None, tax_identifier=None)" >
2024-12-10 11:59:09 +00:00
<ram:Name > ${this.quote_text(party.name)}</ram:Name>
2024-12-05 14:36:07 +00:00
<ram:SpecifiedLegalOrganization >
<py:for each= "id, attrs in this.party_legal_ids(party, address)" >
<ram:ID py:attrs= "attrs" > ${id}</ram:ID>
</py:for>
</ram:SpecifiedLegalOrganization>
<ram:PostalTradeAddress py:if= "address" > ${TradeAddress(address)}</ram:PostalTradeAddress>
<ram:SpecifiedTaxRegistration py:if= "tax_identifier and tax_identifier.type == 'eu_vat'" >
<ram:ID schemeID= 'VA' > ${tax_identifier.code}</ram:ID>
</ram:SpecifiedTaxRegistration>
</py:def>
<py:def function= "TradeAddress(address)" >
<ram:PostcodeCode py:if= "address.postal_code" > ${address.postal_code}</ram:PostcodeCode>
<py:with vars= "lines = (address.street or '').splitlines()" >
2024-12-10 11:59:09 +00:00
<ram:LineOne py:if= "len(lines) > 0" > ${this.quote_text(lines[0])}</ram:LineOne>
<ram:LineTwo py:if= "len(lines) > 1" > ${this.quote_text(lines[1])}</ram:LineTwo>
<ram:LineThree py:if= "len(lines) > 2" > ${(lines[2])}</ram:LineThree>
2024-12-05 14:36:07 +00:00
</py:with>
2024-12-10 11:59:09 +00:00
<ram:CityName py:if= "address.city" > ${(address.city)}</ram:CityName>
2024-12-05 14:36:07 +00:00
<ram:CountryID py:if= "address.country" > ${address.country.code}</ram:CountryID>
2024-12-10 11:59:09 +00:00
<ram:CountrySubDivisionName py:if= "address.subdivision" > ${this.quote_text(address.subdivision.name)}</ram:CountrySubDivisionName>
2024-12-05 14:36:07 +00:00
</py:def>
<py:def function= "TradeTax(tax, amount=None, base=None)" >
<ram:ApplicableTradeTax >
<ram:CalculatedAmount py:if= "amount" py:attrs= "{'currencyID': this.invoice.currency.code}" > ${amount * this.type_sign}</ram:CalculatedAmount>
2024-12-09 12:24:39 +00:00
<ram:TypeCode > ${this.tax_unece_code(tax)}</ram:TypeCode>
2024-12-05 14:36:07 +00:00
<ram:ExemptionReason py:if= "tax.legal_notice" > ${tax.legal_notice}</ram:ExemptionReason>
<ram:BasisAmount py:if= "base" > ${base * this.type_sign}</ram:BasisAmount>
2024-12-09 12:24:39 +00:00
<ram:CategoryCode > ${this.tax_category_code(tax)}</ram:CategoryCode>
2024-12-05 14:36:07 +00:00
<ram:RateApplicablePercent py:if= "tax.type == 'percentage'" > ${tax.rate * 100}</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
</py:def>
<rsm:ExchangedDocumentContext >
<ram:GuidelineSpecifiedDocumentContextParameter >
<ram:ID > urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
<rsm:ExchangedDocument >
2024-12-10 11:59:09 +00:00
<ram:ID > ${this.quote_text(this.invoice.number)}</ram:ID>
<ram:Name py:if= "this.invoice.description" > ${this.quote_text(this.invoice.description)}</ram:Name>
2024-12-05 14:36:07 +00:00
<ram:TypeCode > ${this.type_code}</ram:TypeCode>
<ram:IssueDateTime >
${DateTime(this.invoice.invoice_date)}
</ram:IssueDateTime>
<py:for each= "comment_line in this.get_list_of_comments()" >
<ram:IncludedNote >
<ram:ContentCode py:if= "comment_line.get('content_code')" > ${comment_line['content_code']}</ram:ContentCode>
<ram:Content py:if= "comment_line.get('content')" > ${comment_line['content']}</ram:Content>
<ram:SubjectCode py:if= "comment_line.get('subject_content')" > ${comment_line['subject_content']}</ram:SubjectCode>
</ram:IncludedNote>
</py:for>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction >
<ram:IncludedSupplyChainTradeLineItem py:for= "line_id, line in enumerate(this.lines, 1)" >
<ram:AssociatedDocumentLineDocument >
<ram:LineID > ${line_id}</ram:LineID>
</ram:AssociatedDocumentLineDocument>
2024-12-09 12:24:39 +00:00
<ram:SpecifiedTradeProduct >
<ram:ID py:if= "line.product and line.product.code" > ${line.product.code}</ram:ID>
2024-12-10 11:59:09 +00:00
<ram:Name > ${this.quote_text(line.product.name if line.product else '')}</ram:Name>
<ram:Description py:if= "line.description" > ${this.quote_text(line.description)}</ram:Description>
2024-12-05 14:36:07 +00:00
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement >
<ram:NetPriceProductTradePrice >
2025-01-28 11:50:55 +00:00
<ram:ChargeAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.round_unitprice(line.unit_price)}</ram:ChargeAmount>
2024-12-05 14:36:07 +00:00
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery >
<ram:BilledQuantity py:attrs= "{'unitCode': line.unit.unece_code} if line.unit and line.unit.unece_code else {}" > ${line.quantity * this.type_sign}</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement >
2025-01-09 10:50:09 +00:00
${TradeTax(this.invoice_line_tax(line))}
2024-12-05 14:36:07 +00:00
<ram:SpecifiedTradeSettlementLineMonetarySummation >
<ram:LineTotalAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${line.amount}</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:ApplicableHeaderTradeAgreement >
<ram:SellerTradeParty >
${TradeParty(this.seller_trade_party, this.seller_trade_address, this.seller_trade_tax_identifier)}
</ram:SellerTradeParty>
<ram:BuyerTradeParty >
${TradeParty(this.buyer_trade_party, this.buyer_trade_address, this.buyer_trade_tax_identifier)}
</ram:BuyerTradeParty>
<ram:SellerOrderReferencedDocument py:if= "this.invoice.type == 'in'" >
2024-12-10 11:59:09 +00:00
<ram:IssuerAssignedID > ${this.quote_text(this.invoice.reference)}</ram:IssuerAssignedID>
2024-12-05 14:36:07 +00:00
</ram:SellerOrderReferencedDocument>
<ram:BuyerOrderReferencedDocument py:if= "this.invoice.type == 'out'" >
2024-12-10 11:59:09 +00:00
<ram:IssuerAssignedID > ${this.quote_text(this.invoice.reference)}</ram:IssuerAssignedID>
2024-12-05 14:36:07 +00:00
</ram:BuyerOrderReferencedDocument>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery >
<ram:ShipToTradeParty py:if= "this.ship_to_trade_party" >
${TradeParty(this.ship_to_trade_party, this.ship_to_trade_address)}
</ram:ShipToTradeParty>
<ram:ShipFromTradeParty py:if= "this.ship_from_trade_party" >
${TradeParty(this.ship_from_trade_party, this.ship_from_trade_address)}
</ram:ShipFromTradeParty>
</ram:ApplicableHeaderTradeDelivery>
<ram:ApplicableHeaderTradeSettlement >
2024-12-10 11:59:09 +00:00
<ram:PaymentReference > ${this.quote_text(this.payment_reference)}</ram:PaymentReference>
2024-12-05 14:36:07 +00:00
<ram:InvoiceCurrencyCode > ${this.invoice.currency.code}</ram:InvoiceCurrencyCode>
2024-12-10 11:59:09 +00:00
<py:if test= "len(this.company_bank_accounts()) == 0" >
<ram:SpecifiedTradeSettlementPaymentMeans >
<ram:TypeCode > 1</ram:TypeCode>
</ram:SpecifiedTradeSettlementPaymentMeans>
</py:if>
<py:for each= "banknumber in this.company_bank_accounts()" >
<ram:SpecifiedTradeSettlementPaymentMeans >
<ram:TypeCode > 30</ram:TypeCode>
<ram:Information > Wire transfer</ram:Information>
<ram:PayeePartyCreditorFinancialAccount >
<ram:IBANID > ${banknumber.number_compact}</ram:IBANID>
<ram:AccountName > ${this.quote_text(banknumber.account.bank.party.rec_name)}</ram:AccountName>
</ram:PayeePartyCreditorFinancialAccount>
<ram:PayeeSpecifiedCreditorFinancialInstitution >
<ram:BICID > ${banknumber.account.bank.bic}</ram:BICID>
</ram:PayeeSpecifiedCreditorFinancialInstitution>
</ram:SpecifiedTradeSettlementPaymentMeans>
</py:for>
2024-12-05 14:36:07 +00:00
<py:for each= "tax in this.invoice.taxes" >
${TradeTax(tax.tax, tax.amount, tax.base)}
</py:for>
<ram:SpecifiedTradePaymentTerms py:for= "line in this.invoice.lines_to_pay" >
<ram:Description py:if= "this.invoice.payment_term and this.invoice.payment_term.description" > ${this.invoice.payment_term.description}</ram:Description>
<ram:DueDateDateTime >
${DateTime(line.maturity_date)}
</ram:DueDateDateTime>
<ram:PartialPaymentAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${(line.amount_second_currency or (line.debit - line.credit)) * this.type_sign}</ram:PartialPaymentAmount>
</ram:SpecifiedTradePaymentTerms>
<ram:SpecifiedTradeSettlementHeaderMonetarySummation >
<ram:LineTotalAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.invoice.untaxed_amount * this.type_sign}</ram:LineTotalAmount>
<ram:TaxBasisTotalAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.invoice.untaxed_amount * this.type_sign}</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.invoice.tax_amount * this.type_sign}</ram:TaxTotalAmount>
<ram:GrandTotalAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.invoice.total_amount * this.type_sign}</ram:GrandTotalAmount>
<ram:DuePayableAmount py:attrs= "{'currencyID': this.invoice.currency.code}" > ${this.invoice.amount_to_pay * this.type_sign}</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>