#NEWLINE# def handle( self , * args , **options ) : #NEWLINE# #INDENT# self . stdout . write ( 'Processing products...\n' ) #NEWLINE# products = set ( ) #NEWLINE# total = StockState . objects . count ( ) #NEWLINE# failed = [ ] #NEWLINE# for ( i , ss ) in enumerate ( StockState . objects . all ( ) ) : #NEWLINE# #INDENT# if ( ( i % 500 ) == 0 ) : #NEWLINE# #INDENT# self . stdout . write ( 'done {}/{}' . format ( i , total ) ) #NEWLINE# #UNINDENT# if ( ss . product_id not in products ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# product = Product . get ( ss . product_id ) #NEWLINE# assert ( product . doc_type == 'Product' ) #NEWLINE# products . add ( ss . product_id ) #NEWLINE# #UNINDENT# except ( ResourceNotFound , AssertionError ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# case = CommCareCase . get ( ss . case_id ) #NEWLINE# #UNINDENT# except ResourceNotFound : #NEWLINE# #INDENT# case = CommCareCase ( ) #NEWLINE# #UNINDENT# failed . append ( ( ss , case ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if failed : #NEWLINE# #INDENT# for ( ss , case ) in failed : #NEWLINE# #INDENT# self . stdout . write ( 'No product with ID "{}" found! case ID: {}, domain {}' . format ( ss . product_id , ss . case_id , case . domain ) ) #NEWLINE# #UNINDENT# self . stderr . write ( '{}/{} stock states FAILED check' . format ( len ( failed ) , total ) )