<odoo>
  <record id="action_report_wo" model="ir.actions.report">
        <field name="name">WO Form</field>
        <field name="model">sos_wo</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">sos_inventory.report_wo</field>
        <field name="report_file">sos_inventory.report_wo</field>
        <field name="binding_model_id" eval="False"/>
        <field name="binding_type">report</field>
    </record>

<template id="report_wo">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="web.external_layout">
             <link rel="stylesheet" href="/sos_inventory/static/src/css/style.css" />
                <div class="page">

                    <h2 style="text-align:center">Work Order</h2>
                    <br></br>
                    <!-- HTML Table -->
                    <table class="table table-bordered">
                        <tbody>
                            <tr>
                                <td colspan="2" rowspan="4"><span class="column">Service Provider Name</span> <br></br><br></br><t t-esc="o.supplier_name.service_provider_name"/> <br></br>
                                 <t t-foreach="o.supplier_address.split(',')" t-as="part">
                                        <t t-esc="part"/><br/>
                                    </t></td>
                                <td class="column">W.O. No</td><td><t t-esc="o.wo_no"/></td>
                            </tr>
                            <tr>
                                <td class="column">W.O. Date</td><td><t t-esc="o.wo_date"/></td>
                            </tr>
                            <tr>
                                <td class="column">Your Quotation No and Date </td><td><t t-esc="o.quotation_no"/><br></br><t t-esc="o.quotation_date"/></td>
                            </tr>
                            <tr>
                                <td class="column">Material Delivery Required Date:</td><td><t t-esc="o.material_delivery_required_date"/></td>
                            </tr>
                            <tr>
                            <td class="column">Service Provider GST No</td>
                            <td><t t-esc="o.supplier_gst_no"/></td>
                            <td class="column">Sosaley GST No</td>
                            <td><t t-esc="o.sosaley_gst_no"/></td>
                            </tr>
                            <tr>
                            <td class="column">Invoicing Address</td>
                            <td class="column">Delivery Address</td>
                            <td class="column">SARF No</td>
                            <td><t t-esc="o.sarf_no"/></td>
                            </tr>
                            <tr>
                            <td><t t-foreach="o.invoicing_address.split(',')" t-as="part">
                                        <t t-esc="part"/><br/>
                                    </t></td>
                            <td><t t-foreach="o.delivery_address.split(',')" t-as="part">
                                        <t t-esc="part"/><br/>
                                    </t></td>
                            <td class="column">Contact Person Name and Mobile Number at our office</td>
                            <td><t t-esc="o.Contact_details"/></td>
                            </tr>
                        </tbody>
                    </table>
                   We are pleased to place the order for the mentioned below materials. Please quote our PO Number in all your invoices and delivery challan.
                  <br></br>
<!-- Set the total item count -->
<t t-set="total_items" t-value="len(o.line_ids)"/>

<!-- Display the first 5 items (or fewer) in the first table -->
<table class="table table-bordered">
    <tbody>
      <tr class="column">
                <td>QP #</td>
                <td>HSN Code #</td>
                <td>Material Name and Specification</td>
                <td>Unit Price</td>
                <td>Quantity Required</td>
                <td>Total Price (Rs.)</td>
            </tr>
        <!-- Render the first 5 items -->
        <t t-foreach="o.line_ids[:4]" t-as="line_items">
            <tr>
                  <td><t t-esc="line_items.qp"/></td>
                    <td><t t-esc="line_items.hsn_code"/></td>
                    <td><t t-esc="line_items.component_id.name"/></td>
                    <td><t t-esc="'{:.2f}'.format(line_items.unit_price)"/></td>
                    <td><t t-esc="line_items.quantity"/></td>
                    <td><t t-esc="'{:.2f}'.format(line_items.total_price)"/></td>
            </tr>
        </t>
    </tbody>
</table>

<!-- Page break after first table if there are more than 5 items -->
<t t-if="total_items > 4">
    <div style="page-break-after: always;"></div>
</t>

<!-- Start a new table for the remaining items -->
<t t-if="total_items > 4">
    <table class="table table-bordered">
            
        <tbody>
        <t t-if="total_items >= 5">
        <tr class="column">
                <td>QP #</td>
                <td>HSN Code #</td>
                <td>Material Name and Specification</td>
                <td>Unit Price</td>
                <td>Quantity Required</td>
                <td>Total Price (Rs.)</td>
            </tr>
            </t>
            <!-- Render the remaining items -->
            <t t-foreach="o.line_ids[4:]" t-as="line_items">
                <tr>
                    <td><t t-esc="line_items.qp"/></td>
                    <td><t t-esc="line_items.hsn_code"/></td>
                    <td><t t-esc="line_items.component_id.part_no"/></td>
                    <td><t t-esc="'{:.2f}'.format(line_items.unit_price)"/></td>
                    <td><t t-esc="line_items.quantity"/></td>
                    <td><t t-esc="'{:.2f}'.format(line_items.total_price)"/></td>
                </tr>
            </t>
        </tbody>
    </table>
</t>
 <table class="table table-bordered">
<tbody>

                 <tr>
                 <td rowspan="2" colspan="4">
                 <ul>
                            <t t-set="first" t-value="True"/>
<t t-foreach="o.terms_conditions.splitlines()" t-as="line" t-index="i">
    <t t-if="first">
        <t t-esc="line"/>
        <t t-set="first" t-value="False"/>
    </t>
    <t t-else="">
        <li style="list-style: none;"><t t-esc="line"/></li>
    </t>
</t>

                        </ul>
                 </td><td class="column">Gross Value (Rs.)</td><td><t t-esc="o.gross_value"/></td>
                 </tr>
             
                 <tr>
                 <td class="column">Net Value (Rs.)</td><td><t t-esc="'{:.2f}'.format(o.rounded_total_value)"/></td>
                 </tr>
                 
                 </tbody>
                 </table>
                 For Sosaley Technologies Private Limited
<br></br> <br></br>
                 <img style="height:75px;width:75px" t-if="o.top_management_approval_image" t-att-src="'data:image/png;base64,%s' % (o.top_management_approval_image.decode())" alt="Approval Sign"/>

                </div>
            </t>
        </t>
    </t>
</template>

</odoo>