<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

    <template id="report_delivery_document">
        <t t-call="web.html_container">
            <t t-call="web.external_layout">
                <t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})" />
                <t t-if="o.move_lines and o.move_lines[0].partner_id" name="partner_header">
                    <t t-set="address">
                        <div t-field="o.move_lines[0].partner_id"
                        t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True}'/>
                   </t>
                </t>
                <t t-if="not (o.move_lines and o.move_lines[0].partner_id) and o.partner_id" name="partner_header">
                    <t t-set="address">
                        <div t-field="o.partner_id"
                        t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True}'/>
                    </t>
                </t>
                <div class="page">
                    <h2>
                        <span t-field="o.name"/>
                    </h2>
                    <table class="table table-sm">
                        <thead>
                            <tr>
                                <th t-if="o.origin"><strong>Order</strong></th>
                                <th name="td_sched_date_h">
                                    <strong>Date</strong>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td t-if="o.origin">
                                    <span t-field="o.origin"/>
                                </td>
                                <td name="td_sched_date">
                                   <t t-if="o.state == 'done'">
                                        <span t-field="o.date_done"/>
                                   </t>
                                   <t t-if="o.state != 'done'">
                                        <span t-field="o.scheduled_date"/>
                                   </t>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <table class="table table-sm mt48" t-if="o.state!='done'">
                        <thead>
                            <tr>
                                <th><strong>Product</strong></th>
                                <th><strong>Quantity</strong></th>
                            </tr>
                        </thead>
                        <tbody>
                            <t t-set="lines" t-value="o.move_lines.filtered(lambda x: x.product_uom_qty)"/>
                            <tr t-foreach="lines" t-as="move">
                                <td>
                                    <span t-field="move.product_id"/>
                                    <p t-if="o.picking_type_code == 'outgoing'">
                                        <span t-field="move.product_id.sudo().description_pickingout"/>
                                    </p>
                                    <p t-if="o.picking_type_code == 'incoming'">
                                        <span t-field="move.product_id.sudo().description_pickingin"/>
                                    </p>
                                </td>
                                <td>
                                    <span t-field="move.product_uom_qty"/>
                                    <span t-field="move.product_uom"/>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <table class="table table-sm mt48" t-if="o.move_line_ids and o.state=='done'">
                        <t t-set="has_serial_number" t-value="o.move_line_ids.mapped('lot_id')" />
                        <thead>
                            <tr>
                                <th><strong>Product</strong></th>
                                <th name="lot_serial" t-if="has_serial_number" groups="stock.group_lot_on_delivery_slip">
                                    Lot/Serial Number
                                </th>
                                <th class="text-center"><strong>Quantity</strong></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="o.move_line_ids" t-as="move_line">
                                <td>
                                    <span t-field="move_line.product_id"/>
                                    <p t-if="o.picking_type_code == 'outgoing'">
                                        <span t-field="move_line.product_id.sudo().description_pickingout"/>
                                    </p>
                                    <p t-if="o.picking_type_code == 'incoming'">
                                        <span t-field="move_line.product_id.sudo().description_pickingin"/>
                                    </p>
                                </td>
                                <td t-if="has_serial_number and move_line.lot_name" groups="stock.group_lot_on_delivery_slip">
                                    <span t-field="move_line.lot_name"/>
                                </td>
                                <td t-else="" groups="stock.group_lot_on_delivery_slip">
                                    <span t-field="move_line.lot_id.name"/>
                                </td>
                                <td class="text-center">
                                    <span t-field="move_line.qty_done"/>
                                    <span t-field="move_line.product_uom_id"/>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <p>
                        <t t-if="o.backorder_ids and o.backorder_ids.filtered(lambda x: x.state not in ('done', 'cancel'))">
                            All items couldn't be shipped, the remaining ones will be shipped as soon as they become available.
                        </t>
                    </p>
                </div>
            </t>
         </t>
    </template>

    <template id="report_deliveryslip">
        <t t-foreach="docs" t-as="o">
            <t t-call="stock.report_delivery_document" t-lang="o.partner_id.lang"/>
        </t>
    </template>

</odoo>
