From 2c493d33dc43c814a78a5c8ae2b8dc1a43cb2faf Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 18 Nov 2022 07:40:35 +0100 Subject: [PATCH 1/3] Egon Payment compatibility * EGON expects the payment amount to be a localized string instead of float * adds transformation for this --- intervention/utils/egon_export.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/intervention/utils/egon_export.py b/intervention/utils/egon_export.py index 14ea6b6..0b979a1 100644 --- a/intervention/utils/egon_export.py +++ b/intervention/utils/egon_export.py @@ -11,6 +11,7 @@ import json import pika import xmltodict from django.db.models import Sum +from django.utils import formats from intervention.settings import EGON_RABBITMQ_HOST, EGON_RABBITMQ_USER, EGON_RABBITMQ_PW, EGON_RABBITMQ_PORT from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT @@ -92,6 +93,9 @@ class EgonGmlBuilder: )["summed"] return all_payments + def _float_to_localized_string(self, value: float): + return formats.number_format(value, use_l10n=True, decimal_pos=2) + def _gen_kompensationsArt(self) -> (str, int): comp_type = "Ersatzzahlung" comp_type_code = 774898901 @@ -191,7 +195,7 @@ class EgonGmlBuilder: "@xlink:href": f"http://register.naturschutz.rlp.de/repository/services/referenzliste/1053/{reg_office.atom_id if reg_office else None}", "#text": reg_office.long_name if reg_office else None }, - "oneo:ersatzzahlung": self._sum_all_payments(), + "oneo:ersatzzahlung": self._float_to_localized_string(self._sum_all_payments()), "oneo:kompensationsart": { "@xlink:href": f"http://register.naturschutz.rlp.de/repository/services/referenzliste/88140/{comp_type_code}", "#text": comp_type From 4138b056dfb0591e4f2dc966a8c70c20378f60af Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 18 Nov 2022 13:24:36 +0100 Subject: [PATCH 2/3] #238 Fix * adds casting from Decimal() to primitive float for proper calculation --- api/tests/v1/create/deduction_create_post_body.json | 2 +- api/tests/v1/update/deduction_update_put_body.json | 2 +- compensation/models/eco_account.py | 11 +++++++++-- compensation/tests/ecoaccount/test_workflow.py | 6 +++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/tests/v1/create/deduction_create_post_body.json b/api/tests/v1/create/deduction_create_post_body.json index b467637..69a1466 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 4968bf1..e8589be 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 48414cc..35e4c02 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 ef65eda..b1c9a8f 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()) From 689f3b6d28104d06b04f86575ad80ee03efb48f7 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 18 Nov 2022 13:28:13 +0100 Subject: [PATCH 3/3] Updates LANIS link * changes LANIS link to new layer declaration --- konova/sub_settings/lanis_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/konova/sub_settings/lanis_settings.py b/konova/sub_settings/lanis_settings.py index ac3610b..ae71866 100644 --- a/konova/sub_settings/lanis_settings.py +++ b/konova/sub_settings/lanis_settings.py @@ -15,7 +15,7 @@ DEFAULT_SRID_RLP = 25832 # Needed to redirect to LANIS ## Values to be inserted are [zoom_level, x_coord, y_coord] -LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_f,eiv_l,eiv_p,kom_f,kom_l,kom_p,oek_f,ema_f,mae&service=kartendienste_naturschutz" +LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_recorded,eiv_unrecorded,kom_recorded,kom_unrecorded,oek_recorded,oek_unrecorded,ema_recorded,ema_unrecorded,mae&service=kartendienste_naturschutz" ## This look up table (LUT) defines different zoom levels on the size of the calculate area of a geometry. LANIS_ZOOM_LUT = { 1000000000: 6,