Permalink
Browse files

Merge pull request #27 from wmatyskiewicz/deprecation

Deprecation
  • Loading branch information...
2 parents b141732 + f71177a commit 8daf4b694e6adac1cf6db3ff099b03d6ab11959e @deshipu deshipu committed Jun 26, 2013
Showing with 10 additions and 10 deletions.
  1. +6 −9 src/ralph_assets/models_assets.py
  2. +4 −1 src/ralph_assets/tests/unit/tests_models.py
View
15 src/ralph_assets/models_assets.py
@@ -310,19 +310,16 @@ def __init__(self, *args, **kwargs):
self.saving_user = None
super(Asset, self).__init__(*args, **kwargs)
+ def get_deprecation_months(self):
+ return (1 / self.deprecation_rate * 12) if self.deprecation_rate else 0
+
def is_deprecated(self):
- if not self.support_period or not self.invoice_date:
+ if not self.invoice_date:
return False
- if isinstance(self.invoice_date, basestring):
- self.invoice_date = datetime.datetime.strptime(
- self.invoice_date, '%Y-%m-%d'
- )
deprecation_date = self.invoice_date + relativedelta(
- months=self.support_period
+ months=self.get_deprecation_months()
)
- if isinstance(deprecation_date, datetime.datetime):
- deprecation_date = deprecation_date.date()
- return deprecation_date < datetime.date.today()
+ return True if deprecation_date > datetime.date.today() else False
def delete_with_info(self, *args, **kwargs):
"""
View
5 src/ralph_assets/tests/unit/tests_models.py
@@ -19,16 +19,19 @@ def setUp(self):
sn='1111-1111-1111-1111',
invoice_date='2012-11-28',
support_period=1,
+ deprecation_rate=1.00,
)
self.asset2 = create_asset(
sn='1111-1111-1111-1112',
invoice_date='2012-11-28',
support_period=120,
+ deprecation_rate=0.50,
)
def test_is_deperecation(self):
+ self.assertEqual(self.asset.get_deprecation_months(), 12)
+ self.assertEqual(self.asset2.get_deprecation_months(), 24)
self.assertEqual(self.asset.is_deprecated(), True)
- self.assertEqual(self.asset2.is_deprecated(), False)
class TestApiAssets(TestCase):

0 comments on commit 8daf4b6

Please sign in to comment.