[IMP] mrp: auto-print MO when MO done
Add in feature to allow auto-printing of Production Order report at MO completion. Note that existing backorder view actions had to be adjusted because lack of `views` param did not work with specialized client action to chain actions. Part of task: 3046178 - MRP behavior auto-printing Part-of: odoo/odoo#126791
This commit is contained in:
@@ -11,6 +11,7 @@ from collections import defaultdict
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, fields, models, _, Command
|
||||
from odoo.addons.web.controllers.utils import clean_action
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tools import float_compare, float_round, float_is_zero, format_datetime
|
||||
from odoo.tools.misc import OrderedSet, format_date, groupby as tools_groupby
|
||||
@@ -1967,48 +1968,78 @@ class MrpProduction(models.Model):
|
||||
'state': 'done',
|
||||
})
|
||||
|
||||
report_actions = self._get_autoprint_done_report_actions()
|
||||
if self.env.context.get('skip_redirection'):
|
||||
if report_actions:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'do_multi_print',
|
||||
'params': {
|
||||
'reports': report_actions,
|
||||
}
|
||||
}
|
||||
return True
|
||||
|
||||
another_action = False
|
||||
if not backorders:
|
||||
if self.env.context.get('from_workorder'):
|
||||
return {
|
||||
another_action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'mrp.production',
|
||||
'views': [[self.env.ref('mrp.mrp_production_form_view').id, 'form']],
|
||||
'res_id': self.id,
|
||||
'target': 'main',
|
||||
}
|
||||
if self.user_has_groups('mrp.group_mrp_reception_report'):
|
||||
elif self.user_has_groups('mrp.group_mrp_reception_report'):
|
||||
mos_to_show = self.filtered(lambda mo: mo.picking_type_id.auto_show_reception_report)
|
||||
lines = mos_to_show.move_finished_ids.filtered(lambda m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids)
|
||||
if lines:
|
||||
if any(mo.show_allocation for mo in mos_to_show):
|
||||
action = mos_to_show.action_view_reception_report()
|
||||
return action
|
||||
another_action = mos_to_show.action_view_reception_report()
|
||||
if report_actions:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'do_multi_print',
|
||||
'params': {
|
||||
'reports': report_actions,
|
||||
'anotherAction': another_action,
|
||||
}
|
||||
}
|
||||
if another_action:
|
||||
return another_action
|
||||
return True
|
||||
context = self.env.context.copy()
|
||||
context = {k: v for k, v in context.items() if not k.startswith('default_')}
|
||||
for k, v in context.items():
|
||||
if k.startswith('skip_'):
|
||||
context[k] = False
|
||||
action = {
|
||||
another_action = {
|
||||
'res_model': 'mrp.production',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': dict(context, mo_ids_to_backorder=None)
|
||||
}
|
||||
if len(backorders) == 1:
|
||||
action.update({
|
||||
another_action.update({
|
||||
'views': [[False, 'form']],
|
||||
'view_mode': 'form',
|
||||
'res_id': backorders[0].id,
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
another_action.update({
|
||||
'name': _("Backorder MO"),
|
||||
'domain': [('id', 'in', backorders.ids)],
|
||||
'views': [[False, 'list'], [False, 'form']],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
if report_actions:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'do_multi_print',
|
||||
'params': {
|
||||
'reports': report_actions,
|
||||
'anotherAction': another_action,
|
||||
}
|
||||
}
|
||||
return another_action
|
||||
|
||||
def pre_button_mark_done(self):
|
||||
self._button_mark_done_sanity_checks()
|
||||
@@ -2584,3 +2615,14 @@ class MrpProduction(models.Model):
|
||||
if missing_lot_id_products:
|
||||
error_msg = _('You need to supply Lot/Serial Number for products:') + missing_lot_id_products
|
||||
raise UserError(error_msg)
|
||||
|
||||
def _get_autoprint_done_report_actions(self):
|
||||
""" Reports to auto-print when MO is marked as done
|
||||
"""
|
||||
report_actions = []
|
||||
productions_to_print = self.filtered(lambda p: p.picking_type_id.auto_print_done_production_order)
|
||||
if productions_to_print:
|
||||
action = self.env.ref("mrp.action_report_production_order").report_action(productions_to_print.ids, config=False)
|
||||
clean_action(action, self.env)
|
||||
report_actions.append(action)
|
||||
return report_actions
|
||||
|
||||
@@ -26,6 +26,10 @@ class StockPickingType(models.Model):
|
||||
help="Allow automatic consumption of tracked components that are reserved",
|
||||
)
|
||||
|
||||
auto_print_done_production_order = fields.Boolean(
|
||||
"Auto Print Done Production Order",
|
||||
help="If this checkbox is ticked, Odoo will automatically print the production order of a MO when it is done.")
|
||||
|
||||
@api.depends('code')
|
||||
def _compute_use_create_lots(self):
|
||||
for picking_type in self:
|
||||
|
||||
@@ -138,6 +138,26 @@
|
||||
<field name="auto_show_reception_report" position="after">
|
||||
<field name="auto_show_reception_report" invisible="code != 'mrp_operation'" groups="mrp.group_mrp_reception_report"/>
|
||||
</field>
|
||||
<xpath expr="//page[@name='hardware']" position="after">
|
||||
<page name="mrp_hardware" string="Hardware" invisible="code != 'mrp_operation'">
|
||||
<group>
|
||||
<group string="Print when done">
|
||||
<field name="auto_print_done_production_order" string="Production Order"/>
|
||||
</group>
|
||||
<group string="">
|
||||
<div colspan="2">
|
||||
Odoo opens a PDF preview by default. If you want to print instantly,
|
||||
install the IoT App on a computer that is on the same local network as the
|
||||
barcode operator and configure the routing of the reports.
|
||||
<a href="https://www.odoo.com/documentation/master/applications/productivity/iot/devices/printer.html"
|
||||
target="_blank" class="fa fa-arrow-right">
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user