Odoo Help

Welcome!

This community 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.

0

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

By
Luís
on 11/29/13, 8:26 AM 3,329 views

Hi,

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
1
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

Luís
on 12/2/13, 2:55 PM
0
Cidex
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 ?

Thanks


0
eLBati
On 4/13/16, 10:24 AM

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

stock_picking_back_to_draft

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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