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: handle posted at #661

Merged
merged 4 commits into from
Nov 18, 2024
Merged

feat: handle posted at #661

merged 4 commits into from
Nov 18, 2024

Conversation

anishfyle
Copy link
Contributor

@anishfyle anishfyle commented Nov 11, 2024

Description

  • Handle posted at, added flag to check if posted at is null or not, if it is null then we get spent at value in posted at

Clickup

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

Summary by CodeRabbit

  • New Features
    • Introduced a new flag, is_posted_at_null, in the Expense model to indicate if the posted_at field is null, enhancing tracking capabilities.
    • Updated the SQL database schema to include the new is_posted_at_null column in the expenses table.
    • Changed the default value of the change_accounting_period field in the Configuration model to True, indicating that the accounting period will now change by default.
  • Bug Fixes
    • Modified the test fixture to clear existing TaskLog entries before creating new ones, preventing potential conflicts.

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes introduce a new Boolean field named is_posted_at_null to the Expense model within the apps/fyle/models.py file. This field acts as a flag to indicate whether the posted_at field is null, with a default value set to False and a help text for clarification. Additionally, a migration file is created to implement this change in the database schema. Updates to the SQL database dump reflect the new field and other schema modifications, while a test fixture is adjusted to clear previous TaskLog entries for consistency.

Changes

File Change Summary
apps/fyle/models.py Added a new Boolean field is_posted_at_null to the Expense model to indicate if posted_at is null.
apps/fyle/migrations/0034_expense_is_posted_at_null.py Created a migration to add the is_posted_at_null field to the expense model in the database.
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Added is_posted_at_null column to public.expenses, updated sequence value, and added constraints to public.task_logs.
tests/test_netsuite/conftest.py Modified create_expense_report fixture to clear existing TaskLog entries for a specific expense_group_id.
apps/workspaces/models.py Modified change_accounting_period field in Configuration model to be a BooleanField with default True.
apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py Created a migration to change change_accounting_period field to BooleanField with default True.
requirements.txt Updated version of fyle-integrations-platform-connector from 1.38.4 to 1.39.3.

Possibly related PRs

  • feat: Single credit line for Journal Entry #655: The changes in this PR involve modifications to the Expense model in apps/fyle/models.py, which is directly related to the addition of the is_posted_at_null field in the same model in the main PR.
  • feat: auto enable accounting period #668: This PR also modifies the Configuration model in apps/workspaces/models.py, which is relevant as it shares the same file structure and context of model changes, although it does not directly relate to the Expense model.

Suggested reviewers

  • ruuushhh
  • ashwin1111

Poem

In the garden where expenses bloom,
A flag was added to clear the gloom.
With is_posted_at_null, we now can see,
If posted_at is empty, as clear as can be!
Hopping along, we celebrate this feat,
A model more robust, oh, what a treat! 🐇✨

Warning

Rate limit exceeded

@anishfyle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 635af45 and a66578c.


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.

@github-actions github-actions bot added the size/XS Extra Small PR label Nov 11, 2024
Copy link

Tests Skipped Failures Errors Time
224 0 💤 69 ❌ 17 🔥 38.752s ⏱️

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: 2

🧹 Outside diff range and nitpick comments (1)
apps/fyle/models.py (1)

110-110: Consider enhancing the field definition for better performance and clarity.

The field placement and type are appropriate, but consider these improvements:

  1. Add db_index for better query performance since this field will likely be used in filters
  2. Enhance the help text to be more descriptive about when and why this flag is set
-    is_posted_at_null = models.BooleanField(default=False, help_text='Flag check if posted at is null or not')
+    is_posted_at_null = models.BooleanField(
+        default=False,
+        db_index=True,
+        help_text='Flag indicating if posted_at is null and spent_at should be used instead'
+    )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 96c13db and fa42ac8.

📒 Files selected for processing (1)
  • apps/fyle/models.py (1 hunks)

apps/fyle/models.py Show resolved Hide resolved
apps/fyle/models.py Show resolved Hide resolved
Copy link

Tests Skipped Failures Errors Time
224 0 💤 69 ❌ 17 🔥 36.902s ⏱️

@github-actions github-actions bot added size/M Medium PR and removed size/XS Extra Small PR labels Nov 17, 2024
Copy link

Tests Skipped Failures Errors Time
224 0 💤 0 ❌ 0 🔥 25.996s ⏱️

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 (3)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (1)

12727-12734: Clarify inclusion of task_logs constraints

The addition of unique and foreign key constraints to task_logs table appears unrelated to the PR's objective of handling posted_at. While these are good database practices, please clarify:

  1. Why these constraints are included in this PR
  2. Impact assessment on existing data
  3. Whether this should be in a separate PR

Also applies to: 13773-13780

tests/test_netsuite/conftest.py (2)

65-67: Consider improving test isolation approach.

While clearing TaskLogs helps with test isolation, consider these improvements:

  1. Use the expense_group's id instead of hardcoding expense_group_id=1:
-    TaskLog.objects.filter(expense_group_id=1).delete()
+    TaskLog.objects.filter(expense_group_id=expense_group.id).delete()
  1. Add a more descriptive comment explaining why TaskLogs need to be cleared:
-    # Clear existing TaskLogs for this expense group
+    # Clear existing TaskLogs to prevent interference from previous test runs and ensure clean state

65-67: Add test coverage for the new is_posted_at_null field.

The PR introduces a new is_posted_at_null field to handle null posted_at values, but the test fixtures don't cover this functionality. Consider adding test cases to verify:

  1. Setting is_posted_at_null=True when posted_at is null
  2. Using spent_at as fallback when posted_at is null
  3. Setting is_posted_at_null=False when posted_at has a value

Would you like me to help generate the test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fa42ac8 and 635af45.

📒 Files selected for processing (3)
  • apps/fyle/migrations/0034_expense_is_posted_at_null.py (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (7 hunks)
  • tests/test_netsuite/conftest.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/fyle/migrations/0034_expense_is_posted_at_null.py
🔇 Additional comments (4)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (4)

5-6: LGTM: PostgreSQL version update

Routine maintenance update from 15.7 to 15.9.


7990-7991: Verify scope of tasks migration

While fyle.0034_expense_is_posted_at_null aligns with PR objective, the inclusion of tasks.0012_alter_tasklog_expense_group seems unrelated to posted_at handling. Please clarify if this is intentional.


11633-11641: Verify data consistency for posted_at handling

The sample data shows all records have is_posted_at_null set to false, but some records have posted_at as NULL. This might need reconciliation to ensure the flag accurately reflects the data state.

✅ Verification successful

Based on the output, I can now generate the final response since I have enough information to verify the concern.

No inconsistency found between posted_at and is_posted_at_null values

The data shows consistent handling where:

  • All records have is_posted_at_null set to false
  • All records have posted_at explicitly set to \N (NULL)
  • This is the expected behavior as per the schema design where is_posted_at_null indicates if the record should be considered for processing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for inconsistencies between posted_at and is_posted_at_null values

rg "COPY.*expenses.*posted_at.*is_posted_at_null" -A 10

Length of output: 5093


1151-1152: Verify default value handling for is_posted_at_null

The new column is correctly added with NOT NULL constraint, but we should verify how existing records are handled.

* feat: auto enable accounting period

* reset db

* platform connector ver
Copy link

Tests Skipped Failures Errors Time
224 0 💤 0 ❌ 0 🔥 24.539s ⏱️

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 635af45 and a66578c.

📒 Files selected for processing (4)
  • apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py (1 hunks)
  • apps/workspaces/models.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (7 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apps/workspaces/migrations/0040_alter_configuration_change_accounting_period.py
  • requirements.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql

apps/workspaces/models.py Show resolved Hide resolved
@anishfyle anishfyle merged commit f5b390a into master Nov 18, 2024
4 checks passed
anishfyle added a commit that referenced this pull request Nov 19, 2024
* handle posted at

* migrations, reset db, conftest

* feat: auto enable accounting period (#668)

* feat: auto enable accounting period

* reset db

* platform connector ver
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