Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add rounding down for credit value in notification email
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Giesler committed Jan 13, 2015
1 parent bcd4727 commit f68d315
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go/billing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def create_transaction_interaction(self, cursor, account_number,
(%(account_number)s, %(message_id)s,
%(tag_pool_name)s, %(tag_name)s,
%(message_direction)s, %(message_cost)s, %(storage_cost)s,
%(session_created)s, %(session_cost)s, %(markup_percent)s,
%(session_created)s, %(session_cost)s, %(markup_percent)s,
%(message_credits)s, %(storage_credits)s, %(session_credits)s,
%(credit_factor)s, %(credit_amount)s,
'Completed', now(),
Expand Down
5 changes: 4 additions & 1 deletion go/billing/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from djcelery_email.tasks import send_email

from math import floor

from go.base.s3utils import Bucket
from go.billing import settings
from go.billing.models import (
Expand Down Expand Up @@ -388,13 +390,14 @@ def create_low_credit_notification(account_number, threshold, balance):
Decimal(100) - threshold_percent)
email_from = settings.LOW_CREDIT_NOTIFICATION_EMAIL
email_to = account.user.email
formatted_balance = str(floor(balance*100)/100)
message = render_to_string(
'billing/low_credit_notification_email.txt',
{
'user': account.user,
'account': account,
'threshold_percent': threshold_percent,
'credit_balance': balance,
'credit_balance': formatted_balance,
'reference': notification.id,
})

Expand Down
4 changes: 2 additions & 2 deletions go/billing/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def test_confirm_sent(self):
self.assertEqual(timestamp, notification.success)

def test_email_sent(self):
notification_id, res = self.mk_notification('0.701', '12.34')
notification_id, res = self.mk_notification('0.701', '12.3475')
notification = LowCreditNotification.objects.get(pk=notification_id)
self.assertTrue(res.get() is not None)
self.assertEqual(len(mail.outbox), 1)
Expand All @@ -643,7 +643,7 @@ def test_email_sent(self):
'70.100'),
email.subject)
self.assertTrue('29.900%' in email.body)
self.assertTrue('12.34' in email.body)
self.assertTrue('12.34.' in email.body)
self.assertTrue(self.django_user.get_full_name() in email.body)
self.assertTrue(str(notification.pk) in email.body)
self.assertTrue(str(self.acc.user.email) in email.body)

0 comments on commit f68d315

Please sign in to comment.