#NEWLINE# def recv( ) : #NEWLINE# #INDENT# ' RESTful CRUD controller ' #NEWLINE# recvtable = s3db . inv_recv #NEWLINE# if ( settings . get_inv_shipment_name ( ) == 'order' ) : #NEWLINE# #INDENT# error_msg = T ( 'You do not have permission for any facility to add an order.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error_msg = T ( 'You do not have permission for any facility to receive a shipment.' ) #NEWLINE# #UNINDENT# auth . permitted_facilities ( table = recvtable , error_msg = error_msg ) #NEWLINE# tracktable = s3db . inv_track_item #NEWLINE# atable = s3db . inv_adj_item #NEWLINE# id = request . args ( 0 ) #NEWLINE# if ( id and isinstance ( id , int ) ) : #NEWLINE# #INDENT# record = db ( ( recvtable . id == id ) ) . select ( recvtable . recipient_id , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# try : #NEWLINE# #INDENT# if ( record . recipient_id is None ) : #NEWLINE# #INDENT# db ( ( recvtable . id == id ) ) . update ( recipient_id = auth . s3_logged_in_person ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# status = s3db . inv_ship_status #NEWLINE# SHIP_STATUS_IN_PROCESS = status [ 'IN_PROCESS' ] #NEWLINE# SHIP_STATUS_SENT = status [ 'SENT' ] #NEWLINE# SHIP_STATUS_RECEIVED = status [ 'RECEIVED' ] #NEWLINE# SHIP_STATUS_CANCEL = status [ 'CANCEL' ] #NEWLINE# status = s3db . inv_tracking_status #NEWLINE# TRACK_STATUS_UNKNOWN = status [ 'UNKNOWN' ] #NEWLINE# TRACK_STATUS_PREPARING = status [ 'IN_PROCESS' ] #NEWLINE# TRACK_STATUS_TRANSIT = status [ 'SENT' ] #NEWLINE# TRACK_STATUS_UNLOADING = status [ 'UNLOADING' ] #NEWLINE# TRACK_STATUS_ARRIVED = status [ 'RECEIVED' ] #NEWLINE# TRACK_STATUS_CANCELED = status [ 'CANCEL' ] #NEWLINE# def set_track_attr( status ) : #NEWLINE# #INDENT# for field in tracktable . fields : #NEWLINE# #INDENT# tracktable [ field ] . writable = False #NEWLINE# #UNINDENT# tracktable . send_id . readable = False #NEWLINE# tracktable . recv_id . readable = False #NEWLINE# tracktable . bin . readable = False #NEWLINE# tracktable . adj_item_id . readable = False #NEWLINE# tracktable . recv_quantity . readable = True #NEWLINE# if ( status == TRACK_STATUS_PREPARING ) : #NEWLINE# #INDENT# tracktable . item_source_no . writable = True #NEWLINE# tracktable . item_id . writable = True #NEWLINE# tracktable . item_pack_id . writable = True #NEWLINE# tracktable . quantity . writable = True #NEWLINE# tracktable . currency . writable = True #NEWLINE# tracktable . pack_value . writable = True #NEWLINE# tracktable . expiry_date . writable = True #NEWLINE# tracktable . recv_bin . writable = True #NEWLINE# tracktable . owner_org_id . writable = True #NEWLINE# tracktable . supply_org_id . writable = True #NEWLINE# tracktable . inv_item_status . writable = True #NEWLINE# tracktable . comments . writable = True #NEWLINE# tracktable . recv_quantity . readable = False #NEWLINE# tracktable . send_inv_item_id . readable = False #NEWLINE# tracktable . recv_bin . label = T ( 'Bin' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status == TRACK_STATUS_TRANSIT ) : #NEWLINE# #INDENT# tracktable . send_inv_item_id . readable = False #NEWLINE# tracktable . send_inv_item_id . writable = False #NEWLINE# tracktable . item_source_no . readable = True #NEWLINE# tracktable . item_source_no . writable = False #NEWLINE# tracktable . recv_quantity . writable = True #NEWLINE# tracktable . recv_bin . readable = True #NEWLINE# tracktable . recv_bin . writable = True #NEWLINE# tracktable . comments . writable = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status == TRACK_STATUS_ARRIVED ) : #NEWLINE# #INDENT# tracktable . item_source_no . readable = True #NEWLINE# tracktable . item_source_no . writable = False #NEWLINE# tracktable . item_id . writable = False #NEWLINE# tracktable . send_inv_item_id . writable = False #NEWLINE# tracktable . item_pack_id . writable = False #NEWLINE# tracktable . quantity . writable = False #NEWLINE# tracktable . currency . writable = False #NEWLINE# tracktable . pack_value . writable = False #NEWLINE# tracktable . expiry_date . writable = False #NEWLINE# tracktable . owner_org_id . writable = False #NEWLINE# tracktable . supply_org_id . writable = False #NEWLINE# tracktable . recv_bin . readable = True #NEWLINE# tracktable . recv_bin . writable = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# def prep( r ) : #NEWLINE# #INDENT# record = r . record #NEWLINE# if ( record and ( record . status not in ( SHIP_STATUS_IN_PROCESS , SHIP_STATUS_SENT ) ) ) : #NEWLINE# #INDENT# s3db . configure ( 'inv_recv' , create = False , deletable = False , editable = False , listadd = False ) #NEWLINE# #UNINDENT# component = r . component #NEWLINE# if ( record and component and ( component . name == 'track_item' ) ) : #NEWLINE# #INDENT# if ( ( r . method == 'create' ) or ( r . method == 'delete' ) ) : #NEWLINE# #INDENT# if ( record . status != SHIP_STATUS_IN_PROCESS ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# if r . component_id : #NEWLINE# #INDENT# track_record = db ( ( tracktable . id == r . component_id ) ) . select ( tracktable . status , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# set_track_attr ( track_record . status ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# set_track_attr ( TRACK_STATUS_PREPARING ) #NEWLINE# tracktable . status . readable = False #NEWLINE# #UNINDENT# if ( record . status == SHIP_STATUS_IN_PROCESS ) : #NEWLINE# #INDENT# s3 . crud_strings . inv_recv . title_update = s3 . crud_strings . inv_recv . title_display = T ( 'Process Received Shipment' ) #NEWLINE# #UNINDENT# tracktable . supply_org_id . default = record . organisation_id #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if r . id : #NEWLINE# #INDENT# record = db ( ( recvtable . id == r . id ) ) . select ( recvtable . status , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# set_recv_attr ( record . status ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# set_recv_attr ( SHIP_STATUS_IN_PROCESS ) #NEWLINE# recvtable . recv_ref . readable = False #NEWLINE# if ( r . method and ( r . method != 'read' ) ) : #NEWLINE# #INDENT# recvtable . status . readable = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return True #NEWLINE# #UNINDENT# s3 . prep = prep #NEWLINE# if ( ( len ( request . args ) > 1 ) and ( request . args [ 1 ] == 'track_item' ) ) : #NEWLINE# #INDENT# record = db ( ( recvtable . id == request . args [ 0 ] ) ) . select ( recvtable . status , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# status = ( record . status if record else None ) #NEWLINE# if ( status == SHIP_STATUS_SENT ) : #NEWLINE# #INDENT# list_fields = [ 'id' , 'status' , 'item_id' , 'item_pack_id' , 'quantity' , 'currency' , 'pack_value' , 'recv_quantity' , 'recv_bin' , 'owner_org_id' , 'supply_org_id' ] #NEWLINE# s3db . configure ( 'inv_track_item' , create = False , deletable = False , editable = True , listadd = False , list_fields = list_fields ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if status : #NEWLINE# #INDENT# s3db . configure ( 'inv_track_item' , create = False , deletable = False , editable = False , listadd = False ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# output = s3_rest_controller ( rheader = s3db . inv_recv_rheader ) #NEWLINE# return recvtable