EconomicEvent and EconomicResource create and update
Experimenting with some pseudo-code, please improve as needed. @pospi @ivanminutillo @bhaugen
EconomicEvent which creates an EconomicResource:
If action.resourceEffect is "+" or "-"
If create-resource flag is set
Create the resource with zero quantity fields
Else
If it exists
Get the resource based on resourceInventoriedAs
If there is a resource from the above
If action.resourceEffect is "+"
Add event resourceQuantity to both accountingQuantity and onhandQuantity
Else if action.resourceEffect is "-"
Subtract event resourceQuantity from both accountingQuantity and onhandQuantity
Else if action.resourceEffect is "-+" or action.onhandEffect is "-+" (two resources can be affected)
If create-resource flag is set
Create the to-resource with zero quantity fields
Else
Get the to-resource based on toResourceInventoriedAs
If it exists in the event
Get the from-resource based on the resourceInventoriedAs
If action is "transfer-custody" or "transfer" or "move"
If the from-resource exists
Subtract event resourceQuantity from from-resource.onhandQuantity
If the to-resource exists
Add event resourceQuantity to to-resource.onhandQuantity
If action is "transfer-all-rights" or "transfer" or "move"
If the from-resource exists
Subtract event resourceQuantity from from-resource.accountingQuantity
If the to-resource exists
Add event resourceQuantity to to-resource.accountingQuantity
If a new resource is created by the economic event
or if ((action is "transfer-all-rights" or "transfer")
and resourceInventoriedAs is the same as toResourceInventoriedAs)
Set the primaryAccountable to the receiver agent