<?xml version="1.0"?>
<t name="Sales Order Portal Content" t-name="sale.sale_order_portal_content">
        <!-- Intro -->
        <div id="introduction" t-attf-class="pb-2 pt-3 #{'card-header bg-white' if report_type == 'html' else ''}">
          <h2 class="my-0">
                <t t-out="sale_order.type_name"/>
                <em t-out="sale_order.name"/>
            </h2>
        </div>

        <div t-attf-class="#{'card-body' if report_type == 'html' else ''}">
            <!-- Informations -->
            <div id="informations">
                <div t-if="sale_order.transaction_ids and not invoices and sale_order.state in ('sent', 'sale') and portal_confirmation == 'pay' and not success and not error" t-att-data-order-id="sale_order.id">
                    <t t-if="sale_order.transaction_ids">
                        <t t-call="payment.transaction_status">
                            <t t-set="tx" t-value="sale_order.get_portal_last_transaction()"/>
                        </t>
                    </t>
                </div>
                <div class="row" id="so_date">
                    <div class="mb-3 col-6">
                      <t t-if="sale_order.state in ['sale', 'done', 'cancel']">
                        <strong>Order Date:</strong>
                      </t>
                      <t t-else="">
                         <strong>Quotation Date:</strong>
                      </t>
                      <span t-field="sale_order.date_order" t-options="{&quot;widget&quot;: &quot;date&quot;}"/>
                    </div>
                    <div class="mb-3 col-6" t-if="sale_order.validity_date and sale_order.state in ['draft', 'sent']">
                        <strong>Expiration Date:</strong> <span t-field="sale_order.validity_date" t-options="{&quot;widget&quot;: &quot;date&quot;}"/>
                    </div>
                </div>
                <div class="row" id="invoicing_shipping_address">
                    <div class="col-lg-6">
                        <strong class="d-block mb-1">
                            <t t-if="sale_order.partner_shipping_id == sale_order.partner_invoice_id">
                                Invoicing and Shipping Address:
                            </t>
                            <t t-else="">
                                Invoicing Address:
                            </t>
                        </strong>
                        <address t-field="sale_order.partner_invoice_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
                    </div>
                    <div t-if="sale_order.partner_shipping_id != sale_order.partner_invoice_id" id="shipping_address" class="col-lg-6">
                        <strong class="d-block mb-1">
                            Shipping Address:
                        </strong>
                        <address t-field="sale_order.partner_shipping_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
                    </div>
                </div>

                <t t-set="invoices" t-value="sale_order.invoice_ids.filtered(lambda i: i.state not in ['draft', 'cancel'])"/>
                <div t-if="invoices" class="row">
                    <div class="col">
                        <strong class="d-block mb-1">Invoices</strong>
                        <ul class="list-group mb-4">
                            <t t-foreach="invoices" t-as="i">
                                <t t-set="report_url" t-value="i.get_portal_url(report_type='pdf', download=True)"/>
                                <t t-set="authorized_tx_ids" t-value="i.transaction_ids.filtered(lambda tx: tx.state == 'authorized')"/>
                                <div class="d-flex flex-wrap align-items-center justify-content-between">
                                    <div>
                                        <a t-att-href="report_url">
                                            <span t-out="i.name"/>
                                        </a>
                                        <div class="small d-lg-inline-block">Date: <span class="text-muted" t-field="i.invoice_date"/></div>
                                    </div>
                                    <span t-if="i.payment_state in ('paid', 'in_payment')" class="small badge text-bg-success orders_label_text_align">
                                        <i class="fa fa-fw fa-check"/> <b>Paid</b>
                                    </span>
                                    <span t-elif="i.payment_state == 'reversed'" class="small badge text-bg-success orders_label_text_align">
                                        <i class="fa fa-fw fa-check"/> <b>Reversed</b>
                                    </span>
                                    <span t-elif="authorized_tx_ids" class="small badge text-bg-success orders_label_text_align">
                                        <i class="fa fa-fw fa-check"/> <b>Authorized</b>
                                    </span>
                                    <span t-else="" class="small badge text-bg-info orders_label_text_align">
                                        <i class="fa fa-fw fa-clock-o"/> <b>Waiting Payment</b>
                                    </span>
                                </div>
                            </t>
                        </ul>
                    </div>
                </div>
            </div>

            <section id="details" style="page-break-inside: auto;" class="mt32">
                <h3 id="details">Pricing</h3>

                <t t-set="display_discount" t-value="True in [line.discount &gt; 0 for line in sale_order.order_line]"/>

                <div class="table-responsive">
                    <table t-att-data-order-id="sale_order.id" t-att-data-token="sale_order.access_token" class="table table-sm" id="sales_order_table">
                        <thead class="bg-100">
                            <tr>
                                <th class="text-start" id="product_name_header">Products</th>
                                <th class="text-end">Quantity</th>
                                <th t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                    Unit Price
                                </th>
                                <th t-if="display_discount" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                    <span>Disc.%</span>
                                </th>
                                <th t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                    <span>Taxes</span>
                                </th>
                                <th class="text-end">
                                    <span groups="account.group_show_line_subtotals_tax_excluded">Amount</span>
                                    <span groups="account.group_show_line_subtotals_tax_included">Total Price</span>
                                </th>
                            </tr>
                        </thead>
                        <tbody class="sale_tbody">

                            <t t-set="current_subtotal" t-value="0"/>
                            <t t-set="lines_to_report" t-value="sale_order._get_order_lines_to_report()"/>

                            <t t-foreach="lines_to_report" t-as="line">

                                    <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
                                    <t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>

                                <tr t-att-class="'bg-200 fw-bold o_line_section' if line.display_type == 'line_section' else 'fst-italic o_line_note' if line.display_type == 'line_note' else ''">
                                    <t t-if="not line.display_type">
                                        <td id="product_name">
                                            <span t-field="line.name"/>
                                        </td>
                                        <td class="text-end">
                                            <div id="quote_qty">
                                                <span t-field="line.product_uom_qty"/>
                                                <span t-field="line.product_uom"/>
                                            </div>
                                        </td>
                                        <td t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                            <div t-if="line.discount &gt;= 0" t-field="line.price_unit" t-att-style="line.discount and 'text-decoration: line-through' or None" t-att-class="(line.discount and 'text-danger' or '') + ' text-end'"/>
                                            <div t-if="line.discount">
                                                <t t-out="(1-line.discount / 100.0) * line.price_unit" t-options="{&quot;widget&quot;: &quot;float&quot;, &quot;decimal_precision&quot;: &quot;Product Price&quot;}"/>
                                            </div>
                                        </td>
                                        <td t-if="display_discount" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                            <strong t-if="line.discount &gt; 0" class="text-info">
                                                <t t-out="((line.discount % 1) and '%s' or '%d') % line.discount"/>%
                                            </strong>
                                        </td>
                                        <td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                            <span t-out="', '.join(map(lambda x: (x.description or x.name), line.tax_id))"/>
                                        </td>
                                        <td t-if="not line.is_downpayment" class="text-end">
                                            <span class="oe_order_line_price_subtotal" t-field="line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
                                            <span class="oe_order_line_price_total" t-field="line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
                                        </td>
                                    </t>
                                    <t t-if="line.display_type == 'line_section'">
                                        <td colspan="99">
                                            <span t-field="line.name"/>
                                        </td>
                                        <t t-set="current_section" t-value="line"/>
                                        <t t-set="current_subtotal" t-value="0"/>
                                    </t>
                                    <t t-if="line.display_type == 'line_note'">
                                        <td colspan="99">
                                            <span t-field="line.name"/>
                                        </td>
                                    </t>
                                </tr>
                                <tr t-if="current_section and (line_last or lines_to_report[line_index+1].display_type == 'line_section') and not line.is_downpayment" class="is-subtotal text-end">
                                    <td colspan="99">
                                        <strong class="mr16">Subtotal</strong>
                                        <span t-out="current_subtotal" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: sale_order.pricelist_id.currency_id}"/>
                                    </td>
                                </tr>
                            </t>
                        </tbody>
                    </table>
                </div>

                <div id="total" class="row" name="total" style="page-break-inside: avoid;">
                    <div t-attf-class="#{'col-6' if report_type != 'html' else 'col-sm-7 col-md-6'} ms-auto">
                        <t t-call="sale.sale_order_portal_content_totals_table"/>
                    </div>
                </div>
            </section>

            <section t-if="sale_order.signature" id="signature" name="Signature">
                <div class="row mt-4" name="signature">
                    <div t-attf-class="#{'col-3' if report_type != 'html' else 'col-sm-7 col-md-4'} ms-auto text-center">
                        <h5>Signature</h5>
                        <img t-att-src="image_data_uri(sale_order.signature)" style="max-height: 6rem; max-width: 100%;"/>
                        <p t-field="sale_order.signed_by"/>
                    </div>
                </div>
            </section>

            <section t-if="not is_html_empty(sale_order.note)" id="terms" class="mt-5">
                <h3 class="">Terms &amp; Conditions</h3>
                <hr class="mt-0 mb-1"/>
                <t t-if="sale_order.terms_type == 'html'">
                    <!-- Note is plain text. This ensures a clickable link  -->
                    <t t-set="tc_url" t-value="'%s/terms' % (sale_order.get_base_url())"/>
                    <em>Terms &amp; Conditions: <a href="/terms"><t t-out="tc_url"/></a></em>
                </t>
                <t t-else="">
                    <em t-field="sale_order.note"/>
                </t>
            </section>

            <section t-if="sale_order.payment_term_id" class="mt-5">
                <h3 class="">Payment terms</h3>
                <hr class="mt-0 mb-1"/>
                <span t-field="sale_order.payment_term_id.note"/>
            </section>
        </div>
    </t>

    