[FIX] Stock : Fixed the problem suggested by Buildbot
[odoo/odoo.git] / addons / stock / wizard / stock_split_move.py
index 0092656..aa7e4c1 100644 (file)
@@ -25,9 +25,8 @@ class stock_split_move_line(osv.osv_memory):
     _name = 'stock.move.line.split'
     _description = "Split Moves"
     
-    def default_get(self, cr, uid, fields, context):
-        """ 
-         To get default values for the object.
+    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
@@ -35,17 +34,18 @@ class stock_split_move_line(osv.osv_memory):
          @param context: A standard dictionary 
          @return: A dictionary which of fields with values. 
         """ 
+        if context is None:
+            context = {}
         res = super(stock_split_move_line, self).default_get(cr, uid, fields, context=context)
         record_id = context and context.get('active_id', False) or False
         pick_obj = self.pool.get('stock.picking')
-        pick = pick_obj.browse(cr, uid, record_id)
+        pick = pick_obj.browse(cr, uid, record_id, context=context)
         for m in [line for line in pick.move_lines]:
             res['move%s'%(m.id)] = m.product_qty
         return res
     
     def view_init(self, cr, uid, fields_list, context=None):
-        """ 
-         Creates view dynamically and adding fields at runtime.
+        """ Creates view dynamically and adding fields at runtime.
          @param self: The object pointer.
          @param cr: A database cursor
          @param uid: ID of the user currently logged in
@@ -57,7 +57,7 @@ class stock_split_move_line(osv.osv_memory):
         if record_id:
             pick_obj = self.pool.get('stock.picking')
             try:
-                pick = pick_obj.browse(cr, uid, record_id)
+                pick = pick_obj.browse(cr, uid, record_id, context=context)
                 for m in [line for line in pick.move_lines]:
                     if 'move%s' % m.id not in self._columns:
                         self._columns['move%s' % m.id] = fields.float(string=m.product_id.name)
@@ -67,8 +67,7 @@ class stock_split_move_line(osv.osv_memory):
     
     def fields_view_get(self, cr, uid, view_id=None, view_type='form', 
                         context=None, toolbar=False, submenu=False):
-        """ 
-         Changes the view dynamically
+        """ Changes the view dynamically
          @param self: The object pointer.
          @param cr: A database cursor
          @param uid: ID of the user currently logged in
@@ -79,7 +78,7 @@ class stock_split_move_line(osv.osv_memory):
         record_id = context and context.get('active_id', False) or False
         assert record_id,'Active ID not found'
         pick_obj = self.pool.get('stock.picking')
-        pick = pick_obj.browse(cr, uid, record_id)
+        pick = pick_obj.browse(cr, uid, record_id, context=context)
         arch_lst = ['<?xml version="1.0"?>', '<form string="Split lines">', '<label string="Indicate here the quantity of the new line. A quantity of zero will not split the line." colspan="4"/>']
         for m in [line for line in pick.move_lines]:
             quantity = m.product_qty
@@ -93,9 +92,8 @@ class stock_split_move_line(osv.osv_memory):
         res['arch'] = '\n'.join(arch_lst)
         return res
     
-    def split_lines(self, cr, uid, ids, context):
-        """ 
-         Splits moves in quantity given in the wizard.
+    def split_lines(self, cr, uid, ids, context=None):
+        """ Splits moves in quantity given in the wizard.
          @param self: The object pointer.
          @param cr: A database cursor
          @param uid: ID of the user currently logged in
@@ -103,13 +101,14 @@ class stock_split_move_line(osv.osv_memory):
          @param context: A standard dictionary 
          @return: A dictionary which of fields with values. 
         """ 
+        if context is None:
+            context = {}
         move_obj = self.pool.get('stock.move')
         record_id = context and context.get('active_id', False) or False
         pick_obj = self.pool.get('stock.picking')
-        pick = pick_obj.browse(cr, uid, record_id)
+        pick = pick_obj.browse(cr, uid, record_id, context=context)
         data = self.read(cr, uid, ids[0])
-        move_ids = [m.id for m in [line for line in pick.move_lines]]
-        for move in move_obj.browse(cr, uid, move_ids):
+        for move in pick.move_lines:
             quantity = data['move%s' % move.id]
             if 0 < quantity < move.product_qty:
                 new_qty = move.product_qty - quantity
@@ -117,7 +116,7 @@ class stock_split_move_line(osv.osv_memory):
                 new_obj = move_obj.copy(cr, uid, move.id, {'product_qty' : new_qty, 'product_uos_qty': new_uos_qty, 'state':move.state})
                 uos_qty = quantity / move.product_qty * move.product_uos_qty
                 move_obj.write(cr, uid, [move.id], {'product_qty' : quantity, 'product_uos_qty': uos_qty})
-        return {}
+        return {'type': 'ir.actions.act_window_close'}
     
 stock_split_move_line()