Skip to main content

Important Lot Functions

FunctionWhat it does
system.kanoa.lot.executeLotOperationCreates a lot operation event with all its input and output lot events in one call, so the genealogy is never left half-written
system.kanoa.lot.getLotActivityReturns the lots that currently have material, with quantity by asset and state, filtered by asset, lot name, transport and more

A transfer screen uses both in a loop:

  1. The user picks a source asset, and getLotActivity lists the lots there.
  2. The user picks a lot, a quantity and a destination.
  3. executeLotOperation runs a Transfer: an input at the source and an output at the destination.
  4. The screen calls getLotActivity again to refresh.

A receiving screen only needs the second function: an operation with no inputs and one output.

Building your own screen

Run the operation by hand in Lot Manager first. Note its inputs and outputs, build the same payload in your script, check quantities before you call executeLotOperation, and show a clear success or error message.

Reference Materials: executeLotOperation

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


Reference Materials: getLotActivity

Returns lots along with quantities grouped by location (asset) and state, filtered by the given parameters


Parameters​

paramsDict Dictionary

- assetIdInteger
- assetPathString
- assetTransportNameString
- endDateDateTime
- hasQtyBooleanOnly return lots that have some quantity
- itemIdInteger
- itemNameString
- itemPathString
- lotIdInteger
- lotNameString
- lotStateNameString
- lotStateReasonNameString
- startDateDateTime
- workOrderIdInteger
- workOrderNameString

Returns​

lotActivityData pyDataset


Example​

paramsDict = {'lotName': 'ACRT123'}
lotData = system.kanoa.lot.getLotActivity(paramsDict)
print lotData