1

I am odoo newbie. My goal is to create a method in python that will create backorder from unfinished delivery order and will allow me to skip the user input in wizard.

Basically it should have the same functionality as when user clicks on Validate button and then chooses Create Backorder in wizard, but without the user input in wizard.

enter image description here

xixo222
  • 157
  • 2
  • 9

2 Answers2

0

It's easy to use the method inside of stock.picking

Try this:

backorders = your_picking_id._create_backorder()

It'll generate and return backorder for remaining quantity from your current delivery order.

Saumil gauswami
  • 665
  • 5
  • 16
0

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.

Mehrdad
  • 708
  • 1
  • 17
  • 38