Пример #1
0
    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
Пример #2
0
 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
Пример #3
0
    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()
Пример #4
0
 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()