def employees(request): """Get a licenses employees from Metrc. Args: request (HTTPRequest): A `djangorestframework` request. """ # Authenticate the user. claims = authenticate_request(request) if not claims: message = 'Authentication failed. Please use the console or provide a valid API key.' return Response({'error': True, 'message': message}, status=403) _, project_id = google.auth.default() license_number = request.query_params.get('name') # Optional: Figure out how to pre-initialize a Metrc client. # Get Vendor API key using secret manager. # FIXME: Determine where to store project_id, secret_id, and version_id. vendor_api_key = access_secret_version(project_id=project_id, secret_id='metrc_vendor_api_key', version_id='1') # TODO: Get user API key using secret manager. user_api_key = access_secret_version(project_id=project_id, secret_id=f'{license_number}_secret', version_id='1') # Create a Metrc client. track = authorize(vendor_api_key, user_api_key) # Make a request to the Metrc API. data = track.get_employees(license_number=license_number) # Return the requested data. return Response({'data': data}, content_type='application/json')
def initialize_metrc(project_id, license_number, version_id): """Initialize a Metrc client. Optional: Figure out how to pre-initialize and save Metrc client. """ # Get vendor version number. admin_data = get_document('admin/metrc') vendor_version_id = admin_data['vendor_api_key_secret']['version_id'] # Get Vendor API key using secret manager. vendor_api_key = access_secret_version(project_id=project_id, secret_id='metrc_vendor_api_key', version_id=vendor_version_id) # Get user API key using secret manager. user_api_key = access_secret_version(project_id=project_id, secret_id=f'{license_number}_secret', version_id=version_id) track = authorize(vendor_api_key, user_api_key) return track
""" Retail Workflow """ from cannlytics.traceability import metrc # Initialize a Metrc API client. track = metrc.authorize('your-vendor-api-key', 'your-user-api-key') # Get a retail package. package = track.get_packages(label='abc') # Create a sales receipts. track.create_receipts([{...}, {...}]) # Get recent receipts. sales = track.get_receipts(action='active', start='2021-04-20') # Update the sales receipt using. sale = track.get_receipts(uid='420') sale.total_price = 25 sale.update()
# Initialize the current time. now = datetime.now() current_time = now.isoformat() current_date = now.strftime('%m/%d/%Y') today = current_time[:10] # Initialize Firebase. config = dotenv_values('../../.env') os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = config[ 'GOOGLE_APPLICATION_CREDENTIALS'] db = fb.initialize_firebase() # Initialize a Metrc client. vendor_api_key = config['METRC_TEST_VENDOR_API_KEY'] user_api_key = config['METRC_TEST_USER_API_KEY'] track = metrc.authorize(vendor_api_key, user_api_key) print('--------------------------------------------') print('Performing Metrc Validation Test') print(current_time) print('--------------------------------------------') #------------------------------------------------------------------ # Facilities #------------------------------------------------------------------ # Unless facilities are not set, then get the facilities from Metrc. # Get facilities, with permissions set by the state for each facility type. facilities = track.get_facilities() # Define primary cultivator, lab, and retailer for tests.