Skip to content

Commit

Permalink
Update two fields in the Budget model to accept Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
jefmoura committed Mar 6, 2018
1 parent 22deef6 commit 6d9c8c9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
29 changes: 19 additions & 10 deletions feed/tests/test_budgetview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

from django.test import TestCase
from rest_framework.test import APIRequestFactory
from rest_framework.reverse import reverse
Expand Down Expand Up @@ -76,9 +78,10 @@ def test_create_budget(self):
response = view(request)

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['proposed_value'],
self.assertEqual(Decimal(response.data['proposed_value']),
data['proposed_value'])
self.assertEqual(response.data['actual_value'], data['actual_value'])
self.assertEqual(Decimal(response.data['actual_value']),
data['actual_value'])
self.assertEqual(response.data['created_by'], user_url)

# Check WorkflowLevel2
Expand All @@ -101,9 +104,10 @@ def test_create_budget_without_wkfl2(self):
response = view(request)

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['proposed_value'],
self.assertEqual(Decimal(response.data['proposed_value']),
data['proposed_value'])
self.assertEqual(response.data['actual_value'], data['actual_value'])
self.assertEqual(Decimal(response.data['actual_value']),
data['actual_value'])
self.assertEqual(response.data['created_by'], user_url)


Expand All @@ -129,8 +133,10 @@ def test_update_budget(self):

budget = Budget.objects.get(pk=response.data['id'])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['proposed_value'], budget.proposed_value)
self.assertEqual(response.data['actual_value'], budget.actual_value)
self.assertEqual(Decimal(response.data['proposed_value']),
budget.proposed_value)
self.assertEqual(Decimal(response.data['actual_value']),
budget.actual_value)

# Check WorkflowLevel2
wkfl2 = budget.workflowlevel2
Expand All @@ -154,8 +160,9 @@ def test_update_budget_without_actual_value(self):

budget = Budget.objects.get(pk=response.data['id'])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['proposed_value'], budget.proposed_value)
self.assertEqual(response.data['actual_value'], 0)
self.assertEqual(Decimal(response.data['proposed_value']),
budget.proposed_value)
self.assertEqual(Decimal(response.data['actual_value']), 0)

# Check WorkflowLevel2
wkfl2 = budget.workflowlevel2
Expand All @@ -174,8 +181,10 @@ def test_update_budget_without_wkfl2(self):

budget = Budget.objects.get(pk=response.data['id'])
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['proposed_value'], budget.proposed_value)
self.assertEqual(response.data['actual_value'], budget.actual_value)
self.assertEqual(Decimal(response.data['proposed_value']),
budget.proposed_value)
self.assertEqual(Decimal(response.data['actual_value']),
budget.actual_value)


class BudgetFilterViewTest(TestCase):
Expand Down
36 changes: 36 additions & 0 deletions workflow/migrations/0018_auto_20180302_0814.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-03-02 16:14
from __future__ import unicode_literals

from decimal import Decimal
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workflow', '0017_auto_20180226_0031'),
]

operations = [
migrations.AlterField(
model_name='budget',
name='actual_value',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), help_text='Monetary value positive or negative', max_digits=12, verbose_name='Actual'),
),
migrations.AlterField(
model_name='budget',
name='proposed_value',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), help_text='Approximate value if not a monetary fund', max_digits=12, verbose_name='Budget'),
),
migrations.AlterField(
model_name='historicalbudget',
name='actual_value',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), help_text='Monetary value positive or negative', max_digits=12, verbose_name='Actual'),
),
migrations.AlterField(
model_name='historicalbudget',
name='proposed_value',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), help_text='Approximate value if not a monetary fund', max_digits=12, verbose_name='Budget'),
),
]
8 changes: 4 additions & 4 deletions workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,8 @@ class Budget(models.Model):
cost_center = models.CharField("Cost Center", max_length=135, blank=True, null=True, help_text="Associate a cost with a type of expense")
donor_code = models.CharField("Donor Code", max_length=135, blank=True, null=True, help_text="Third Party coded field")
description_of_contribution = models.CharField(max_length=255, blank=True, null=True, help_text="Purpose or use for funds")
proposed_value = models.IntegerField("Budget", default=0, blank=True, null=True, help_text="Approximate value if not a monetary fund")
actual_value = models.IntegerField("Actual", default=0, blank=True, null=True, help_text="Monetary value positive or negative")
proposed_value = models.DecimalField("Budget", decimal_places=2, max_digits=12, default=Decimal("0.00"), blank=True, help_text="Approximate value if not a monetary fund")
actual_value = models.DecimalField("Actual", decimal_places=2, max_digits=12, default=Decimal("0.00"), blank=True, help_text="Monetary value positive or negative")
workflowlevel2 = models.ForeignKey(WorkflowLevel2, blank=True, null=True, on_delete=models.SET_NULL, help_text="Releated workflow level 2")
local_currency = models.ForeignKey(Currency, blank=True, null=True, related_name="local", help_text="Primary Currency")
donor_currency = models.ForeignKey(Currency, blank=True, null=True, related_name="donor", help_text="Secondary Currency")
Expand All @@ -1361,9 +1361,9 @@ def save(self, *args, **kwargs):
self.edit_date = timezone.now()

if self.proposed_value is None:
self.proposed_value = 0
self.proposed_value = Decimal("0.00")
if self.actual_value is None:
self.actual_value = 0
self.actual_value = Decimal("0.00")

if self.workflowlevel2:
wflvl2 = self.workflowlevel2
Expand Down

0 comments on commit 6d9c8c9

Please sign in to comment.