<?xml version="1.0"?>
<t t-name="account_edi_ubl_cii.ubl_20_InvoiceType">
        <t xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
            <cbc:UBLVersionID t-out="vals.get('ubl_version_id')"/>
            <cbc:CustomizationID t-out="vals.get('customization_id')"/>
            <cbc:ProfileID t-out="vals.get('profile_id')"/>
            <cbc:ID t-out="vals.get('id')"/>
            <cbc:IssueDate t-out="vals.get('issue_date')"/>
            <cbc:InvoiceTypeCode t-if="invoice.move_type == 'out_invoice'" t-att="vals.get('invoice_type_code_attrs', {})" t-out="vals.get('invoice_type_code')"/>
            <t t-foreach="vals.get('note_vals', [])" t-as="note">
                <cbc:Note t-out="note"/>
            </t>
            <cbc:DocumentCurrencyCode t-att="vals.get('document_currency_code_attrs', {})" t-out="invoice.currency_id.name.upper()"/>
            <t t-foreach="vals.get('invoice_period_vals_list', [])" t-as="foreach_vals">
                <cac:InvoicePeriod>
                    <cbc:StartDate t-out="foreach_vals.get('start_date')"/>
                    <cbc:EndDate t-out="foreach_vals.get('end_date')"/>
                </cac:InvoicePeriod>
            </t>
            <cac:OrderReference>
                <cbc:ID t-esc="vals.get('order_reference')"/>
                <cbc:SalesOrderID t-esc="vals.get('sales_order_id')"/>
            </cac:OrderReference>
            <cac:BillingReference t-if="vals.get('billing_reference_vals')">
                <cac:InvoiceDocumentReference>
                    <cbc:ID t-out="vals['billing_reference_vals'].get('id')"/>
                    <cbc:IssueDate t-out="vals['billing_reference_vals'].get('issue_date')"/>
                </cac:InvoiceDocumentReference>
            </cac:BillingReference>
            <cac:AccountingSupplierParty>
                <t t-set="accounting_supplier_vals" t-value="vals.get('accounting_supplier_party_vals', {})"/>
                <cac:Party>
                    <t t-call="{{PartyType_template}}">
                        <t t-set="vals" t-value="accounting_supplier_vals.get('party_vals', {})"/>
                    </t>
                </cac:Party>
            </cac:AccountingSupplierParty>
            <cac:AccountingCustomerParty>
                <t t-set="accounting_customer_vals" t-value="vals.get('accounting_customer_party_vals', {})"/>
                <cac:Party>
                    <t t-call="{{PartyType_template}}">
                        <t t-set="vals" t-value="accounting_customer_vals.get('party_vals', {})"/>
                    </t>
                </cac:Party>
            </cac:AccountingCustomerParty>
            <t id="delivery_foreach" t-foreach="vals.get('delivery_vals_list', [])" t-as="foreach_vals">
                <cac:Delivery>
                    <cbc:ActualDeliveryDate t-out="foreach_vals.get('actual_delivery_date')"/>
                    <cac:DeliveryLocation>
                        <cac:Address>
                            <t t-call="{{AddressType_template}}">
                                <t t-set="vals" t-value="foreach_vals.get('delivery_location_vals', {}).get('delivery_address_vals', {})"/>
                            </t>
                        </cac:Address>
                    </cac:DeliveryLocation>
                </cac:Delivery>
            </t>
            <!-- In UBL 2.0 PaymentMeans is only present for Invoice
            while in UBL 2.1, it is present for Invoice and CreditNote
            http://www.datypic.com/sc/ubl20/e-ns19_Invoice.html
            http://www.datypic.com/sc/ubl20/e-ns14_CreditNote.html -->
            <t t-if="invoice.move_type == 'out_invoice'">
                <t t-foreach="vals.get('payment_means_vals_list', [])" t-as="foreach_vals">
                    <cac:PaymentMeans>
                        <t t-call="{{PaymentMeansType_template}}">
                            <t t-set="vals" t-value="foreach_vals"/>
                        </t>
                    </cac:PaymentMeans>
                </t>
            </t>
            <t t-foreach="vals.get('payment_terms_vals', [])" t-as="foreach_vals">
                <cac:PaymentTerms>
                    <t t-foreach="foreach_vals.get('note_vals', [])" t-as="note">
                        <cbc:Note t-out="note"/>
                    </t>
                </cac:PaymentTerms>
            </t>
            <t t-foreach="vals.get('allowance_charge_vals', [])" t-as="foreach_vals">
                <cac:AllowanceCharge>
                    <t t-call="{{AllowanceChargeType_template}}">
                        <t t-set="vals" t-value="foreach_vals"/>
                    </t>
                </cac:AllowanceCharge>
            </t>
            <t t-foreach="vals.get('tax_total_vals', [])" t-as="foreach_vals">
                <cac:TaxTotal>
                    <t t-call="{{TaxTotalType_template}}">
                        <t t-set="vals" t-value="foreach_vals"/>
                    </t>
                </cac:TaxTotal>
            </t>
            <cac:LegalMonetaryTotal>
                <t t-set="monetary_tot_vals" t-value="vals.get('legal_monetary_total_vals', {})"/>
                <cbc:LineExtensionAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('line_extension_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:TaxExclusiveAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('tax_exclusive_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:TaxInclusiveAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('tax_inclusive_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:AllowanceTotalAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('allowance_total_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:ChargeTotalAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('charge_total_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:PrepaidAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('prepaid_amount'), monetary_tot_vals.get('currency_dp'))"/>
                <cbc:PayableAmount t-att-currencyID="monetary_tot_vals['currency'].name" t-out="format_float(monetary_tot_vals.get('payable_amount'), monetary_tot_vals.get('currency_dp'))"/>
            </cac:LegalMonetaryTotal>
            <t t-foreach="vals.get('invoice_line_vals', [])" t-as="foreach_vals">
                <cac:InvoiceLine t-if="invoice.move_type == 'out_invoice'">
                    <t t-call="{{InvoiceLineType_template}}">
                        <t t-set="vals" t-value="foreach_vals"/>
                    </t>
                </cac:InvoiceLine>
                <cac:CreditNoteLine t-if="invoice.move_type == 'out_refund'">
                    <t t-call="{{InvoiceLineType_template}}">
                        <t t-set="vals" t-value="foreach_vals"/>
                    </t>
                </cac:CreditNoteLine>
            </t>
        </t>
    </t>

    