Skip to main content

system.kanoa.lot.executeLotOperation(lotOperationEventInfo, inputLotEvents, outputLotEvents, userId)

Creates or updates a lot operation event with input and output lot events


Parameters

lotOperationEventInfo Dictionary

- assetIdIntegerasset the operation is performed on
- enabledBoolean
- lotOperationEventIdIntegerSet to None for a new lot operation or use an existing operation event
- lotOperationIdInteger
- tStampDateTime

inputLotEvents List of Dictionaries: list of input lotEventInfo dictionaries to be consumed by this operation. All keys are required unless stated.

- assetIdInteger
- assetTransportIdIntegerNot required
- commentStringNot required
- itemIdIntegerRequired if this is a new lot
- itemUnitIdInteger
- lotEventQtyFloat
- lotIdIntegerEither lotId or lotName must be provided
- lotNameStringEither lotId or lotName must be provided
- lotStateIdInteger
- lotStateReasonIdIntegerNot required
- shiftIdIntegerNot required
- tStampDateTime
- workOrderIdIntegerNot required

outputLotEvents List of Dictionaries: list of output lotEventInfo dictionaries that are to be created by this operation

- assetIdInteger
- assetTransportIdIntegerNot required
- commentStringNot required
- itemIdIntegerRequired if this is a new lot
- itemUnitIdInteger
- lotEventQtyFloat
- lotIdIntegerEither lotId or lotName must be provided
- lotNameStringEither lotId or lotName must be provided
- lotStateIdInteger
- lotStateReasonIdIntegerNot required
- shiftIdIntegerNot required
- tStampDateTime
- workOrderIdIntegerNot required

userId Integer:Id of the user executing the function


Returns

lotOperationEventId Integer
message String None if success


Example


Receive a new lot

lotOperationId = system.kanoa.utilities.getFieldValue('lotOperationId', system.kanoa.lot.getLotOperations({'lotOperationName': 'Receive'}))
assetPath = 'Kanoa Safety Inc\Chatillon\Receiving'
assetId = system.kanoa.utilities.getFieldValue('assetId', system.kanoa.asset.getAssets({'assetPath': assetPath}))
sources = system.kanoa.utilities.convertDatasetToDict(system.kanoa.item.getItemSource({}), 'itemSourceName', 'itemSourceId')
lotStates = system.kanoa.utilities.convertDatasetToDict(system.kanoa.lot.getLotStates({}), 'lotStateName', 'lotStateId')

lotOperationEventInfo = {
'lotOperationEventId': None,
'lotOperationId': lotOperationId,
'assetId': assetId,
'tStamp': system.date.now(),
'enabled': True
}
inputLotEvents = []
outputLotEvents = [{
'lotEventId': None,
'lotId': 1,
'lotEventQty': 100,
'workOrderId': None,
'assetId':1,
'itemSourceId': sources['output'],
'lotStateId': lotStates['OK'],
'lotStateReasonId': None,
'shiftId': None,
'tStamp': system.date.now(),
'comment':None,
'lotOperationEventId': None,
'assetTransportId': None
}]
lotOperationEventId, msg = system.kanoa.lot.executeLotOperation(lotOperationEventInfo, inputLotEvents, outputLotEvents, userId)

--------------------------

Transfer lots from a transport to a new location

#Create some useful data sources
sources = system.kanoa.utilities.convertDatasetToDict(system.kanoa.item.getItemSource({}), 'itemSourceName', 'itemSourceId')
userId = system.kanoa.security.getIDPUserId({'userName': 'SYSTEM'})
assetPath = 'Kanoa Safety Inc\Chatillon\Production\Line 1'
assetId = system.kanoa.utilities.getFieldValue('assetId', system.kanoa.asset.getAssets({'assetPath': assetPath}))
timeNow = system.date.now()

#Create new lot Operation event to transfer lots
lotOperationId = system.kanoa.utilities.getFieldValue('lotOperationId', system.kanoa.lot.getLotOperations({'lotOperationName': 'Transfer'}))
lotOperationEventInfo = {
'lotOperationEventId': None,
'lotOperationId': lotOperationId,
'assetId': assetId,
'tStamp': timeNow,
'enabled': True
}

#Get lots at the assetTransport
data = system.kanoa.utilities.convertDatasetToJSON(system.kanoa.lot.getLotActivity({'assetTransportName': '2'}))

#Create lotEvents
keysToKeep = {'lotId', 'lotEventQty', 'workOrderId', 'assetId', 'lotStateId', 'lotStateReasonId'}
inputLotEvents = []
outputLotEvents = []
for lotActivity in data:
lotEventInfo = {k: v for k, v in lotActivity.items() if k in keysToKeep}

inputLotEventInfo = dict(lotEventInfo)
inputLotEventInfo['tStamp'] = timeNow
inputLotEventInfo['itemSourceId'] = sources['input']
inputLotEvents.append(inputLotEventInfo)

outputLotEventInfo = dict(lotEventInfo)
outputLotEventInfo['itemSourceId'] = sources['output']
outputLotEventInfo['assetId'] = assetId
outputLotEventInfo['assetTransportId'] = None #If you want to clear it

outputLotEvents.append(lotEventInfo)

lotOperationEventId, msg = system.kanoa.lot.executeLotOperation(lotOperationEventInfo, inputLotEvents, outputLotEvents, userId)
print lotOperationEventId, msg