<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template id="report_inventory">
            <t t-call="web.html_container">
                <t t-foreach="docs" t-as="o">
                    <t t-call="web.external_layout">
                        <div class="page">
                            <br/>
                            <h2>Stock Inventory</h2>

                            <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th><strong>Inventory</strong></th>
                                    <th><strong>Date</strong></th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <span t-field="o.name"/>
                                    </td>
                                    <td>
                                        <span t-field="o.date"/>
                                    </td>
                                </tr>
                            </tbody>
                            </table>

                            <t t-set="locations" t-value="o.line_ids.mapped('location_id')"/>
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th groups="stock.group_stock_multi_locations"><strong>Location</strong></th>
                                        <th><strong>Product</strong></th>
                                        <th groups="stock.group_production_lot"><strong>Production Lot</strong></th>
                                        <th groups="stock.group_tracking_lot"><strong>Package</strong></th>
                                        <th class="text-right"><strong>Quantity</strong></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <t t-foreach="locations" t-as="location">
                                        <tr groups="stock.group_stock_multi_locations">
                                            <td colspan="2"><strong t-esc="location.display_name"/></td>
                                            <td groups="stock.group_production_lot"></td>
                                            <td groups="stock.group_tracking_lot"></td>
                                            <td></td>
                                        </tr>
                                        <tr t-foreach="o.line_ids.filtered(lambda line: line.location_id.id == location.id)" t-as="line">
                                            <td groups="stock.group_stock_multi_locations"></td>
                                            <td><span t-field="line.product_id"/></td>
                                            <td groups="stock.group_production_lot"><span t-field="line.prod_lot_id"/></td>
                                            <td groups="stock.group_tracking_lot"><span t-field="line.package_id"/></td>
                                            <td class="text-right"><span t-field="line.product_qty"/> <span t-field="line.product_uom_id" groups="uom.group_uom"/></td>
                                        </tr>
                                    </t>
                                </tbody>
                            </table>

                            <t t-if="o.filter == 'product' and o.product_id">
                              <div class="row justify-content-end">
                                <div class="col-4">
                                     <table class="table table-sm">
                                        <tr class="border-black">
                                            <td><strong>Total Quantity</strong></td>
                                            <td class="text-right">
                                                <span t-field="o.total_qty"/> <span t-field="o.product_id.uom_id"/>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                              </div>
                            </t>
                        </div>
                    </t>
                 </t>
             </t>
        </template>
    </data>
</odoo>
