I built a calculator for calculating the sales commission on a certain sale.
The value of the commission is depended on a lot of factors. Therefore the parameters to have to be passed to the function in which I calculate the commission is very large too. The function itself is also very confusing, because some of the factors are booleans (new customer, f.e.) and some are floats (transport costs, f.e.).
How can I make these kind of "calculation functions" more readable? Should I break them up in smaller pieces?
Here is the function, although I am looking also for more general advice how to tackle these kind of functions.
def get_provision_sales(
verkaufspreis_hw,
einkaufspreis_hw,
vk_software,
ek_software,
bonafide,
laufzeit,
abloese,
gebraucht,
neukunde,
spedition,
sonstige_kosten,
provision_pct = 0.33,
service_pct=0.035,
solutions=False ):
if spedition:
spedition_amount = 89.99
else:
spedition_amount = 0
verkaufspreis_hw = verkaufspreis_hw or 0
if vk_software > 0:
software_mod = 0.7
else:
software_mod = 1
if not bonafide:
provision_modifier = 0.76
else:
provision_modifier = 1
if neukunde:
provision_pct = 0.27
laufzeit = laufzeit or 0
abloese = abloese or 0
if gebraucht:
db_modifier = 1
sonstige_kosten = 0
deckungsbeitrag = 0.6 * float(verkaufspreis_hw)
else:
db_modifier = 0.85
deckungsbeitrag = float(verkaufspreis_hw) - ( float(einkaufspreis_hw) + float(abloese) + float(spedition_amount) )
provision_sales = (deckungsbeitrag * db_modifier + float(sonstige_kosten)) * provision_pct * provision_modifier
provision_sales += software_mod*0.15*(float(vk_software)-float(ek_software))
return provision_sales