Merge pull request '#238 Fix' (#239) from 238_Type_error_on_eco_account_edit into master

Reviewed-on: SGD-Nord/konova#239
This commit is contained in:
mpeltriaux 2022-11-18 13:29:11 +01:00
commit 0bc486502f
4 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,5 @@
{
"eco_account": "CHANGE_BEFORE_RUN!!!",
"surface": 500.0,
"surface": 500.50,
"intervention": "CHANGE_BEFORE_RUN!!!"
}

View File

@ -1,5 +1,5 @@
{
"eco_account": "CHANGE_BEFORE_RUN!!!",
"surface": 523400.0,
"surface": 523400.50,
"intervention": "CHANGE_BEFORE_RUN!!!"
}

View File

@ -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

View File

@ -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())