diff --git a/src/documents/migrations/1054_customfieldinstance_value_monetary_amount_and_more.py b/src/documents/migrations/1054_customfieldinstance_value_monetary_amount_and_more.py index 37d1aaeab..0bc135646 100644 --- a/src/documents/migrations/1054_customfieldinstance_value_monetary_amount_and_more.py +++ b/src/documents/migrations/1054_customfieldinstance_value_monetary_amount_and_more.py @@ -1,5 +1,6 @@ -# Generated by Django 5.1.1 on 2024-09-29 05:16 +# Generated by Django 5.1.1 on 2024-09-29 16:13 +import django.db.models.functions.comparison import django.db.models.functions.text from django.db import migrations from django.db import models @@ -18,13 +19,22 @@ class Migration(migrations.Migration): db_persist=True, expression=models.Case( models.When( - then=django.db.models.functions.text.Substr( - "value_monetary", - 1, + then=django.db.models.functions.comparison.Cast( + django.db.models.functions.text.Substr("value_monetary", 1), + output_field=models.DecimalField( + decimal_places=2, + max_digits=125, + ), ), value_monetary__regex="^\\d+", ), - default=django.db.models.functions.text.Substr("value_monetary", 4), + default=django.db.models.functions.comparison.Cast( + django.db.models.functions.text.Substr("value_monetary", 4), + output_field=models.DecimalField( + decimal_places=2, + max_digits=125, + ), + ), output_field=models.DecimalField(decimal_places=2, max_digits=125), ), output_field=models.DecimalField(decimal_places=2, max_digits=125), diff --git a/src/documents/models.py b/src/documents/models.py index 51c19c83e..e10de523d 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -23,6 +23,7 @@ if settings.AUDIT_LOG_ENABLED: from auditlog.registry import auditlog from django.db.models import Case +from django.db.models.functions import Cast from django.db.models.functions import Substr from django_softdelete.models import SoftDeleteModel @@ -929,10 +930,16 @@ class CustomFieldInstance(models.Model): # If the value starts with a number and no currency symbol, use the whole string models.When( value_monetary__regex=r"^\d+", - then=Substr("value_monetary", 1), + then=Cast( + Substr("value_monetary", 1), + output_field=models.DecimalField(decimal_places=2, max_digits=125), + ), ), # If the value starts with a 3-char currency symbol, use the rest of the string - default=Substr("value_monetary", 4), + default=Cast( + Substr("value_monetary", 4), + output_field=models.DecimalField(decimal_places=2, max_digits=125), + ), output_field=models.DecimalField(decimal_places=2, max_digits=125), ), output_field=models.DecimalField(decimal_places=2, max_digits=125),