system.kanoa.lot.executeLotOperation(lotOperationEventInfo, inputLotEvents, outputLotEvents, userId)
Creates or updates a lot operation event with input and output lot events
Parameters
lotOperationEventInfo Dictionary
| - assetId | Integer | asset the operation is performed on |
| - enabled | Boolean | |
| - lotOperationEventId | Integer | Set to None for a new lot operation or use an existing operation event |
| - lotOperationId | Integer | |
| - tStamp | DateTime |
inputLotEvents List of Dictionaries: list of input lotEventInfo dictionaries to be consumed by this operation. All keys are required unless stated.
| - assetId | Integer | |
| - assetTransportId | Integer | Not required |
| - comment | String | Not required |
| - itemId | Integer | Required if this is a new lot |
| - itemUnitId | Integer | |
| - lotEventQty | Float | |
| - lotId | Integer | Either lotId or lotName must be provided |
| - lotName | String | Either lotId or lotName must be provided |
| - lotStateId | Integer | |
| - lotStateReasonId | Integer | Not required |
| - shiftId | Integer | Not required |
| - tStamp | DateTime | |
| - workOrderId | Integer | Not required |
outputLotEvents List of Dictionaries: list of output lotEventInfo dictionaries that are to be created by this operation
| - assetId | Integer | |
| - assetTransportId | Integer | Not required |
| - comment | String | Not required |
| - itemId | Integer | Required if this is a new lot |
| - itemUnitId | Integer | |
| - lotEventQty | Float | |
| - lotId | Integer | Either lotId or lotName must be provided |
| - lotName | String | Either lotId or lotName must be provided |
| - lotStateId | Integer | |
| - lotStateReasonId | Integer | Not required |
| - shiftId | Integer | Not required |
| - tStamp | DateTime | |
| - workOrderId | Integer | Not 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