← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 778473] Re: Unlink Stock picking doen't work correctly for picking in the state "auto"

 

Thank you, great job

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/778473

Title:
  Unlink Stock picking doen't work correctly for picking in the state
  "auto"

Status in OpenERP Modules (addons):
  Fix Released

Bug description:
  Hi
  I thound a problem in the module stock.
  Let's explain :
  The object stock.picking can have 5 states (draft, auto, confirmed, assigned, done, cancel)
  In a normal case the state 'auto' is used only temporary and so a picking never stay in this state. So nobody have seen this bug. But my custom module use it ;)

  The problem occure when you try to delete a picking in the state 'auto'.
  Indeed if you look in the code line 1122, you see that only the picking in the state (draft, confirmed, assigned, done, cancel) are supported correctly by the function unlink. For the unknow state the function will delete the picking but not the stock_move ===> This is mean your stock is incorrect
   As the state 'auto' is a native state I think the function have to support it.

  ####CODE START
      def unlink(self, cr, uid, ids, context=None):
          move_obj = self.pool.get('stock.move')
          if context is None:
              context = {}
          for pick in self.browse(cr, uid, ids, context=context):
              if pick.state in ['done','cancel']:
                  raise osv.except_osv(_('Error'), _('You cannot remove the picking which is in %s state !')%(pick.state,))
              elif pick.state in ['confirmed','assigned', 'draft']:          <<<<<<HERE
                  ids2 = [move.id for move in pick.move_lines]
                  ctx = context.copy()
                  ctx.update({'call_unlink':True})
                  if pick.state != 'draft':
                      #Cancelling the move in order to affect Virtual stock of product
                      move_obj.action_cancel(cr, uid, ids2, ctx)
                  #Removing the move
                  move_obj.unlink(cr, uid, ids2, ctx)

          return super(stock_picking, self).unlink(cr, uid, ids, context=context)
  ####CODE END

  There is two solution :
  replacing 
              elif pick.state in ['confirmed','assigned', 'draft']:
  by
              elif pick.state in ['confirmed','assigned', 'draft', 'auto']:

  OR

  replacing 
              elif pick.state in ['confirmed','assigned', 'draft']:
  by
              else:

  The big advantage of the seconde solution is that if you add a state
  on the object stock.picking the stock_move will be automatically
  deleted, without any extra coding. If you had a very special state
  which need more code in the unlink function you have just to inherit
  it.

  What do you think ?
  I think it will be good to have it fixed on 6.1.
  Thanks

  For information :
  I am building a module to had a lot of the posibility one the workflow one of this is to reserve a picking from the sale order.
  For exemple, a customer buy on your website a product and paid it with bank transferts. You don't when to validate the sale order because the customer maybe never send the money, but you want to have a "reserved picking" to reduce your stock level. So I make it possible. 
  v5 branch : https://code.launchpad.net/~akretion-team/+junk/sale_extended_workflow
  soon v6 branch


References