diff --git a/apps/fyle/migrations/0043_expensegroup_eg_ws_fund_null_idx.py b/apps/fyle/migrations/0043_expensegroup_eg_ws_fund_null_idx.py new file mode 100644 index 00000000..d8453b3e --- /dev/null +++ b/apps/fyle/migrations/0043_expensegroup_eg_ws_fund_null_idx.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.28 on 2026-02-12 08:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0042_expense_expenses_workspa_ad984e_idx'), + ] + + operations = [ + migrations.AddIndex( + model_name='expensegroup', + index=models.Index(condition=models.Q(('exported_at__isnull', True)), fields=['workspace_id', 'fund_source'], name='eg_ws_fund_null_idx'), + ), + ] diff --git a/apps/fyle/models.py b/apps/fyle/models.py index b032bde7..ad7d02b9 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -4,7 +4,7 @@ from django.contrib.postgres.aggregates import ArrayAgg from django.contrib.postgres.fields import ArrayField from django.db import models -from django.db.models import Count, JSONField +from django.db.models import Count, JSONField, Q from django.db.models.fields.json import KeyTextTransform from fyle_accounting_library.fyle_platform.constants import IMPORTED_FROM_CHOICES from fyle_accounting_library.fyle_platform.enums import ExpenseImportSourceEnum @@ -12,9 +12,15 @@ from fyle_accounting_mappings.models import ExpenseAttribute from apps.users.models import User +from apps.workspaces.enums import ( + ExportTypeEnum, + SystemCommentEntityTypeEnum, + SystemCommentIntentEnum, + SystemCommentReasonEnum, + SystemCommentSourceEnum, +) from apps.workspaces.models import Configuration, Workspace from apps.workspaces.system_comments import add_system_comment -from apps.workspaces.enums import ExportTypeEnum, SystemCommentEntityTypeEnum, SystemCommentIntentEnum, SystemCommentReasonEnum, SystemCommentSourceEnum ALLOWED_FIELDS = [ 'employee_email', 'report_id', 'claim_number', 'settlement_id', @@ -490,6 +496,13 @@ class ExpenseGroup(models.Model): class Meta: db_table = 'expense_groups' + indexes = [ + models.Index( + fields=['workspace_id', 'fund_source'], + condition=Q(exported_at__isnull=True), + name='eg_ws_fund_null_idx', + ), + ] @staticmethod def create_expense_groups_by_report_id_fund_source(expense_objects: list[Expense], configuration: Configuration, workspace_id: int, system_comments: list = None) -> None: diff --git a/apps/internal/migrations/0001_auto_generated_sql.py b/apps/internal/migrations/0001_auto_generated_sql.py index a9329774..bec4a2b5 100644 --- a/apps/internal/migrations/0001_auto_generated_sql.py +++ b/apps/internal/migrations/0001_auto_generated_sql.py @@ -57,8 +57,8 @@ class Migration(migrations.Migration): ('fyle', '0036_auto_20250108_0702'), ('users', '0002_auto_20201228_0802'), ('mappings', '0016_auto_20250108_0702'), - ('tasks', '0010_alter_tasklog_expense_group'), - ('workspaces','0043_configuration_skip_accounting_export_summary_post'), + ('tasks', '0016_tasklog_is_attachment_upload_failed'), + ('workspaces','0060_workspace_org_settings'), ('sage_intacct', '0030_auto_20241112_0425'), ] # This is the first migration operations = safe_run_sql(sql_files)