Skip to content

Commit

Permalink
Add boolean support, migrations and fixtures (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle authored May 14, 2024
1 parent ac60bda commit d83026c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/fyle/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions apps/fyle/migrations/0035_alter_expensefilter_custom_field_type.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 1 addition & 1 deletion apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
5 changes: 3 additions & 2 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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);


--
Expand Down

0 comments on commit d83026c

Please sign in to comment.