Before this commit we could print the product labels of a picking from a picking, but we couldn't print only the lots/sns. This commit adds in this ability. Because we want to be flexible with this label printing (i.e. have the option to choose between printing zpl or pdf + 1 per unit or per lot/sn), we include it in the general "Print Labels" button with additional wizards. Note that we assume: 1. If there are no lot_ids in the picking => default to only product labels wizard (i.e. this also means if a picking that only creates New Lots/SN, lots/sns will not be printable until picking is validated.) 2. Lots/SN PDF labels will only be in the 4x12 label format 3. Batch pickings can also print lot/sn labels Part of task: 2494740 Related ENT PR: odoo/enterprise#23323 closes odoo/odoo#82389 Related: odoo/upgrade#3202 Signed-off-by: Arnold Moyaux <arm@odoo.com>
43 lines
1.7 KiB
Python
43 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):
|
|
_name = 'lot.label.layout'
|
|
_description = 'Choose the sheet layout to print lot labels'
|
|
|
|
picking_ids = fields.Many2many('stock.picking')
|
|
label_quantity = fields.Selection([
|
|
('lots', 'One per lot/SN'),
|
|
('units', 'One per unit')], string="Quantity to print", required=True, default='lots')
|
|
print_format = fields.Selection([
|
|
('4x12', '4 x 12'),
|
|
('zpl', 'ZPL Labels')], string="Format", default='4x12', required=True)
|
|
|
|
def process(self):
|
|
self.ensure_one()
|
|
xml_id = 'stock.action_report_lot_label'
|
|
if self.print_format == 'zpl':
|
|
xml_id = 'stock.label_lot_template'
|
|
if self.label_quantity == 'lots':
|
|
docids = self.picking_ids.move_line_ids.lot_id.ids
|
|
else:
|
|
uom_categ_unit = self.env.ref('uom.product_uom_categ_unit')
|
|
quantity_by_lot = defaultdict(int)
|
|
for move_line in self.picking_ids.move_line_ids:
|
|
if not move_line.lot_id:
|
|
continue
|
|
if move_line.product_uom_id.category_id == uom_categ_unit:
|
|
quantity_by_lot[move_line.lot_id.id] += int(move_line.qty_done)
|
|
else:
|
|
quantity_by_lot[move_line.lot_id.id] += 1
|
|
docids = []
|
|
for lot_id, qty in quantity_by_lot.items():
|
|
docids.append([lot_id] * qty)
|
|
report_action = self.env.ref(xml_id).report_action(docids)
|
|
report_action.update({'close_on_report_download': True})
|
|
return report_action
|