[IMP] stock: auto-print reception report labels
Add in feature to allow auto-printing of reception report labels at picking validation when there are lines assigned in the reception report (i.e. any MTO linkages/move_dest_ids). Note that a little fix hack was necessary for this feature (i.e. override of ir.actions.report to ensure that the doc_ids/docs are correctly set) since this report was originally designed to be called ONLY from the JS + using the report link to pass the correct parameters, which cannot be done in the same way via the standard ir.actions.report.report_action method Part of task: 3046178 - general auto-print goal Part-of: odoo/odoo#126791
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import barcode
|
||||
from . import ir_actions_report
|
||||
from . import product_strategy
|
||||
from . import res_company
|
||||
from . import res_partner
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from odoo import models
|
||||
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = 'ir.actions.report'
|
||||
|
||||
def _get_rendering_context(self, report, docids, data):
|
||||
data = super()._get_rendering_context(report, docids, data)
|
||||
if report.report_name == 'stock.report_reception_report_label' and not docids:
|
||||
docids = data['docids']
|
||||
docs = self.env[report.model].browse(docids)
|
||||
data.update({
|
||||
'doc_ids': docids,
|
||||
'docs': docs,
|
||||
})
|
||||
return data
|
||||
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
import math
|
||||
import time
|
||||
from ast import literal_eval
|
||||
from datetime import date, timedelta
|
||||
@@ -88,6 +89,9 @@ 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_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.")
|
||||
|
||||
auto_print_package_label = fields.Boolean(
|
||||
"Auto Print Package Label",
|
||||
@@ -1730,4 +1734,19 @@ class Picking(models.Model):
|
||||
action = self.env.ref("stock.action_report_delivery").report_action(pickings_to_print.ids, config=False)
|
||||
clean_action(action, self.env)
|
||||
report_actions.append(action)
|
||||
|
||||
if self.user_has_groups('stock.group_reception_report'):
|
||||
reception_labels_to_print = self.filtered(lambda p: p.picking_type_id.auto_print_reception_report_labels and p.picking_type_id.code != 'outgoing')
|
||||
if reception_labels_to_print:
|
||||
moves_to_print = reception_labels_to_print.move_ids.move_dest_ids
|
||||
if moves_to_print:
|
||||
# needs to be string to support python + js calls to report
|
||||
quantities = ','.join(str(qty) for qty in moves_to_print.mapped(lambda m: math.ceil(m.product_uom_qty)))
|
||||
data = {
|
||||
'docids': moves_to_print.ids,
|
||||
'quantity': quantities,
|
||||
}
|
||||
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)
|
||||
return report_actions
|
||||
|
||||
@@ -128,6 +128,7 @@
|
||||
<group name="auto_print">
|
||||
<group string="Print on Validation">
|
||||
<field name="auto_print_delivery_slip" string="Delivery Slip"/>
|
||||
<field name="auto_print_reception_report_labels" string="Reception Report Labels" invisible="code == 'outgoing'" groups="stock.group_reception_report"/>
|
||||
</group>
|
||||
<group string="">
|
||||
<div colspan="2">
|
||||
|
||||
Reference in New Issue
Block a user