[IMP] stock: auto-print product/lot labels
Add in feature to allow auto-printing of product and lot labels at picking validation. Note that the `product.label.layout` (wizard) has a default picking quantity value for how many labels should be printed out for each product that makes sense for the auto-print case, whereas the `lot.label.layout` (wizard) allows the the user to choose whether or not to print out 1 label per lot/SN or the qty done of each lot/SN, and both are valid options for auto-printing. Therefore the selection choices for `product_label_format` matches it's corresponding wizard's choices exactly, whereas the `lot_label_format` combines the `print_format` + `label_quantity` of its corresponding wizard. Hopefully no additional print formats are created for the lot labels... Part of task: 3046178 - general auto-print goal Part-of: odoo/odoo#126791
This commit is contained in:
@@ -89,6 +89,27 @@ class PickingType(models.Model):
|
||||
auto_print_delivery_slip = fields.Boolean(
|
||||
"Auto Print Delivery Slip",
|
||||
help="If this checkbox is ticked, Odoo will automatically print the delivery slip of a picking when it is validated.")
|
||||
|
||||
auto_print_product_labels = fields.Boolean(
|
||||
"Auto Print Product Labels",
|
||||
help="If this checkbox is ticked, Odoo will automatically print the product labels of a picking when it is validated.")
|
||||
product_label_format = fields.Selection([
|
||||
('dymo', 'Dymo'),
|
||||
('2x7xprice', '2 x 7 with price'),
|
||||
('4x7xprice', '4 x 7 with price'),
|
||||
('4x12', '4 x 12'),
|
||||
('4x12xprice', '4 x 12 with price'),
|
||||
('zpl', 'ZPL Labels'),
|
||||
('zplxprice', 'ZPL Labels with price')], string="Product Label Format to auto-print", default='2x7xprice')
|
||||
auto_print_lot_labels = fields.Boolean(
|
||||
"Auto Print Lot/SN Labels",
|
||||
help="If this checkbox is ticked, Odoo will automatically print the lot/SN labels of a picking when it is validated.")
|
||||
lot_label_format = fields.Selection([
|
||||
('4x12_lots', '4 x 12 - One per lot/SN'),
|
||||
('4x12_units', '4 x 12 - One per unit'),
|
||||
('zpl_lots', 'ZPL Labels - One per lot/SN'),
|
||||
('zpl_units', 'ZPL Labels - One per unit')],
|
||||
string="Lot Label Format to auto-print", default='4x12_lots')
|
||||
auto_print_reception_report_labels = fields.Boolean(
|
||||
"Auto Print Reception Report Labels",
|
||||
help="If this checkbox is ticked, Odoo will automatically print the reception report labels of a picking when it is validated.")
|
||||
@@ -1749,4 +1770,32 @@ class Picking(models.Model):
|
||||
action = self.env.ref('stock.label_picking').report_action(moves_to_print, data=data, config=False)
|
||||
clean_action(action, self.env)
|
||||
report_actions.append(action)
|
||||
pickings_print_product_label = self.filtered(lambda p: p.picking_type_id.auto_print_product_labels)
|
||||
pickings_by_print_formats = pickings_print_product_label.grouped(lambda p: p.picking_type_id.product_label_format)
|
||||
for print_format in pickings_print_product_label.picking_type_id.mapped("product_label_format"):
|
||||
pickings = pickings_by_print_formats.get(print_format)
|
||||
wizard = self.env['product.label.layout'].create({
|
||||
'product_ids': pickings.move_ids.product_id.ids,
|
||||
'move_ids': pickings.move_ids.ids,
|
||||
'picking_quantity': 'picking',
|
||||
'print_format': pickings.picking_type_id.product_label_format,
|
||||
})
|
||||
action = wizard.process()
|
||||
if action:
|
||||
clean_action(action, self.env)
|
||||
report_actions.append(action)
|
||||
if self.user_has_groups('stock.group_production_lot'):
|
||||
pickings_print_lot_label = self.filtered(lambda p: p.picking_type_id.auto_print_lot_labels and p.move_line_ids.lot_id)
|
||||
pickings_by_print_formats = pickings_print_lot_label.grouped(lambda p: p.picking_type_id.lot_label_format)
|
||||
for print_format in pickings_print_lot_label.picking_type_id.mapped("lot_label_format"):
|
||||
pickings = pickings_by_print_formats.get(print_format)
|
||||
wizard = self.env['lot.label.layout'].create({
|
||||
'picking_ids': pickings.ids,
|
||||
'label_quantity': 'lots' if '_lots' in print_format else 'units',
|
||||
'print_format': '4x12' if '4x12' in print_format else 'zpl',
|
||||
})
|
||||
action = wizard.process()
|
||||
if action:
|
||||
clean_action(action, self.env)
|
||||
report_actions.append(action)
|
||||
return report_actions
|
||||
|
||||
@@ -128,6 +128,18 @@
|
||||
<group name="auto_print">
|
||||
<group string="Print on Validation">
|
||||
<field name="auto_print_delivery_slip" string="Delivery Slip"/>
|
||||
<label for="auto_print_product_labels" string="Product Labels"/>
|
||||
<div class="o_row">
|
||||
<field name="auto_print_product_labels" string="Product Labels"/>
|
||||
<label for="product_label_format" string="Print label as:" invisible="not auto_print_product_labels" class="fw-bold"/>
|
||||
<field name="product_label_format" invisible="not auto_print_product_labels"/>
|
||||
</div>
|
||||
<label for="auto_print_lot_labels" string="Lot/SN Labels" groups="stock.group_production_lot"/>
|
||||
<div class="o_row" groups="stock.group_production_lot">
|
||||
<field name="auto_print_lot_labels" string="Lot/SN Labels"/>
|
||||
<label for="lot_label_format" string="Print label as:" invisible="not auto_print_lot_labels" class="fw-bold"/>
|
||||
<field name="lot_label_format" invisible="not auto_print_lot_labels"/>
|
||||
</div>
|
||||
<field name="auto_print_reception_report_labels" string="Reception Report Labels" invisible="code == 'outgoing'" groups="stock.group_reception_report"/>
|
||||
</group>
|
||||
<group string="">
|
||||
|
||||
Reference in New Issue
Block a user