2013-06-27 09:43:56 +00:00
# -*- coding: utf-8 -*-
from openerp . osv import fields , osv
2013-07-31 17:23:54 +00:00
from openerp . tools . translate import _
2013-06-27 09:43:56 +00:00
2013-06-27 13:13:29 +00:00
class stock_picking_wave ( osv . osv ) :
_name = " stock.picking.wave "
2013-08-01 15:52:39 +00:00
_order = " name desc "
2013-06-27 09:43:56 +00:00
_columns = {
2014-02-14 14:57:12 +00:00
' name ' : fields . char ( ' Picking Wave Name ' , required = True , help = ' Name of the picking wave ' ) ,
2014-01-30 10:58:01 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible ' , help = ' Person responsible for this wave ' ) ,
2013-06-27 09:43:56 +00:00
' picking_ids ' : fields . one2many ( ' stock.picking ' , ' wave_id ' , ' Pickings ' , help = ' List of picking associated to this wave ' ) ,
2014-02-12 14:13:02 +00:00
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' in_progress ' , ' Running ' ) , ( ' done ' , ' Done ' ) , ( ' cancel ' , ' Cancelled ' ) ] , string = " State " , required = True ) ,
2013-06-27 09:43:56 +00:00
}
2013-08-03 14:41:22 +00:00
2013-07-31 13:28:36 +00:00
_defaults = {
2013-08-01 15:22:15 +00:00
' name ' : ' / ' ,
2014-01-20 15:43:48 +00:00
' state ' : ' draft ' ,
2013-07-31 13:28:36 +00:00
}
2013-06-27 09:43:56 +00:00
def confirm_picking ( self , cr , uid , ids , context = None ) :
picking_todo = self . pool . get ( ' stock.picking ' ) . search ( cr , uid , [ ( ' wave_id ' , ' in ' , ids ) ] , context = context )
2014-01-20 15:43:48 +00:00
self . write ( cr , uid , ids , { ' state ' : ' in_progress ' } , context = context )
return self . pool . get ( ' stock.picking ' ) . action_assign ( cr , uid , picking_todo , context = context )
2013-06-27 09:43:56 +00:00
def cancel_picking ( self , cr , uid , ids , context = None ) :
picking_todo = self . pool . get ( ' stock.picking ' ) . search ( cr , uid , [ ( ' wave_id ' , ' in ' , ids ) ] , context = context )
2013-07-29 14:12:50 +00:00
self . pool . get ( ' stock.picking ' ) . action_cancel ( cr , uid , picking_todo , context = context )
2013-08-01 15:52:39 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } , context = context )
2013-06-27 09:43:56 +00:00
2013-07-29 15:20:12 +00:00
def print_picking ( self , cr , uid , ids , context = None ) :
'''
This function print the report for all picking_ids associated to the picking wave
'''
2014-03-14 15:13:20 +00:00
context = context or { }
2014-03-27 17:42:28 +00:00
return self . pool . get ( " report " ) . get_action ( cr , uid , ids , ' stock_picking_wave.report_pickingwave ' , context = context )
2013-07-29 15:20:12 +00:00
2013-07-31 13:28:36 +00:00
def create ( self , cr , uid , vals , context = None ) :
2013-08-01 15:22:15 +00:00
if vals . get ( ' name ' , ' / ' ) == ' / ' :
2013-07-31 13:28:36 +00:00
vals [ ' name ' ] = self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' picking.wave ' ) or ' / '
return super ( stock_picking_wave , self ) . create ( cr , uid , vals , context = context )
def copy ( self , cr , uid , id , default = None , context = None ) :
if not default :
default = { }
default . update ( {
2013-08-01 15:22:15 +00:00
' state ' : ' in_progress ' ,
2013-07-31 13:28:36 +00:00
' name ' : self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' picking.wave ' ) ,
} )
2013-08-01 15:22:15 +00:00
return super ( stock_picking_wave , self ) . copy ( cr , uid , id , default = default , context = context )
2013-07-31 13:28:36 +00:00
2013-08-01 15:22:15 +00:00
def done ( self , cr , uid , ids , context = None ) :
2014-02-03 07:28:33 +00:00
picking_todo = set ( )
2014-01-30 10:58:01 +00:00
for wave in self . browse ( cr , uid , ids , context = context ) :
for picking in wave . picking_ids :
2014-02-03 07:28:33 +00:00
if picking . state in ( ' cancel ' , ' done ' ) :
continue
if picking . state != ' assigned ' :
raise osv . except_osv ( _ ( ' Warning ' ) , _ ( ' Some pickings are still waiting for goods. Please check or force their availability before setting this wave to done. ' ) )
picking_todo . add ( picking . id )
2014-01-20 15:43:48 +00:00
if picking_todo :
2014-02-03 07:28:33 +00:00
self . pool . get ( ' stock.picking ' ) . action_done ( cr , uid , list ( picking_todo ) , context = context )
2013-07-31 13:28:36 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' done ' } , context = context )
2013-06-27 09:43:56 +00:00
class stock_picking ( osv . osv ) :
_inherit = " stock.picking "
2013-07-01 14:39:09 +00:00
_columns = {
2014-01-31 10:28:01 +00:00
' wave_id ' : fields . many2one ( ' stock.picking.wave ' , ' Picking Wave ' , states = { ' done ' : [ ( ' readonly ' , True ) ] , ' cancel ' : [ ( ' readonly ' , True ) ] } , help = ' Picking wave associated to this picking ' ) ,
2013-07-30 16:20:26 +00:00
}