I have a plugin that monitors the RetrieveExchangeRate message in order to override the rate if the record it is being applied to has a populated field called abc_customexchangerate. This works well when updating a given record through a form for example. If abc_customexhcnagerate has a value in it and I update a money field on the form then the exchangerate field will get populated with the value from abc_customexchangerate and the base value will then be calculated automatically using this custom rate.
Where I am running in to problems is when I have a parent/child relationship.
For example I have a Contract parent entity that contains references to 1 or more ContractItem records. The child ContractItem records have a cost field but don't have a abc_customexchangerate field. This means that when I update the cost, the base cost will be calculated using the normal exchange rate pulled from the currencies table. This is as expected/wanted.
When a child cost changes though I also trigger a plugin to calculate a total cost across all child items for the affected parent and update the TotalCost money field on the parent. The parent DOES have an abc_customexchangerate field but this is typically ignored as a new call to RetrieveExchangeRate is not being made (so my exchange rate interceptor plugin never fires).
From the tests I have done...
1) if the transaction currency used by the Child Item is the same as that used by Parent then the exchange rate retrieved when updating the child's cost field is being used when the calculating the base total cost (on the parent) after updating the total cost field (on the parent). This means that a call to RetrieveExchangeRate isn't made from the parent and so the base value for the Total Cost is calculated using the Exchange rate retrieved when updating the child record and not the abc_customexchangerate I need it to use.
2) if the transaction currency used by the Child Item is NOT the same as that used by the Parent then RetrieveExchangeRate is called, my exchange rate interceptor plugin kicks in, and the base value for the Total Cost is correctly calculated using the abc_customexchangerate.
Does anyone know how to overcome this issue so that RetrieveExchangeRate is called when the parent Total Cost is updated in response to a cost being updated in a child, even when the parent and child currencies are the same?
Thanks
Alan