Odoo Help


How to set to draft the stock picking out when state is cancel?

on 11/29/13, 8:26 AM 4,676 views


I want to set to draft the stock picking out when state is cancel. How can I do that?

I know that is possible create a button and set the state to draft, but in this particulary case change the state isn't enough because it has movement of products in stock move and in stock inventory.

I have created a button "Set to Confirmed":

image description

This button call this function:

def set_to_confirmed(self, cr, uid, ids, context=None):
    """ Changes picking state to delivered.
    @return: True
    for stock_picking_out_ids in ids:

        stock_picking_out_obj = self.browse(cr, uid, stock_picking_out_ids, context)
        move_lines = stock_picking_out_obj.move_lines

        for move_lines_obj in move_lines:

            self.pool.get('stock.move').write(cr, uid, move_lines_obj.id, {'state': 'confirmed'} )

    self.write(cr, uid, ids, {'state': 'confirmed'})
    return True

This works and change the state to confirmed but after this I can't continue the workflow, in others words, the button that appears in this state "Check Availability" and "Force Availability" doesn't work and give me a error:

Not enough stock, unable to reserve the products

Any ideia the steps that I have to do to this functionality works?

will you share your module for community

Atul Kumar jain
on 8/8/14, 4:43 AM
Julio Serna
On 11/29/13, 4:21 PM

here are many stuff your code aren't respecting the workflow of stock.picking you are jumping the transition from draft to confirm, you can't go back a state of picking by python code with function write() and hope that the workflow of picking work fine. the workflow of the picking has two node of flow stop, when the state of picking are cancel or done when the picking are in state cancel you must regenerate the workflow

in this way:

def set_to_draft(self, cr, uid, ids, *args):
    if not len(ids):
        return False
    move_obj = self.pool.get('stock.move')
    self.write(cr, uid, ids, {'state': 'draft'})
    wf_service = netsvc.LocalService("workflow")
    for p_id in ids:
        moves = move_obj.search(cr, uid, [('picking_id', '=', p_id)])
        move_obj.write(cr, uid, moves, {'state': 'draft'})
        # Deleting the existing instance of workflow for PO
        wf_service.trg_delete(uid, 'stock.picking', p_id, cr)
        wf_service.trg_create(uid, 'stock.picking', p_id, cr)
    for (id, name) in self.name_get(cr, uid, ids):
        message = _("Picking '%s' has been set in draft state.") % name
        self.log(cr, uid, id, message)
    return True

don't forget import netsvc

best regards

Thank you so much

on 12/2/13, 2:55 PM
On 4/13/16, 12:29 PM

Hi Bati,

thank you for sharing stock_picking_back_to_draft link. I wish to try this, however the link takes to an error page. Can you post the correct link ?


On 4/13/16, 10:24 AM

I think the correct answer to the question described in the title is: using a module like


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 11/29/13, 8:26 AM
Seen: 4676 times
Last updated: 4/13/16, 12:29 PM