Update logic for calculating markup from margin
to assume margin value is between 0 - 100 by default, instead of assuming it's between 0.0 - 1.0 part of a broader effort to standardize how we handle percentage values
This commit is contained in:
parent
8fb67c2ce2
commit
b6803ce301
|
@ -27,6 +27,7 @@ Pricing Utilities
|
|||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import decimal
|
||||
import warnings
|
||||
|
||||
|
||||
def gross_margin(price, cost, percentage=False):
|
||||
|
@ -59,12 +60,19 @@ def gross_margin(price, cost, percentage=False):
|
|||
return 100 * margin
|
||||
|
||||
|
||||
def calculate_markup(margin):
|
||||
def calculate_markup_from_margin(margin, from_decimal=False):
|
||||
"""
|
||||
Calculate the "markup" value corresponding to the given margin.
|
||||
|
||||
:param margin: Profit margin as decimal percentage (e.g. between
|
||||
0.0 and 1.0).
|
||||
This assumes the ``margin`` value is user-friendly, e.g. ``37.5``
|
||||
instead of ``0.375`` to represent 37.5%, unless ``from_decimal``
|
||||
is true in which case the decimal format is assumed.
|
||||
|
||||
:param margin: Profit margin percentage.
|
||||
|
||||
:param from_decimal: If false (the default), then ``margin``
|
||||
should (normally) be between 0 - 100. But if true, then
|
||||
``margin`` is assumed to be between 0.0 and 1.0 instead.
|
||||
|
||||
:returns: Equivalent cost markup as decimal value (e.g. 1.4).
|
||||
"""
|
||||
|
@ -73,7 +81,24 @@ def calculate_markup(margin):
|
|||
if margin == 0:
|
||||
return 1
|
||||
|
||||
return 1 / (1 - margin)
|
||||
if from_decimal:
|
||||
margin *= 100
|
||||
|
||||
return 100 / (100 - margin)
|
||||
|
||||
|
||||
def calculate_markup_from_margin_decimal(margin):
|
||||
warnings.warn("calculate_markup_from_margin_decimal() is deprecated; "
|
||||
"please use calculate_markup_from_margin() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return calculate_markup_from_margin(margin, from_decimal=True)
|
||||
|
||||
|
||||
def calculate_markup(margin):
|
||||
warnings.warn("calculate_markup() is deprecated; please use "
|
||||
"calculate_markup_from_margin() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return calculate_markup_from_margin(margin, from_decimal=True)
|
||||
|
||||
|
||||
def calculate_variance(oldvalue, newvalue):
|
||||
|
|
Loading…
Reference in a new issue