Skip to content

Commit

Permalink
✨ [#326] -- correctly handle currency/Decimal types
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Dec 27, 2021
1 parent 221bf56 commit 67df43a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/openforms/registrations/contrib/camunda/apps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from decimal import Decimal

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _

from django_camunda.utils import TYPE_MAP as CAMUNDA_TYPE_MAP


class CamundaApp(AppConfig):
name = "openforms.registrations.contrib.camunda"
label = "registrations_camunda"
verbose_name = _("Camunda registration plugin")

def ready(self):
patch_django_camunda()

# register plugin
from . import plugin # noqa


def patch_django_camunda():
CAMUNDA_TYPE_MAP[Decimal] = ("Double", lambda val: str(val))
2 changes: 1 addition & 1 deletion src/openforms/registrations/contrib/camunda/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_process_variables(
# dict of {componentKey: camundaProcesVar} mapping
simple_mappings = dict(
[
(key := process_var["componentKey"], process_var.get("alias") or key)
(key := process_var["component_key"], process_var.get("alias") or key)
for process_var in process_variables
if process_var.get("enabled")
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from decimal import Decimal
from unittest.mock import patch

from django.test import TestCase
Expand Down Expand Up @@ -276,12 +277,12 @@ def test_submission_with_mapped_variables(self, m, mock_start_process):
"process_variables": [
{
"enabled": True,
"componentKey": "currency",
"component_key": "currency",
"alias": "amount",
},
{
"enabled": True,
"componentKey": "invoiceCategory",
"component_key": "invoiceCategory",
"alias": "",
},
],
Expand All @@ -294,7 +295,7 @@ def test_submission_with_mapped_variables(self, m, mock_start_process):
process_key="invoice",
variables=serialize_variables(
{
"amount": "25.00",
"amount": Decimal("25.00"),
"invoiceCategory": "Misc",
}
),
Expand Down
2 changes: 2 additions & 0 deletions src/openforms/registrations/contrib/camunda/type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
The work in #1068 should eventually make this module obsolete.
"""
from decimal import Decimal
from typing import Any, Dict, List

from dateutil import parser
Expand Down Expand Up @@ -60,6 +61,7 @@ def selectboxes(component, value) -> List[str]:
"map": noop, # list of coordinates (lng, lat) in float format
"password": to_str,
"licenseplate": to_str,
"currency": lambda c, value: Decimal(str(value)),
}


Expand Down

0 comments on commit 67df43a

Please sign in to comment.