You can inherit stock.picking
and override the _pre_action_done_hook
method to create the backorders instead of returning the confirmation wizard.
class StockPicking(models.Model):
_inherit = 'stock.picking'
def _pre_action_done_hook(self):
vals = super(StockPicking, self)._pre_action_done_hook()
if isinstance(vals, dict):
if (
vals.get('type') == 'ir.actions.act_window' and
vals.get('res_model') == 'stock.backorder.confirmation'
):
pickings_to_validate = self.env.context.get(
'button_validate_picking_ids')
if pickings_to_validate:
pickings_to_validate = self.env['stock.picking'].browse(
pickings_to_validate).with_context(skip_backorder=True)
return pickings_to_validate.button_validate()
return vals
The code block inside above if
statement, is taken from process
method of stock.backorder.confirmation
which is the method linked to the Create Backorder
button on the wizard. You can read the method in stock/wizard/stock_backorder_confirmation.py
.