diff --git a/api/tests/v1/create/deduction_create_post_body.json b/api/tests/v1/create/deduction_create_post_body.json index b467637c..69a1466d 100644 --- a/api/tests/v1/create/deduction_create_post_body.json +++ b/api/tests/v1/create/deduction_create_post_body.json @@ -1,5 +1,5 @@ { "eco_account": "CHANGE_BEFORE_RUN!!!", - "surface": 500.0, + "surface": 500.50, "intervention": "CHANGE_BEFORE_RUN!!!" } \ No newline at end of file diff --git a/api/tests/v1/update/deduction_update_put_body.json b/api/tests/v1/update/deduction_update_put_body.json index 4968bf19..e8589be2 100644 --- a/api/tests/v1/update/deduction_update_put_body.json +++ b/api/tests/v1/update/deduction_update_put_body.json @@ -1,5 +1,5 @@ { "eco_account": "CHANGE_BEFORE_RUN!!!", - "surface": 523400.0, + "surface": 523400.50, "intervention": "CHANGE_BEFORE_RUN!!!" } \ No newline at end of file diff --git a/compensation/models/eco_account.py b/compensation/models/eco_account.py index 48414cca..35e4c02b 100644 --- a/compensation/models/eco_account.py +++ b/compensation/models/eco_account.py @@ -118,8 +118,15 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix intervention__deleted=None, ) deductions_surfaces = deductions.aggregate(Sum("surface"))["surface__sum"] or 0 - available_surfaces = self.deductable_surface or deductions_surfaces ## no division by zero - ret_val = available_surfaces - deductions_surfaces + + available_surface = self.deductable_surface + if available_surface is None: + # Fallback! + available_surface = deductions_surfaces + else: + available_surface = float(available_surface) + + ret_val = available_surface - deductions_surfaces return ret_val diff --git a/compensation/tests/ecoaccount/test_workflow.py b/compensation/tests/ecoaccount/test_workflow.py index ef65edaa..b1c9a8f4 100644 --- a/compensation/tests/ecoaccount/test_workflow.py +++ b/compensation/tests/ecoaccount/test_workflow.py @@ -188,7 +188,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase): # Prepare data for deduction creation deduct_url = reverse("compensation:acc:new-deduction", args=(self.eco_account.id,)) - test_surface = 10.00 + test_surface = 10.50 post_data = { "surface": test_surface, "account": self.eco_account.id, @@ -207,7 +207,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase): # Make sure the deductible surface is valid for the request self.eco_account.set_recorded(self.superuser) self.eco_account.refresh_from_db() - self.eco_account.deductable_surface = test_surface + 1.00 + self.eco_account.deductable_surface = test_surface + 1.0 self.eco_account.save() self.assertIsNotNone(self.eco_account.recorded) self.assertGreater(self.eco_account.deductable_surface, test_surface) @@ -244,7 +244,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase): deduction = EcoAccountDeduction.objects.create( intervention=self.intervention, account=self.eco_account, - surface=0 + surface=1.10 ) self.assertEqual(1, self.intervention.deductions.count()) self.assertEqual(1, self.eco_account.deductions.count())