'Get Depreciation'

def get_depreciation(self):

    if self.check_depreciate():
        self.set_rate()
        from_purchase = (datetime.date(datetime.now()) - self.purchase_date)
        days_from_purchase = from_purchase.days
        if (days_from_purchase >= (self.lifetime * 365)):
            return (self.initial_value - self.endlife_value).quantize(Decimal('.01'), rounding=ROUND_UP)
        straight = Decimal((((self.initial_value - self.endlife_value) / (self.lifetime * 365)) * days_from_purchase)).quantize(Decimal('.01'), rounding=ROUND_UP)
        if (self.depreciation_type == 'reducing'):
            i = self.initial_value
            daily_depreciation_rate = Decimal(str((1 - math.pow((self.endlife_value / self.initial_value), (1 / (self.lifetime * 365))))))
            for g in range(1, days_from_purchase):
                i -= (i * daily_depreciation_rate)
            reducing = round((self.initial_value - i), 2)
            if (reducing > straight):
                return reducing.quantize(Decimal('.01'), rounding=ROUND_UP)
            else:
                return straight.quantize(Decimal('.01'), rounding=ROUND_UP)
        elif (self.depreciation_type == 'straight'):
            return straight.quantize(Decimal('.01'), rounding=ROUND_UP)
        else:
            return Decimal('0.00')
    else:
        return Decimal('0.00')
