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

        <template id="report_picking">
            <t t-call="web.html_container">
                <t t-foreach="docs" t-as="o">
                    <t t-call="web.external_layout">
                        <div class="page">
                            <div class="row justify-content-end mb16">
                                <div class="col-4" name="right_box">
                                    <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', o.name, 600, 100)" style="width:300px;height:50px;" alt="Barcode"/>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-6">
                                    <div t-if="o.move_ids_without_package and o.move_ids_without_package[0].partner_id and o.move_ids_without_package[0].partner_id.id != o.partner_id.id">
                                        <span><strong>Delivery Address:</strong></span>
                                        <div t-field="o.move_ids_without_package[0].partner_id"
                                            t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True, "phone_icons": True}'/>
                                    </div>
                                    <div t-if="o.picking_type_id.code != 'internal' and (not o.move_ids_without_package or not o.move_ids_without_package[0].partner_id) and o.picking_type_id.warehouse_id.partner_id">
                                        <span><strong>Warehouse Address:</strong></span>
                                        <div t-field="o.picking_type_id.warehouse_id.partner_id"
                                            t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True, "phone_icons": True}'/>
                                    </div>
                                </div>
                                <div class="col-5 offset-1">
                                    <div t-if="o.picking_type_id.code=='incoming' and o.partner_id">
                                        <span><strong>Vendor Address:</strong></span>
                                    </div>
                                    <div t-if="o.picking_type_id.code=='internal' and o.partner_id">
                                        <span><strong>Warehouse Address:</strong></span>
                                    </div>
                                    <div t-if="o.picking_type_id.code=='outgoing' and o.partner_id">
                                        <span><strong>Customer Address:</strong></span>
                                    </div>
                                    <div t-if="o.partner_id" name="partner_header">
                                        <div t-field="o.partner_id"
                                           t-options='{"widget": "contact", "fields": ["name", "phone"], "no_marker": True, "phone_icons": True}'/>
                                        <p t-if="o.sudo().partner_id.vat"><t t-esc="o.company_id.country_id.vat_label or 'Tax ID'"/>: <span t-field="o.sudo().partner_id.vat"/></p>
                                    </div>
                                </div>
                            </div>
                            <br/>
                            <h1 t-field="o.name" class="mt0 float-left"/>
                            <div class="clearfix"/>
                            <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th t-if="o.origin"><strong>Order</strong></th>
                                    <th><strong>State</strong></th>
                                    <th name="td_sched_date_h" width="20%"><strong>Scheduled Date</strong></th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td t-if="o.origin">
                                        <span t-field="o.origin"/>
                                    </td>
                                    <td>
                                        <span t-field="o.state"/>
                                    </td>
                                    <td name="td_sched_date" width="20%">
                                        <span t-field="o.scheduled_date"/>
                                    </td>
                                </tr>
                            </tbody>
                            </table>
                            <br/>
                            <br/>
                            <table class="table table-sm" t-if="o.move_line_ids">
                                <t t-set="has_barcode" t-value="any([move_ids_without_package.product_id and move_ids_without_package.product_id.sudo().barcode or move_ids_without_package.package_id for move_ids_without_package in o.move_line_ids])"/>
                                <t t-set="has_serial_number" t-value="o.move_line_ids.filtered(lambda ml: ml.lot_id or ml.lot_name)" groups="stock.group_production_lot"/>
                                <thead>
                                    <tr>
                                        <th><strong>Product</strong></th>
                                        <th><strong>Quantity</strong></th>
                                        <th width="20%" t-if="o.picking_type_id.code != 'incoming'" align="left"><strong>From</strong>
                                        </th>
                                        <th t-if="o.picking_type_id.code != 'outgoing'"><strong>To</strong></th>
                                        <th width="15%" class="text-center" t-if="has_serial_number">
                                           <strong>Lot/Serial Number</strong>
                                        </th>
                                        <th width="15%" class="text-center" t-if="has_barcode"><strong>
                                            Product Barcode</strong>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <t t-foreach="o.move_ids_without_package.sorted(key=lambda m: m.product_id.id)" t-as="move">
                                        <t t-foreach="move.move_line_ids.sorted(key=lambda ml: ml.location_id.id)" t-as="ml">
                                            <tr>
                                                <td>
                                                    <span t-field="ml.product_id.display_name"/><br/>
                                                    <span t-field="ml.product_id.description_picking"/>
                                                </td>
                                                <td>
                                                    <span t-if="o.state != 'done'" t-field="ml.product_uom_qty"/>
                                                    <span t-if="o.state == 'done'" t-field="ml.qty_done"/>
                                                    <span t-field="ml.product_uom_id" groups="uom.group_uom"/>

                                                </td>
                                                <td width="20%" t-if="o.picking_type_id.code != 'incoming'">
                                                    <span t-esc="ml.location_id.display_name"/>
                                                        <t t-if="ml.package_id">
                                                            <span t-field="ml.package_id"/>
                                                        </t>
                                                </td>
                                                <td t-if="o.picking_type_id.code != 'outgoing'">
                                                    <div>
                                                        <span t-field="ml.location_dest_id"/>
                                                        <t t-if="ml.result_package_id">
                                                            <span t-field="ml.result_package_id"/>
                                                        </t>
                                                    </div>
                                                </td>
                                                <td width="15%" class=" text-center h6" t-if="has_serial_number">
                                                    <img t-if="has_serial_number and (ml.lot_id or ml.lot_name)" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=1' % ('Code128', ml.lot_id.name, 600, 100)" style="width:100%;height:35px;" alt="Barcode"/>

                                                </td>
                                                <td width="15%" class="text-center" t-if="has_barcode">
                                                    <t t-if="product_barcode != move.product_id.barcode">
                                                        <span t-if="move.product_id and move.product_id.barcode">
                                                            <img t-if="len(move.product_id.barcode) == 13" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', move.product_id.barcode, 600, 100)" style="width:100%;height:35px" alt="Barcode"/>
                                                            <img t-elif="len(move.product_id.barcode) == 8" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN8', move.product_id.barcode, 600, 100)" style="width:100%;height:35px" alt="Barcode"/>
                                                            <img t-else="" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', move.product_id.barcode, 600, 100)" style="width:100%;height:35px" alt="Barcode"/>

                                                        </span>
                                                        <t t-set="product_barcode" t-value="move.product_id.barcode"/>
                                                    </t>
                                                </td>
                                            </tr>
                                        </t>
                                    </t>
                                  </tbody>
                            </table>
                            <table class="table table-sm" t-if="o.package_level_ids and o.picking_type_entire_packs">
                                <thead>
                                    <tr>
                                        <th width="25%">Package</th>
                                        <th width="25%" class="text-center">Barcode</th>
                                        <th width="25%" class="text-left">Source</th>
                                        <th width="25%" class="text-right">Destination</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr t-foreach="o.package_level_ids.sorted(key=lambda p: p.package_id.name)" t-as="package">
                                        <t t-set="package" t-value="package.with_context(picking_id=o.id)" />
                                        <td><span t-field="package.package_id.name"/></td>
                                        <td><img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', package.package_id.name, 600, 100)" style="width:300px    ;height:50px" alt="Barcode"/></td>
                                        <td><span t-field="package.location_id"/></td>
                                        <td><span t-field="package.location_dest_id"/></td>
                                    </tr>
                                </tbody>
                            </table>
                            <t t-set="no_reserved_product" t-value="o.move_lines.filtered(lambda x: x.product_uom_qty != x.reserved_availability and x.move_line_ids and x.state!='done')"/>
                            <p t-if="o.state in ['draft', 'waiting', 'confirmed'] or no_reserved_product"><i class="fa fa-exclamation-triangle" />
                                All products could not be reserved. Click on the "Check Availability" button to try to reserve products
                            </p>
                            <p t-field="o.note"/>
                        </div>
                    </t>
                </t>
            </t>
        </template>
        <template id="report_picking_type_label">
            <t t-call="web.basic_layout">
                <t t-foreach="docs" t-as="o">
                    <div class="page">
                        <div class="oe_structure"/>
                        <div class="row">
                            <div class="col-8">
                                <table class="table table-condensed" style="border-bottom: 0px solid white !important;width: 3in;">
                                    <tr>
                                      <th style="text-align: left;">
                                        <span t-field="o.name"/>
                                      </th>
                                    </tr>
                                    <tr>
                                        <td style="text-align: center; vertical-align: middle;" class="col-5">
                                            <img t-if="o.barcode" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', o.barcode, 600, 150)" style="width:100%;height:20%;"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </t>
            </t>
        </template>
    </data>
</odoo>
