From d83026c91bd290ade52dbc1fe9558e3a2e8b8e25 Mon Sep 17 00:00:00 2001 From: Anish Kr Singh <116036738+anishfyle@users.noreply.github.com> Date: Tue, 14 May 2024 17:04:00 +0530 Subject: [PATCH] Add boolean support, migrations and fixtures (#610) --- apps/fyle/helpers.py | 3 +++ ...35_alter_expensefilter_custom_field_type.py | 18 ++++++++++++++++++ apps/fyle/models.py | 2 +- .../reset_db_fixtures/reset_db.sql | 5 +++-- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 apps/fyle/migrations/0035_alter_expensefilter_custom_field_type.py diff --git a/apps/fyle/helpers.py b/apps/fyle/helpers.py index 54e8f530..ed63f663 100644 --- a/apps/fyle/helpers.py +++ b/apps/fyle/helpers.py @@ -133,6 +133,9 @@ def construct_expense_filter(expense_filter): # If the custom field is of type NUMBER, convert the values to integers if expense_filter.custom_field_type == 'NUMBER': expense_filter.values = [int(value) for value in expense_filter.values] + # If the expense filter is a custom field and the operator is yes or no(checkbox) + if expense_filter.custom_field_type == 'BOOLEAN': + expense_filter.values[0] = True if expense_filter.values[0] == 'true' else False # Construct the filter for the custom property filter1 = {f'custom_properties__{expense_filter.condition}__{expense_filter.operator}': expense_filter.values[0] if len(expense_filter.values) == 1 and expense_filter.operator != 'in' else expense_filter.values} # Assign the constructed filter to the constructed expense filter diff --git a/apps/fyle/migrations/0035_alter_expensefilter_custom_field_type.py b/apps/fyle/migrations/0035_alter_expensefilter_custom_field_type.py new file mode 100644 index 00000000..7ccb7ba5 --- /dev/null +++ b/apps/fyle/migrations/0035_alter_expensefilter_custom_field_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-05-14 11:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0034_expense_previous_export_state'), + ] + + operations = [ + migrations.AlterField( + model_name='expensefilter', + name='custom_field_type', + field=models.CharField(choices=[('SELECT', 'SELECT'), ('NUMBER', 'NUMBER'), ('TEXT', 'TEXT'), ('BOOLEAN', 'BOOLEAN')], help_text='Custom field type', max_length=255, null=True), + ), + ] diff --git a/apps/fyle/models.py b/apps/fyle/models.py index e8b77690..f1d106f0 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -28,7 +28,7 @@ EXPENSE_FILTER_JOIN_BY = (('AND', 'AND'), ('OR', 'OR')) -EXPENSE_FILTER_CUSTOM_FIELD_TYPE = (('SELECT', 'SELECT'), ('NUMBER', 'NUMBER'), ('TEXT', 'TEXT')) +EXPENSE_FILTER_CUSTOM_FIELD_TYPE = (('SELECT', 'SELECT'), ('NUMBER', 'NUMBER'), ('TEXT', 'TEXT'), ('BOOLEAN', 'BOOLEAN')) EXPENSE_FILTER_OPERATOR = (('isnull', 'isnull'), ('in', 'in'), ('iexact', 'iexact'), ('icontains', 'icontains'), ('lt', 'lt'), ('lte', 'lte'), ('not_in', 'not_in')) diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index cf0879de..3dce6712 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 15.6 (Debian 15.6-1.pgdg120+2) --- Dumped by pg_dump version 15.6 (Debian 15.6-1.pgdg120+2) +-- Dumped by pg_dump version 15.7 (Debian 15.7-1.pgdg120+1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -4029,6 +4029,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 179 fyle_accounting_mappings 0024_auto_20230922_0819 2024-05-07 08:25:50.966444+00 180 fyle_accounting_mappings 0025_expenseattributesdeletioncache 2024-05-07 08:25:51.005092+00 181 tasks 0011_error_repetition_count 2024-05-07 08:25:51.025747+00 +182 fyle 0035_alter_expensefilter_custom_field_type 2024-05-14 11:12:11.084476+00 \. @@ -33957,7 +33958,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 181, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 182, true); --