I’m not addressing your logic or calculations yet, but the first thing I noticed is that you’re making a major mistake here.
As I wrote in my post at Design Problem - #4 by KenWhitesell
- Never, under any condition or circumstance, for absolutely no reason whatever, should you ever, ever even think about using FloatField for financial data or financial-related fields. Not for costs, prices, totals, hours, rates, nothing - just don’t do it. Use the Decimal field for them.
While this issue goes well beyond just Python and Django, the Python docs at 15. Floating Point Arithmetic: Issues and Limitations — Python 3.11.3 documentation do a good job of introducing the topic.
Now, regarding your logic - what makes you think something is wrong? Do you have some data that you have tested with that is giving you unexpected values? Or are you getting some type of error message?