<?xml version="1.0"?>
<t name="Purchase Order Portal Content" t-name="purchase.purchase_order_portal_content">
      <!-- Intro -->
      <div id="introduction" class="mt-5 mt-lg-0 pb-2 pt-0">
        <h2 class="my-0">
          <t t-if="order.state in ['draft', 'sent']">Request for Quotation</t>
          <t t-else="1">
            Purchase Order
          </t>
          <em t-esc="order.name"/>
        </h2>
      </div>

      <div>
          <!-- Informations -->
          <div id="informations">
              <div class="row" id="po_date">
                  <div class="mb-3 col-6">
                    <t t-if="order.state in ['draft', 'sent']">
                      <strong>Request For Quotation Date:</strong>
                    </t>
                    <t t-if="order.state in ['purchase', 'done', 'cancel']">
                      <strong>Order Date:</strong>
                    </t>
                    <span t-field="order.date_order" t-options="{&quot;widget&quot;: &quot;date&quot;}"/>
                  </div>
              </div>
              <div class="row">
                  <div class="col-lg-6">
                    <strong class="d-block mb-1">From:</strong>
                    <address t-field="order.company_id.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
                    <strong>Confirmation Date:</strong> <span t-field="order.date_approve" t-options="{&quot;widget&quot;: &quot;date&quot;}"/><br/>
                    <div t-att-class="'d-inline' if order.date_planned else 'd-none'">
                      <strong>Receipt Date:</strong><span class="ms-1" t-field="order.date_planned" t-options="{&quot;widget&quot;: &quot;date&quot;}"/>
                    </div>
                  </div>
              </div>

              <t t-set="invoices" t-value="[i for i in order.invoice_ids if 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)"/>
                              <div class="d-flex flex-wrap align-items-center justify-content-between">
                                  <div>
                                      <a t-att-href="report_url">
                                          <span t-esc="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="badge rounded-pill text-bg-success small"><i class="fa fa-fw fa-check"/>Paid</span>
                                  <span t-elif="i.payment_state == 'reversed'" class="badge rounded-pill text-bg-success small"><i class="fa fa-fw fa-check"/>Reversed</span>
                                  <span t-else="" class="small badge rounded-pill text-bg-primary"><i class="fa fa-fw fa-clock-o"/>Waiting Payment</span>
                              </div>
                          </t>
                      </ul>
                  </div>
              </div>
          </div>

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

              <div class="table-responsive">
                <table t-att-data-order-id="order.id" t-att-data-token="order.access_token" class="table table-sm" id="purchase_order_table">
                    <t t-set="display_price_and_taxes" t-value="not update_dates and order.state in ['sent', 'purchase', 'done']"/>
                    <thead class="bg-100">
                        <tr>
                            <th class="text-start">Products</th>
                            <th class="text-end">Quantity</th>
                            <th t-if="update_dates" class="text-end">Scheduled Date</th>
                            <th t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">Unit Price</th>
                            <th t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                <span>Taxes</span>
                            </th>
                            <th t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">Disc.%</th>
                            <th class="text-end" t-if="not update_dates and order.state in ['purchase', 'done']">
                                <span>Amount</span>
                            </th>
                        </tr>
                    </thead>
                    <tbody class="purchase_tbody">

                          <t t-set="current_subtotal" t-value="0"/>

                          <t t-foreach="order.order_line" t-as="line">

                              <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>

                            <tr t-att-class="'fw-bold o_line_section' if line.display_type == 'line_section' else 'fst-italic text-break' if line.display_type == 'line_note' else ''">
                                <t t-if="not line.display_type">
                                    <td id="product_name" class="d-flex">
                                        <img t-att-src="line.product_id.image_128 and image_data_uri(line.product_id.image_128) or '/web/static/img/placeholder.png'" alt="Product" class="d-none d-lg-inline o_purchase_portal_product_image"/>
                                        <span t-field="line.name"/>
                                    </td>
                                    <td class="text-end">
                                        <div id="quote_qty">
                                            <span t-field="line.product_qty"/>
                                            <span t-field="line.product_uom" groups="uom.group_uom"/>
                                        </div>
                                    </td>
                                    <td t-if="update_dates" class="text-end">
                                        <div class="container">
                                          <div class="mb-3">
                                            <div class="input-group date">
                                                <input type="text" class="form-control datetimepicker-input o-purchase-datetimepicker text-end" t-att-data-access-token="order.access_token" t-att-data-order-id="order.id" t-att-data-line-id="line.id" t-att-data-value="line.date_planned.isoformat()"/>
                                            </div>
                                          </div>
                                        </div>
                                    </td>
                                    <td t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                        <div t-field="line.price_unit" class="text-end"/>
                                    </td>
                                    <td t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                        <span t-out="', '.join(map(lambda x: (x.name), line.taxes_id))"/>
                                    </td>
                                    <td t-if="display_price_and_taxes" t-attf-class="text-end {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
                                        <div t-field="line.discount" class="text-end"/>
                                    </td>
                                    <td class="text-end" t-if="not update_dates and order.state in ['purchase', 'done']">
                                        <span class="oe_order_line_price_subtotal" t-field="line.price_subtotal"/>
                                    </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>

                            <t t-if="current_section and (line_last or order.order_line[line_index+1].display_type == 'line_section') and order.state in ['purchase', 'done']">
                                <tr class="is-subtotal text-end">
                                    <td colspan="99">
                                        <strong class="mr16">Subtotal</strong>
                                        <span t-esc="current_subtotal" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: order.currency_id}"/>
                                    </td>
                                </tr>
                            </t>
                        </t>
                    </tbody>
                </table>
              </div>

              <div id="total" t-if="order.state in ['purchase', 'done']" class="row" name="total" style="page-break-inside: avoid;">
                  <div t-attf-class="#{'col-4' if report_type != 'html' else 'col-sm-7 col-md-5'} ms-auto">
                      <t t-call="purchase.purchase_order_portal_content_totals_table"/>
                  </div>
              </div>
          </section>

          <section id="terms" class="mt-5" t-if="order.notes">
              <h3 class="">Terms &amp; Conditions</h3>
              <hr class="mt-0 mb-1"/>
              <em t-field="order.notes"/>
          </section>

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

  