#238 Fix
* adds casting from Decimal() to primitive float for proper calculation
This commit is contained in:
parent
c2fc210868
commit
4138b056df
@ -1,5 +1,5 @@
|
||||
{
|
||||
"eco_account": "CHANGE_BEFORE_RUN!!!",
|
||||
"surface": 500.0,
|
||||
"surface": 500.50,
|
||||
"intervention": "CHANGE_BEFORE_RUN!!!"
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"eco_account": "CHANGE_BEFORE_RUN!!!",
|
||||
"surface": 523400.0,
|
||||
"surface": 523400.50,
|
||||
"intervention": "CHANGE_BEFORE_RUN!!!"
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user