← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 725571] Re: Stock: Output to customer movement created twice

 

The problem is created by a wrong recursion on any stock move. When
chained locations are used, all moves are regenerated on confirmation of
movement for the remaining locations of the chain.

It affects all movements, including of course sale and
purchase.Additionally, new moves are created on wrong state.

I have written a fix as an additional module. I attach the source, with
comments on changes:


class stock_move(osv.osv):
    _inherit = "stock.move"
    
    def create_chained_picking(self, cr, uid, moves, context=None):
        """
        BASE: stock.create_chained_picking, Version 6.0.1
        Modified by NUMA
        """
        res_obj = self.pool.get('res.company')
        location_obj = self.pool.get('stock.location')
        move_obj = self.pool.get('stock.move')
        wf_service = netsvc.LocalService("workflow")
        new_moves = []
        if context is None:
            context = {}
        seq_obj = self.pool.get('ir.sequence')
        for picking, todo in self._chain_compute(cr, uid, moves, context=context).items():
            ptype = todo[0][1][5] and todo[0][1][5] or location_obj.picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0])
            if picking:
                # name of new picking according to its type
                new_pick_name = seq_obj.get(cr, uid, 'stock.picking.' + ptype)
                pickid = self._create_chained_picking(cr, uid, new_pick_name, picking, ptype, todo, context=context)
                # Need to check name of old picking because it always considers picking as "OUT" when created from Sale Order
                old_ptype = location_obj.picking_type_get(cr, uid, picking.move_lines[0].location_id, picking.move_lines[0].location_dest_id)
                if old_ptype != picking.type:
                    old_pick_name = seq_obj.get(cr, uid, 'stock.picking.' + old_ptype)
                    self.pool.get('stock.picking').write(cr, uid, picking.id, {'name': old_pick_name}, context=context)
            else:
                pickid = False
            for move, (loc, dummy, delay, dummy, company_id, ptype) in todo:
                new_id = move_obj.copy(cr, uid, move.id, {
                    'location_id': move.location_dest_id.id,
                    'location_dest_id': loc.id,

                    # NUMA : completed date
                    #'date_moved': time.strftime('%Y-%m-%d'),
                    'date_moved': time.strftime('%Y-%m-%d %H:%M:%S'),

                    'picking_id': pickid,

                    # NUMA : chained movement should be reserved
                    #'state': 'waiting',
                    'state': 'assigned',

                    'company_id': company_id or res_obj._company_default_get(cr, uid, 'stock.company', context=context)  ,
                    'move_history_ids': [],
                    'date': (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') + relativedelta(days=delay or 0)).strftime('%Y-%m-%d'),
                    'move_history_ids2': []}
                )
                move_obj.write(cr, uid, [move.id], {
                    'move_dest_id': new_id,
                    'move_history_ids': [(4, new_id)]
                })
                new_moves.append(self.browse(cr, uid, [new_id])[0])
            if pickid:
                wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_confirm', cr)

        # NUMA - No recursive call til confirmed!
        # if new_moves:
        #    new_moves += self.create_chained_picking(cr, uid, new_moves, context)

        return new_moves

    def action_confirm(self, cr, uid, ids, context=None):
        """
        BASE: stock.action_confirm, Version 6.0.1
        Modified by NUMA
        
        Confirms stock move.
        @return: List of ids.
        """
        moves = self.browse(cr, uid, ids, context=context)
        self.write(cr, uid, ids, {'state': 'confirmed'})
        res_obj = self.pool.get('res.company')
        location_obj = self.pool.get('stock.location')
        move_obj = self.pool.get('stock.move')
        wf_service = netsvc.LocalService("workflow")

        # NUMA - Do NOT create next move in chain til done!
        # self.create_chained_picking(cr, uid, moves, context)

        return []

    def action_done(self, cr, uid, ids, context=None):
        """
        BASE: stock.action_done, Version 6.0.1
        Modified by NUMA

        Makes the move done and if all moves are done, it will finish the picking.
        @return:
        """
        partial_datas=''
        picking_ids = []
        move_ids = []
        partial_obj=self.pool.get('stock.partial.picking')
        wf_service = netsvc.LocalService("workflow")
        partial_id=partial_obj.search(cr,uid,[])
        if partial_id:
            partial_datas = partial_obj.read(cr, uid, partial_id, context=context)[0]
        if context is None:
            context = {}

        todo = []
        for move in self.browse(cr, uid, ids, context=context):
            #print 'DONE MOVE', move.id, move.product_id.name, move.move_dest_id.id, move.state, move.move_dest_id and move.move_dest_id.state
            if move.state=="draft":
                todo.append(move.id)
        if todo:
            self.action_confirm(cr, uid, todo, context=context)

        for move in self.browse(cr, uid, ids, context=context):
            if move.state in ['done','cancel']:
                continue
            move_ids.append(move.id)

            if move.picking_id:
                picking_ids.append(move.picking_id.id)
            if move.move_dest_id.id and (move.state != 'done'):
                self.write(cr, uid, [move.id], {'move_history_ids': [(4, move.move_dest_id.id)]})
                #cr.execute('insert into stock_move_history_ids (parent_id,child_id) values (%s,%s)', (move.id, move.move_dest_id.id))
                if move.move_dest_id.state in ('waiting', 'confirmed'):
                    self.force_assign(cr, uid, [move.move_dest_id.id], context=context)
                    if move.move_dest_id.picking_id:
                        wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
                    if move.move_dest_id.auto_validate:
                        self.action_done(cr, uid, [move.move_dest_id.id], context=context)

            self._create_product_valuation_moves(cr, uid, move, context=context)
            prodlot_id = partial_datas and partial_datas.get('move%s_prodlot_id' % (move.id), False)
            if prodlot_id:
                self.write(cr, uid, [move.id], {'prodlot_id': prodlot_id}, context=context)
            if move.state not in ('confirmed','done'):
                self.action_confirm(cr, uid, move_ids, context=context)

        self.write(cr, uid, move_ids, {'state': 'done', 'date_planned':
time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)

        # NUMA - Create next move in chain
        moves = self.browse(cr, uid, move_ids, context=context)
        self.create_chained_picking(cr, uid, moves, context)

        for id in move_ids:
             wf_service.trg_trigger(uid, 'stock.move', id, cr)

        for pick_id in picking_ids:
            wf_service.trg_write(uid, 'stock.picking', pick_id, cr)

        return True

-- 
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/725571

Title:
  Stock: Output to customer movement created twice

Status in OpenERP Modules (addons):
  Confirmed

Bug description:
  1) Steps to reproduce the issue you have observed

    Create a sale order with a stockable product and "Invoice From The Picking" as Shipping Policy (invoice on shipped quantities)
    Confirm the order
    Go on Warehouse / Warehouse Management / Delivery Orders
    2 delivery orders have been created for the sale order. That's normal: there is one from stock to output and one from output to   customers
    Check availibility, and then process the first delivery order (Stock->Output)

  2) The result you observed

    An other movement is created from output to customers

  3) The result you expected

    No more movement would be created

  4) The platform your are using

  OpenERP - GTK Client - v6.0.1 (Windows)
  OpenERP Server Linux

  5) The OpenERP version you are using

  V6RC2


References