Guest User

Untitled

a guest
Apr 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1.  
  2. class stock_return_picking(osv.osv_memory):
  3.     _inherit = 'stock.return.picking'
  4.  
  5.     def create_returns(self, cr, uid, ids, context=None):
  6.         """
  7.         Creates return picking.
  8.         @param self: The object pointer.
  9.         @param cr: A database cursor
  10.         @param uid: ID of the user currently logged in
  11.         @param ids: List of ids selected
  12.         @param context: A standard dictionary
  13.         @return: A dictionary which of fields with values.
  14.        """
  15.         if context is None:
  16.             context = {}
  17.         record_id = context and context.get('active_id', False) or False
  18.         move_obj = self.pool.get('stock.move')
  19.         pick_obj = self.pool.get('stock.picking')
  20.         uom_obj = self.pool.get('product.uom')
  21.         wf_service = netsvc.LocalService("workflow")
  22.    
  23.         pick = pick_obj.browse(cr, uid, record_id, context=context)
  24.         data = self.read(cr, uid, ids[0])
  25.         new_picking = None
  26.         date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
  27.  
  28.         set_invoice_state_to_none = True
  29.         returned_lines = 0
  30.         for move in pick.move_lines:
  31.             if not new_picking:
  32.                 if pick.type=='out':
  33.                     new_type = 'in'
  34.                 elif pick.type=='in':
  35.                     new_type = 'out'
  36.                 else:
  37.                     new_type = 'internal'
  38.                 new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
  39.                         'move_lines':[], 'state':'draft', 'type':new_type,
  40.                         'date':date_cur, 'invoice_state':data['invoice_state'],})
  41.             new_location=move.location_dest_id.id
  42.             if move.state=='done':
  43.                 new_qty = data['return%s' % move.id]
  44.                 returned_qty = move.product_qty
  45.  
  46.                 for rec in move.move_history_ids2:
  47.                     returned_qty -= rec.product_qty
  48.  
  49.                 if returned_qty != new_qty:
  50.                     set_invoice_state_to_none = False
  51.  
  52.                 if new_qty:
  53.                     returned_lines += 1
  54.                     new_move=move_obj.copy(cr, uid, move.id, {
  55.                         'product_qty': new_qty,
  56.                         'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
  57.                             new_qty, move.product_uos.id),
  58.                         'picking_id':new_picking, 'state':'draft',
  59.                         'location_id':new_location, 'location_dest_id':move.location_id.id,
  60.                         'date':date_cur,})
  61.                     move_obj.write(cr, uid, [move.id], {'product_qty': returned_qty - new_qty, 'move_history_ids2':[(4,new_move)]})
  62.  
  63.         if not returned_lines:
  64.             raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
  65.  
  66.         if set_invoice_state_to_none:
  67.             pick_obj.write(cr, uid, [pick.id], {'invoice_state':'none'})
  68.         wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
  69.         pick_obj.force_assign(cr, uid, [new_picking], context)
  70.         # Update view id in context, lp:702939
  71.         view_list = {
  72.                 'out': 'view_picking_out_tree',
  73.                 'in': 'view_picking_in_tree',
  74.                 'internal': 'vpicktree',
  75.             }
  76.         data_obj = self.pool.get('ir.model.data')
  77.         res = data_obj.get_object_reference(cr, uid, 'stock', view_list.get(new_type, 'vpicktree'))
  78.         context.update({'view_id': res and res[1] or False})
  79.         return {
  80.             'domain': "[('id', 'in', ["+str(new_picking)+"])]",
  81.             'name': 'Picking List',
  82.             'view_type':'form',
  83.             'view_mode':'tree,form',
  84.             'res_model':'stock.picking',
  85.             'type':'ir.actions.act_window',
  86.             'context':context,
  87.         }
  88.  
  89. stock_return_picking()
Add Comment
Please, Sign In to add comment