Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created August 3, 2015 16:20
Show Gist options
  • Select an option

  • Save shofetim/b04771c3263c144e0bed to your computer and use it in GitHub Desktop.

Select an option

Save shofetim/b04771c3263c144e0bed to your computer and use it in GitHub Desktop.
def _parse_float(s):
return float(s.replace(',',''))
def _size_to_unit_of_measure(size):
# normalize case
size = size.lower()
# Not everything is currently split-able on white space, ie
# there are existing examples of 9oz etc. But I think those
# are date entry errors and should be corrected
parts = size.split(' ')
# surprisingly there are many floats rather than ints.
numeric = self._parse_float(parts[0])
if parts[1] == 'x':
numeric = numeric * self.parse_float(parts[2])
unit = parts[-1].replace('.', '')
return (numeric, unit)
def unit_price(level):
try:
price = self.get_price(level=level)
size = self._size_to_unit_of_measure(self.piece.name)
return price / self.quantity * size
except:
return None
def unit_price_retail():
return self.unit_price(level=RETAIL)
def unit_price_wholesale():
return self.unit_price(level=WHOLESALE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment