def valid_mileage_range_for_log_date(self, log, datetime, distance_units=None): if distance_units is None: distance_units = get_current_distance_unit() if distance_units == MILES: distance_field = 'mileage' else: distance_field = 'mileage_km' base_queryset = self.get_query_set().filter( log=log).values(distance_field) try: min = base_queryset.filter( date__lt=datetime).order_by('-date')[:1][0][distance_field] except: min = 0 try: max = base_queryset.filter( date__gt=datetime).order_by('date')[:1][0][distance_field] except: max = sys.maxint return (min, max)
def save(self): # rev the modified date on the MaintenanceLog if we're editing an editing action #self.log.save() if get_current_distance_unit() == MILES: self.mileage_km = decimal.Decimal(self.mileage) * KILOMETERS_PER_MILE else: self.mileage = decimal.Decimal(self.mileage_km) / KILOMETERS_PER_MILE super(MaintenanceAction, self).save()
def save(self): # rev the modified date on the MaintenanceLog if we're editing an editing action #self.log.save() if get_current_distance_unit() == MILES: self.mileage_km = decimal.Decimal( self.mileage) * KILOMETERS_PER_MILE else: self.mileage = decimal.Decimal( self.mileage_km) / KILOMETERS_PER_MILE super(MaintenanceAction, self).save()
def get_economy(self, distance_units=None, volume_units=None): if not volume_units: volume_units = get_current_volume_unit() if not distance_units: distance_units = get_current_distance_unit() economy = 0 if distance_units == MILES: economy = decimal.Decimal(self.miles) else: economy = decimal.Decimal(self.kilometers) if volume_units == GALLONS: economy = economy / decimal.Decimal(self.gallons) else: economy = economy / decimal.Decimal(self.liters) return economy
def get_economy(self, distance_units=None, volume_units=None): if not volume_units: volume_units = get_current_volume_unit() if not distance_units: distance_units = get_current_distance_unit() economy = 0 if distance_units == MILES: economy = decimal.Decimal(self.miles) else: economy = decimal.Decimal(self.kilometers) if volume_units == GALLONS: economy = economy / decimal.Decimal(self.gallons) else: economy = economy / decimal.Decimal(self.liters) return economy
def save(self): """ Save in all units to allow faster lookups, and easier inclusion of both in reporting functions. """ if get_current_volume_unit() == GALLONS: self.liters = decimal.Decimal(self.gallons) * LITERS_PER_GALLON else: self.gallons = decimal.Decimal(self.liters) / LITERS_PER_GALLON if get_current_distance_unit() == MILES: self.kilometers = decimal.Decimal(self.miles) * KILOMETERS_PER_MILE else: self.miles = decimal.Decimal(self.kilometers) / KILOMETERS_PER_MILE # Description will just be "fill up" self.description = 'Fuel fill-up' super(FillupAction, self).save()
def valid_mileage_range_for_log_date(self, log, datetime, distance_units=None): if distance_units is None: distance_units = get_current_distance_unit() if distance_units == MILES: distance_field = 'mileage' else: distance_field = 'mileage_km' base_queryset = self.get_query_set().filter(log=log).values(distance_field) try: min = base_queryset.filter(date__lt=datetime).order_by('-date')[:1][0][distance_field] except: min = 0 try: max = base_queryset.filter(date__gt=datetime).order_by('date')[:1][0][distance_field] except: max = sys.maxint return (min, max)
def save(self): """ Save in all units to allow faster lookups, and easier inclusion of both in reporting functions. """ if get_current_volume_unit() == GALLONS: self.liters = decimal.Decimal(self.gallons) * LITERS_PER_GALLON else: self.gallons = decimal.Decimal(self.liters) / LITERS_PER_GALLON if get_current_distance_unit() == MILES: self.kilometers = decimal.Decimal(self.miles) * KILOMETERS_PER_MILE else: self.miles = decimal.Decimal(self.kilometers) / KILOMETERS_PER_MILE # Description will just be "fill up" self.description = 'Fuel fill-up' super(FillupAction, self).save()