diff --git a/feed/tests/test_budgetview.py b/feed/tests/test_budgetview.py index 74f960fb5..1e26c69d0 100644 --- a/feed/tests/test_budgetview.py +++ b/feed/tests/test_budgetview.py @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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): diff --git a/workflow/migrations/0018_auto_20180302_0814.py b/workflow/migrations/0018_auto_20180302_0814.py new file mode 100644 index 000000000..91c7c6559 --- /dev/null +++ b/workflow/migrations/0018_auto_20180302_0814.py @@ -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'), + ), + ] diff --git a/workflow/models.py b/workflow/models.py index 6961dd9c6..f2b84e156 100755 --- a/workflow/models.py +++ b/workflow/models.py @@ -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") @@ -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