Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make db changes and fixture updates to support split expenses #671

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Nov 18, 2024

Clickup

https://app.clickup.com/t/86cx0vh5m

Summary by CodeRabbit

  • New Features

    • Introduced bank_transaction_id for tracking bank transactions in expenses.
    • Added split_expense_grouping to enhance expense grouping options.
  • Bug Fixes

    • Updated database schema to accommodate new fields in expense-related tables.
  • Tests

    • Enhanced test fixtures to include new fields for improved testing accuracy.

Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

This pull request introduces new fields to the Expense and ExpenseGroupSettings models in a Django application. Specifically, it adds a bank_transaction_id field to the Expense model and a split_expense_grouping field to the ExpenseGroupSettings model. Additionally, the migration file updates the database schema to reflect these changes, and various test fixtures are modified to include these new fields. The changes ensure that the application can track bank transactions and manage expense grouping more effectively.

Changes

File Change Summary
apps/fyle/migrations/0035_support_split_expense_grouping.py Added bank_transaction_id to expense model and split_expense_grouping to expensegroupsettings model. Established migration dependency.
apps/fyle/models.py Added constant SPLIT_EXPENSE_GROUPING, bank_transaction_id field to Expense, and split_expense_grouping field to ExpenseGroupSettings. Introduced get_default_split_expense_grouping method.
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Modified expense_group_settings and expenses tables to include new columns split_expense_grouping and bank_transaction_id. Updated data copy commands.
tests/test_fyle/fixtures.py Added bank_transaction_id to multiple expense entries and introduced split_expense_grouping with value "MULTIPLE_LINE_ITEM" in two entries.
tests/test_workspaces/test_apis/test_export_settings/fixtures.py Added split_expense_grouping with value 'MULTIPLE_LINE_ITEM' to multiple sections in export settings.

Possibly related PRs

  • fix: expense group creation #653: This PR focuses on the creation of expense groups, which is directly related to the changes made in the main PR that introduces new fields in the Expense and ExpenseGroupSettings models.
  • feat: handle posted at #661: This PR adds a new field is_posted_at_null to the Expense model, which is relevant to the changes in the main PR that also modifies the Expense model by adding new fields.

Suggested labels

size/L

Suggested reviewers

  • ruuushhh

Poem

🐇 In the meadow where expenses bloom,
New fields sprout, dispelling gloom.
Bank IDs and groupings, all in line,
Tracking our spending, oh so fine!
With every change, our hopes take flight,
For better records, we hop with delight! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Tests Skipped Failures Errors Time
227 0 💤 4 ❌ 0 🔥 25.852s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (1)

11637-11645: Update test data for bank_transaction_id

All expense records have bank_transaction_id = NULL. If this field is meant to track bank transactions:

  1. Consider adding test cases with non-NULL values
  2. Document the scenarios where this field should/shouldn't be populated
  3. Ensure test coverage for both cases
tests/test_fyle/fixtures.py (1)

249-249: Consider using unique bank_transaction_ids for different expenses

Currently, all expenses use the same bank_transaction_id: 'btxnqmATEEBkJ4'. This might not adequately test scenarios where unique transaction IDs are important. Consider using distinct IDs to better represent real-world data and catch potential issues with transaction tracking or grouping.

-            'bank_transaction_id': 'btxnqmATEEBkJ4',
+            'bank_transaction_id': 'btxnqmATEEBkJ4_1234',

And similar unique suffixes for other expenses.

Also applies to: 290-290, 331-331, 859-859, 901-901

apps/fyle/models.py (2)

213-215: Add docstring for consistency.

Consider adding a docstring to maintain consistency with other default value functions in the file.

 def get_default_split_expense_grouping():
+    """
+    Returns the default value for split expense grouping
+    :return: str
+    """
     return 'MULTIPLE_LINE_ITEM'

241-245: Fix indentation for consistency.

The indentation of the field definition is inconsistent with other fields in the model.

-    split_expense_grouping = models.CharField(
-        max_length=100,
-        default=get_default_split_expense_grouping,
-        choices=SPLIT_EXPENSE_GROUPING, help_text='specify line items for split expenses grouping'
-    )
+    split_expense_grouping = models.CharField(
+        max_length=100,
+        default=get_default_split_expense_grouping,
+        choices=SPLIT_EXPENSE_GROUPING,
+        help_text='specify line items for split expenses grouping'
+    )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 065f8bc and a41a418.

