#NEWLINE# def inv_item( ) : #NEWLINE# #INDENT# ' REST Controller ' #NEWLINE# viewing = get_vars . get ( 'viewing' , None ) #NEWLINE# if viewing : #NEWLINE# #INDENT# ( tn , id ) = viewing . split ( '.' , 1 ) #NEWLINE# if ( tn == 'inv_track_item' ) : #NEWLINE# #INDENT# table = s3db . inv_track_item #NEWLINE# record = db ( ( table . id == id ) ) . select ( table . item_id , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# redirect ( URL ( c = 'inv' , f = 'track_movement' , args = [ ] , vars = { #NEWLINE# #INDENT# 'viewing' : ( '%s.%s' % ( 'inv_inv_item' , record . item_id ) ) , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# #UNINDENT# tablename = 'inv_inv_item' #NEWLINE# table = s3db [ tablename ] #NEWLINE# auth . permitted_facilities ( table = table , error_msg = T ( 'You do not have permission for any site to add an inventory item.' ) ) #NEWLINE# s3 . crud_strings [ tablename ] . msg_list_empty = T ( 'No Stock currently registered' ) #NEWLINE# report = get_vars . get ( 'report' ) #NEWLINE# if ( report == 'mon' ) : #NEWLINE# #INDENT# s3 . crud_strings [ tablename ] . update ( dict ( title_list = T ( 'Monetization Report' ) , subtitle_list = T ( 'Monetization Details' ) ) ) #NEWLINE# s3db . configure ( tablename , list_fields = [ 'id' , ( T ( 'Donor' ) , 'supply_org_id' ) , ( T ( 'Items/Description' ) , 'item_id' ) , ( T ( 'Quantity' ) , 'quantity' ) , ( T ( 'Unit' ) , 'item_pack_id' ) , ( T ( 'Unit Value' ) , 'pack_value' ) , ( T ( 'Total Value' ) , 'total_value' ) , ( T ( 'Remarks' ) , 'comments' ) , 'status' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s3db . configure ( tablename , insertable = settings . get_inv_direct_stock_edits ( ) , list_fields = [ 'id' , 'site_id' , 'item_id' , 'item_id$code' , 'item_id$item_category_id' , 'quantity' , 'pack_value' ] ) #NEWLINE# #UNINDENT# if ( ( len ( request . args ) > 1 ) and ( request . args [ 1 ] == 'track_item' ) ) : #NEWLINE# #INDENT# s3db . configure ( 'inv_track_item' , create = False , listadd = False , editable = False , deletable = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s3 . filter = ( table . quantity != 0 ) #NEWLINE# #UNINDENT# def prep( r ) : #NEWLINE# #INDENT# if ( r . method != 'report' ) : #NEWLINE# #INDENT# s3 . dataTable_group = 1 #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# s3 . prep = prep #NEWLINE# def import_prep( data ) : #NEWLINE# #INDENT# '\n            Deletes all Stock records of the organisation/branch\n            before processing a new data import\n        ' #NEWLINE# ( resource , tree ) = data #NEWLINE# xml = current . xml #NEWLINE# tag = xml . TAG #NEWLINE# att = xml . ATTRIBUTE #NEWLINE# if s3 . importerReplace : #NEWLINE# #INDENT# if ( tree is not None ) : #NEWLINE# #INDENT# root = tree . getroot ( ) #NEWLINE# expr = ( "/%s/%s[@%s='org_organisation']/%s[@%s='name']" % ( tag . root , tag . resource , att . name , tag . data , att . field ) ) #NEWLINE# orgs = root . xpath ( expr ) #NEWLINE# otable = s3db . org_organisation #NEWLINE# stable = s3db . org_site #NEWLINE# itable = s3db . inv_inv_item #NEWLINE# for org in orgs : #NEWLINE# #INDENT# org_name = ( org . get ( 'value' , None ) or org . text ) #NEWLINE# if org_name : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# org_name = json . loads ( xml . xml_decode ( org_name ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if org_name : #NEWLINE# #INDENT# query = ( ( ( otable . name == org_name ) & ( stable . organisation_id == otable . id ) ) & ( itable . site_id == stable . id ) ) #NEWLINE# resource = s3db . resource ( 'inv_inv_item' , filter = query ) #NEWLINE# resource . delete ( format = 'xml' , cascade = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# resource . skip_import = True #NEWLINE# #UNINDENT# #UNINDENT# s3 . import_prep = import_prep #NEWLINE# s3 . importerPrep = ( lambda : dict ( ReplaceOption = T ( 'Remove existing data before import' ) ) ) #NEWLINE# output = s3_rest_controller ( pdf_paper_alignment = 'Landscape' , pdf_table_autogrow = 'B' , pdf_groupby = 'site_id, item_id' , pdf_orderby = 'expiry_date, supply_org_id' , rheader = s3db . inv_rheader ) #NEWLINE# if ( ( 'add_btn' in output ) and ( not settings . get_inv_direct_stock_edits ( ) ) ) : #NEWLINE# #INDENT# del output [ 'add_btn' ] #NEWLINE# #UNINDENT# return output