[MERGE] trunk
authorThibault Francois <tfr@openerp.com>
Wed, 22 Dec 2010 15:00:33 +0000 (16:00 +0100)
committerThibault Francois <tfr@openerp.com>
Wed, 22 Dec 2010 15:00:33 +0000 (16:00 +0100)
bzr revid: tfr@openerp.com-20101222150033-l395zkbh61vstwyb

1  2 
addons/stock/wizard/stock_partial_move.py
addons/stock/wizard/stock_partial_picking.py

@@@ -198,23 -166,17 +199,23 @@@ class stock_partial_move(osv.osv_memory
              p_moves[product_move.move_id.id] = product_move
              
          moves_ids_final = []
-         for move in move_obj.browse(cr, uid, move_ids):
+         for move in move_obj.browse(cr, uid, move_ids, context=context):
              if move.state in ('done', 'cancel'):
                  continue
 -            if not p_moves.get(move.id, False):
 +            if not p_moves.get(move.id):
                  continue
 +            
 +            print p_moves[move.id].product_id.id
 +            print p_moves[move.id].quantity
 +            print p_moves[move.id].product_uom.id
 +            
              partial_datas['move%s' % (move.id)] = {
 -                'product_id' : p_moves[move.id].product_id.id,
 +                'product_id' : p_moves[move.id].id,
                  'product_qty' : p_moves[move.id].quantity,
 -                'product_uom' : p_moves[move.id].product_uom.id,
 +                'product_uom' :p_moves[move.id].product_uom.id,
                  'prodlot_id' : p_moves[move.id].prodlot_id.id,
              }
 +            
              moves_ids_final.append(move.id)
              if (move.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
                  partial_datas['move%s' % (move.id)].update({
@@@ -90,46 -148,46 +90,45 @@@ class stock_partial_picking(osv.osv_mem
          result['fields'] = _moves_fields
          return result
  
 -    def default_get(self, cr, uid, fields, context=None):
 -        """ To get default values for the object.
 -        @param self: The object pointer.
 -        @param cr: A database cursor
 -        @param uid: ID of the user currently logged in
 -        @param fields: List of fields for which we want default values
 -        @param context: A standard dictionary
 -        @return: A dictionary which of fields with values.
 -        """
 -        res = super(stock_partial_picking, self).default_get(cr, uid, fields, context=context)
 +    def __create_partial_picking_memory(self, picking, is_in):
 +        move_memory = {
 +            'product_id' : picking.product_id.id,
 +            'quantity' : picking.product_qty,
 +            'product_uom' : picking.product_uom.id,
 +            'prodlot_id' : picking.prodlot_id.id,
 +            'move_id' : picking.id,
 +        }
 +    
 +        if is_in:
 +            move_memory.update({
 +                'cost' : picking.product_id.standard_price,
 +                'currency' : picking.product_id.company_id.currency_id.id,
 +            })
 +        return move_memory
 +
 +    def __get_active_stock_pickings(self, cr, uid, context=None):
          pick_obj = self.pool.get('stock.picking')
 -        if context is None:
 -            context={}
 -        if 'date' in fields:
 -            res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
 -        for pick in pick_obj.browse(cr, uid, context.get('active_ids', []), context=context):
 +        if not context:
 +            context = {}
 +               
 +        res = []
 +        for pick in pick_obj.browse(cr, uid, context.get('active_ids', []), context):
              need_product_cost = (pick.type == 'in')
              for m in pick.move_lines:
                  if m.state in ('done', 'cancel'):
 -                    continue
 -                if 'move%s_product_id'%(m.id) in fields:
 -                    res['move%s_product_id'%(m.id)] = m.product_id.id
 -                if 'move%s_product_qty'%(m.id) in fields:
 -                    res['move%s_product_qty'%(m.id)] = m.product_qty
 -                if 'move%s_product_uom'%(m.id) in fields:
 -                    res['move%s_product_uom'%(m.id)] = m.product_uom.id
 -                if 'move%s_prodlot_id'%(m.id) in fields:
 -                    res['move%s_prodlot_id'%(m.id)] = m.prodlot_id.id
 -                if (need_product_cost and m.product_id.cost_method == 'average'):
 -                    # Always use default product cost and currency from Product Form, 
 -                    # which belong to the Company owning the product
 -                    currency = m.product_id.company_id.currency_id.id
 -                    price = m.product_id.standard_price
 -                    if 'move%s_product_price'%(m.id) in fields:
 -                        res['move%s_product_price'%(m.id)] = price
 -                    if 'move%s_product_currency'%(m.id) in fields:
 -                        res['move%s_product_currency'%(m.id)] = currency
 +                    continue           
 +                res.append(self.__create_partial_picking_memory(m, need_product_cost))
 +            
          return res
 +    
 +    _defaults = {
 +        'product_moves_in' : __get_active_stock_pickings,
 +        'product_moves_out' : __get_active_stock_pickings,
 +        'date' : lambda *a : time.strftime('%Y-%m-%d %H:%M:%S'),
 +    }
 +    
  
-     def do_partial(self, cr, uid, ids, context):
+     def do_partial(self, cr, uid, ids, context=None):
          """ Makes partial moves and pickings done.
          @param self: The object pointer.
          @param cr: A database cursor
          partial_datas = {
              'delivery_date' : partial.date
          }
-         
-        
-         for pick in pick_obj.browse(cr, uid, picking_ids):
++
+         for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
              need_product_cost = (pick.type == 'in')
 -            for m in pick.move_lines:
 -                if m.state in ('done', 'cancel'):
 +            moves_list = need_product_cost and partial.product_moves_in  or partial.product_moves_out
 +            p_moves = {}
 +            for product_move in moves_list:
 +                p_moves[product_move.move_id.id] = product_move
 +            
 +            
 +            for move in pick.move_lines:
 +                if move.state in ('done', 'cancel'):
                      continue
 -                partial_datas['move%s'%(m.id)] = {
 -                    'product_id' : getattr(partial, 'move%s_product_id'%(m.id)).id,
 -                    'product_qty' : getattr(partial, 'move%s_product_qty'%(m.id)),
 -                    'product_uom' : getattr(partial, 'move%s_product_uom'%(m.id)).id,
 -                    'prodlot_id' : getattr(partial, 'move%s_prodlot_id'%(m.id)).id
 +                if not p_moves.get(move.id):
 +                    continue
 +                
 +                partial_datas['move%s' % (move.id)] = {
 +                'product_id' : p_moves[move.id].id,
 +                'product_qty' : p_moves[move.id].quantity,
 +                'product_uom' :p_moves[move.id].product_uom.id,
 +                'prodlot_id' : p_moves[move.id].prodlot_id.id,
                  }
 -
 -                if (need_product_cost and m.product_id.cost_method == 'average'):
 -                    partial_datas['move%s'%(m.id)].update({
 -                        'product_price' : getattr(partial, 'move%s_product_price'%(m.id)),
 -                        'product_currency': getattr(partial, 'move%s_product_currency'%(m.id)).id
 -                    })
 +            
 +               
 +                if (move.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
 +                    partial_datas['move%s' % (move.id)].update({
 +                                                    'product_price' : p_moves[move.id].cost,
 +                                                    'product_currency': p_moves[move.id].currency.id,
 +                                                    })
          pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
          return {}