📒 Files selected for processing (5)
  • apps/fyle/migrations/0035_support_split_expense_grouping.py (1 hunks)
  • apps/fyle/models.py (6 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (7 hunks)
  • tests/test_fyle/fixtures.py (7 hunks)
  • tests/test_workspaces/test_apis/test_export_settings/fixtures.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/fyle/migrations/0035_support_split_expense_grouping.py
🔇 Additional comments (11)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (4)

962-963: ⚠️ Potential issue

Review NOT NULL constraint implementation

The new split_expense_grouping column is marked as NOT NULL but:

  1. There's no DEFAULT value specified
  2. No CHECK constraint to validate allowed values
  3. Existing records would need a value during migration

Consider:

  1. Adding a DEFAULT value
  2. Adding a CHECK constraint to validate values
  3. Documenting the migration strategy for existing records
#!/bin/bash
# Check if migration handles existing records
fd -t f -e py . -E "*.pyc" | xargs rg -A 10 "split_expense_grouping"

# Look for enum/choices definition
fd -t f -e py . -E "*.pyc" | xargs rg "class.*ExpenseGroupSettings|SPLIT_EXPENSE_GROUPING"

1153-1154: Consider indexing bank_transaction_id

The bank_transaction_id column might benefit from an index if it's used for lookups or as a foreign key. Also, consider:

  1. Adding a unique constraint if this ID should be unique
  2. Adding a foreign key constraint if it references another table
  3. Documenting the nullability requirements as all sample data shows NULL values
#!/bin/bash
# Check if bank_transaction_id is used in queries
fd -t f -e py . -E "*.pyc" | xargs rg "bank_transaction_id"

# Look for related models/tables
fd -t f -e sql . | xargs rg "bank.*transaction"

11582-11585: Verify data migration strategy

All expense_group_settings records use 'MULTIPLE_LINE_ITEM' for split_expense_grouping. Consider:

  1. Documenting if this is the intended default value
  2. Verifying if other values are supported
  3. Updating test data to cover different scenarios if multiple values are supported
#!/bin/bash
# Look for other possible values in code
fd -t f -e py . -E "*.pyc" | xargs rg "MULTIPLE_LINE_ITEM|split_expense_grouping.*=|split_expense_grouping.*choices"

5-5: Verify PostgreSQL version downgrade compatibility

The PostgreSQL version has been downgraded from 15.9 to 15.7. While both versions are from the same major release (15.x), ensure this matches your development and production environments to avoid potential compatibility issues.

✅ Verification successful

PostgreSQL version change appears safe to proceed

The version change from 15.9 to 15.7 is a minor version downgrade within the same major version (15.x). After analyzing the codebase:

  • No specific PostgreSQL version requirements are documented
  • No version-specific PostgreSQL features are being used
  • Both versions are recent and part of the same major release, maintaining backward compatibility
  • The change is only in test fixtures, not affecting production environments
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if README or documentation specifies required PostgreSQL version
fd -t f -e md . | xargs rg -i "postgres(ql)?\s*(version|requirement)"

# Check if there are any version-specific PostgreSQL features in use
rg -i '\-\-\s*Requires PostgreSQL' 

Length of output: 5094


Script:

#!/bin/bash
# Check for PostgreSQL version in Docker files or configuration
fd -t f "Dockerfile|docker-compose.*\.yml|\.env.*" | xargs rg -i "postgres(ql)?\s*:\s*\d+\.\d+"

# Check for any database configuration files
fd -t f -e py . | xargs rg -i "postgres(ql)?\s*:\s*\d+\.\d+"

# Check for any version-specific PostgreSQL features in SQL files
fd -t f -e sql . | xargs rg -i "requires\s+postgres(ql)?\s*>\s*\d+\.\d+"

Length of output: 235

tests/test_fyle/fixtures.py (2)

1000-1001: Verify all possible values for split_expense_grouping

The addition of "split_expense_grouping": "MULTIPLE_LINE_ITEM" suggests this is a choice field. Let's verify all possible values to ensure test coverage.

#!/bin/bash
# Search for the model definition and any choices/enums for split_expense_grouping
ast-grep --pattern 'class ExpenseGroupSettings:
  $$$
  split_expense_grouping = $$$
  $$$'

# Also check for any migrations defining choices
rg -l "split_expense_grouping.*choices" --type py

1105-1106: Verify expense state configurations for all expense types

The changes add both ccc_expense_state and split_expense_grouping configurations. Let's ensure all expense types and states are properly configured.

tests/test_workspaces/test_apis/test_export_settings/fixtures.py (2)

78-79: LGTM! Response matches request payload.

The split_expense_grouping field in the response correctly mirrors the configuration from the request payload, maintaining consistency.


29-30: Consider adding test cases for different split expense grouping values.

While the current test case covers the 'MULTIPLE_LINE_ITEM' scenario, it would be beneficial to add test cases that validate the behavior with different possible values of split_expense_grouping.

apps/fyle/models.py (3)

75-76: LGTM! Well-structured choices constant.

The SPLIT_EXPENSE_GROUPING constant follows Django's choice field convention and provides clear, self-documenting options.


108-108: LGTM! Well-defined field for bank transaction tracking.

The bank_transaction_id field follows Django model field best practices with appropriate nullability and length constraints.


325-326: Verify split_expense_grouping value validation.

The update_expense_group_settings method accepts the new field but doesn't explicitly validate that the value matches the choices. While Django's model field will handle this, consider adding explicit validation for better error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants