Files
odoo_source/addons/stock/wizard/product_label_layout.py
T
Tiffany Chang (tic) 0d882a4e49 [FIX] product,stock: print lot when provided instead of product
When Print Labels was revamped in odoo/odoo#69690 it was decided that
only product barcodes would be printed. Unfortunately we want SN/Lot
barcodes to be printed instead when they are filled in, so we make this
the case when applicable (i.e. when printing Transfer Quantites + qtys
done).

closes odoo/odoo#80079

Task: 2678336
X-original-commit: 105587e9e411442fd8e6d30efaa35b90b0e09959
Signed-off-by: Arnold Moyaux <arm@odoo.com>
2021-11-19 12:50:58 +00:00

40 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import defaultdict
from odoo import fields, models
class ProductLabelLayout(models.TransientModel):
_inherit = 'product.label.layout'
move_line_ids = fields.Many2many('stock.move.line')
picking_quantity = fields.Selection([
('picking', 'Transfer Quantities'),
('custom', 'Custom')], string="Quantity to print", required=True, default='custom')
print_format = fields.Selection(selection_add=[
('zpl', 'ZPL Labels'),
('zplxprice', 'ZPL Labels with price')
], ondelete={'zpl': 'set default', 'zplxprice': 'set default'})
def _prepare_report_data(self):
xml_id, data = super()._prepare_report_data()
if 'zpl' in self.print_format:
xml_id = 'stock.label_product_product'
if self.picking_quantity == 'picking' and self.move_line_ids:
qties = defaultdict(int)
custom_barcodes = defaultdict(list)
uom_unit = self.env.ref('uom.product_uom_categ_unit', raise_if_not_found=False)
for line in self.move_line_ids:
if line.product_uom_id.category_id == uom_unit:
if (line.lot_id or line.lot_name) and int(line.qty_done):
custom_barcodes[line.product_id.id].append((line.lot_id.name or line.lot_name, int(line.qty_done)))
continue
qties[line.product_id.id] += line.qty_done
# Pass only products with some quantity done to the report
data['quantity_by_product'] = {p: int(q) for p, q in qties.items() if q}
data['custom_barcodes'] = custom_barcodes
return xml_id, data