[FIX] mrp: print barcodes

- Create a product A with a barcode, UOM as 'Unit(s)' with a BOM
- Create a MO for A with more than one unit, validate
- Print the 'Finished Product Label (PDF)'

A single label is printed for all units, although it is not logical: a
label should be printed for each unit, as already done for the Zebra
labels.

In case the product UOM is 'Unit(s)', we print a label per unit. To do
so, we use a template similar to `label_transfer_template_view_pdf`.

opw-2091663

closes odoo/odoo#39311

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-10-24 09:34:11 +00:00
parent 7fc3e56bb2
commit 46ef76555f
+67 -42
View File
@@ -107,51 +107,76 @@
<template id="label_production_view_pdf">
<t t-call="web.basic_layout">
<t t-foreach="docs" t-as="o">
<div class="page">
<table class="table table-condensed" style="border-bottom: 0px solid white !important;width: 3in;" t-if="o.move_finished_ids">
<t t-set="lines" t-value="o.move_finished_ids"/>
<t t-foreach="lines" t-as="line">
<t t-set="move_lines" t-value="line.move_line_ids.filtered(lambda x: x.state != 'done' and x.product_qty)"/>
<t t-if="o.state == 'done'">
<t t-set="move_lines" t-value="line.move_line_ids.filtered(lambda x: x.state == 'done' and x.qty_done)"/>
<div class="page">
<t t-foreach="docs" t-as="production">
<t t-foreach="production.move_finished_ids" t-as="move">
<t t-if="production.state == 'done'">
<t t-set="move_lines" t-value="move.move_line_ids.filtered(lambda x: x.state == 'done' and x.qty_done)"/>
</t>
<t t-else="">
<t t-set="move_lines" t-value="move.move_line_ids.filtered(lambda x: x.state != 'done' and x.product_qty)"/>
</t>
<t t-foreach="move_lines" t-as="move_line">
<t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
<t t-set="qty" t-value="int(move_line.qty_done)"/>
</t>
<t t-foreach="move_lines" t-as="ml">
<tr>
<th style="text-align: left;">
<span t-field="line.product_id"/>
</th>
</tr>
<tr>
<td>
<span>Quantity:</span>
<span t-esc="ml.product_uom_qty" t-if="ml.state !='done'"/>
<span t-esc="ml.qty_done" t-if="ml.state =='done'"/>
<span t-field="ml.product_uom_id" groups="uom.group_uom"/>
</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;" class="col-5">
<t t-if="ml.lot_id">
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', ml.lot_id.name, 600, 100)" style="width:100%;height:35px" alt="Barcode"/>
<span t-field="ml.lot_id.name"/>
</t>
</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;" class="col-5">
<t t-if="line.product_id.barcode and not ml.lot_id">
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', line.product_id.barcode, 600, 100)" style="width:100%;height:20%;" alt="Barcode"/>
<span t-field="line.product_id.barcode"/>
</t>
</td>
</tr>
<t t-else="">
<t t-set="qty" t-value="1"/>
</t>
<t t-foreach="range(qty)" t-as="item">
<t t-translation="off">
<div style="display: inline-table; height: 10rem; width: 32%;">
<table class="table table-bordered" style="border: 2px solid black;" t-if="production.move_finished_ids">
<tr>
<th class="table-active text-left" style="height:4rem;">
<span t-esc="move.product_id.display_name"/>
<br/>
<span>Quantity:</span>
<t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
<span>1.0</span>
<span t-field="move_line.product_uom_id" groups="uom.group_uom"/>
</t>
<t t-else="">
<span t-esc="move_line.product_uom_qty" t-if="move_line.state !='done'"/>
<span t-esc="move_line.qty_done" t-if="move_line.state =='done'"/>
<span t-field="move_line.product_uom_id" groups="uom.group_uom"/>
</t>
</th>
</tr>
<t t-if="move_line.product_id.tracking != 'none'">
<tr>
<td class="text-center align-middle">
<t t-if="move_line.lot_name or move_line.lot_id">
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', move_line.lot_name, 600, 150)" style="width:100%;height:4rem" alt="Barcode"/>
<span t-esc="move_line.lot_name or move_line.lot_id.name"/>
</t>
<t t-else="">
<span class="text-muted">No barcode available</span>
</t>
</td>
</tr>
</t>
<t t-if="move_line.product_id.tracking == 'none'">
<tr>
<td class="text-center align-middle" style="height: 6rem;">
<t t-if="move_line.product_id.barcode">
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', move_line.product_id.barcode, 600, 150)" style="width:100%;height:4rem" alt="Barcode"/>
<span t-esc="move_line.product_id.barcode"/>
</t>
<t t-else="">
<span class="text-muted">No barcode available</span>
</t>
</td>
</tr>
</t>
</table>
</div>
</t>
</t>
</t>
</table>
<div class="oe_structure"/>
</div>
</t>
</t>
</t>
</div>
</t>
</template>