Currently Home Assistant tracks energy consumption costs and exports compensation separately and then just calculates the difference to calculate total cost.
In many places a counter net balance is used to to determine your total cost. In Spain for example, they calculate the difference in energy input and output in an hourly basis and then they charge you or compensate for that.
e.g. if you spend 1kwh from 13:00 to 13:30 but also exported 800wh from 13:30 to 14:00, you will only be charged for 200wh (instead of being charged 1kwh and then paid for 800wh, which is less favourable).
This feature could be enabled and configured for hourly or daily or monthly basis depending on your electric contract.