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

Changing process bill payments #640

Merged
merged 4 commits into from
Jun 28, 2024
Merged

Conversation

Ashutosh619-sudo
Copy link
Contributor

@Ashutosh619-sudo Ashutosh619-sudo commented Jun 27, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced the expense reimbursement status check with new logic to handle expense payment statuses based on Fyle data and platform expenses.
  • Tests

    • Added mock tests for test_create_bill_payment and test_post_bill_payment_exceptions functions.

Copy link

coderabbitai bot commented Jun 27, 2024

Warning

Rate limit exceeded

@Ashutosh619-sudo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 22 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

Files that changed from the base of the PR and between 6d4f6ea and 1a05fcf.

Walkthrough

The changes improve the check_expenses_reimbursement_status function to handle expense payment status more effectively based on Fyle data and filtered credit expenses. The logic now updates the paid status accurately and involves filtering options. Additionally, mock patches were added to test functions for better test coverage.

Changes

File Path Change Summary
apps/quickbooks_online/tasks.py Modified check_expenses_reimbursement_status to include additional parameters and filtering logic.
tests/test_quickbooks_online/test_tasks.py Added mock patches for fyle_integrations_platform_connector.apis.Expenses.get in specific tests.

Sequence Diagrams

sequenceDiagram
    participant User
    participant TaskScheduler
    participant QuickBooksOnline as QBO
    participant Fyle

    User->>TaskScheduler: Trigger expense reimbursement check
    TaskScheduler->>QBO: Call check_expenses_reimbursement_status
    QBO->>Fyle: Fetch expense data
    Fyle-->>QBO: Return expense data
    QBO->>Fyle: Call get_filter_credit_expenses
    Fyle-->>QBO: Return filtered credit expenses
    QBO-->>TaskScheduler: Update expenses with paid status
Loading

Poem

In the land of QuickBooks bright,
Fyle's data takes its flight.
Expenses checked with care,
Filtered credit in the air.
Reimbursements, now so clear,
Financial harmony, we cheer! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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

Outside diff range and nitpick comments (1)
apps/quickbooks_online/tasks.py (1)

[!TIP]
Codebase Verification

Ensure proper transaction handling in process_bill_payments.

The process_bill_payments method relies on the @handle_qbo_exceptions decorator for exception handling. However, the method lacks internal try, except, or finally blocks, raising concerns about the robustness of transaction management. The decorator handles specific exceptions but may not cover all edge cases, especially those related to database integrity.

  • File: apps/quickbooks_online/tasks.py
  • Lines: 571-598

Consider adding explicit try, except, and finally blocks within the process_bill_payments method to ensure comprehensive error handling and maintain database integrity.

Analysis chain

Line range hint 595-631: Ensure proper transaction handling in process_bill_payments.

This method handles bill payment processing. Verify that the transaction management is robust and that all edge cases are handled, especially regarding database integrity and error management.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify transaction handling in `process_bill_payments`.

# Test: Search for error handling patterns in the method.
rg --type python $'try|except|finally' -C 5 -g 'apps/quickbooks_online/tasks.py'

Length of output: 110



Script:

#!/bin/bash
# Description: Verify transaction handling in `process_bill_payments`.

# Test: Search for error handling patterns in the method.
rg 'try|except|finally' -C 5 -g 'apps/quickbooks_online/tasks.py'

Length of output: 24963



Script:

#!/bin/bash
# Description: Verify the implementation of the `@handle_qbo_exceptions` decorator.

# Test: Search for the `handle_qbo_exceptions` decorator implementation.
rg 'def handle_qbo_exceptions' -A 20

Length of output: 1694

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1950503 and d8cc71f.

Files selected for processing (1)
  • apps/quickbooks_online/tasks.py (3 hunks)
Additional context used
Ruff
apps/quickbooks_online/tasks.py

14-14: apps.fyle.models.Reimbursement imported but unused

Remove unused import: apps.fyle.models.Reimbursement

(F401)


173-173: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


239-241: Use a single if statement instead of nested if statements

(SIM102)


240-241: Use a single if statement instead of nested if statements

(SIM102)


244-247: Use a single if statement instead of nested if statements

(SIM102)


253-253: Avoid extraneous parentheses

Remove extraneous parentheses

(UP034)


274-275: Use a single if statement instead of nested if statements

(SIM102)


278-279: Use a single if statement instead of nested if statements

(SIM102)


316-316: Comparison to None should be cond is None

Replace with cond is None

(E711)


316-316: Use implicit references for positional format fields

Remove explicit positional indices

(UP030)


316-316: Use f-string instead of format call

Convert to f-string

(UP032)


639-639: Use f-string instead of format call

Convert to f-string

(UP032)

Additional comments not posted (2)
apps/quickbooks_online/tasks.py (2)

631-637: Use f-string for dynamic string formatting.

The format method is used for string formatting. It's recommended to use f-strings for better readability and performance.

- task_log, _ = TaskLog.objects.update_or_create(workspace_id=workspace_id, task_id='PAYMENT_{}'.format(bill.expense_group.id), defaults={'status': 'IN_PROGRESS', 'type': 'CREATING_BILL_PAYMENT'})
+ task_log, _ = TaskLog.objects.update_or_create(workspace_id=workspace_id, task_id=f'PAYMENT_{bill.expense_group.id}', defaults={'status': 'IN_PROGRESS', 'type': 'CREATING_BILL_PAYMENT'})

Likely invalid or redundant comment.


574-595: Updated function signature and logic in check_expenses_reimbursement_status.

The function now takes additional parameters workspace_id and platform, and includes logic to manage the paid_on_fyle flag based on the payment status from Fyle. Ensure that all calls to this function are updated to pass the new parameters.

Verification successful

Function calls to check_expenses_reimbursement_status are updated correctly.

The check_expenses_reimbursement_status function is called with the new parameters workspace_id and platform in the codebase.

  • apps/quickbooks_online/tasks.py: check_expenses_reimbursement_status(bill.expense_group.expenses.all(), workspace_id=workspace_id, platform=platform)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `check_expenses_reimbursement_status` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type python $'check_expenses_reimbursement_status'

Length of output: 85



Script:

#!/bin/bash
# Description: Verify all function calls to `check_expenses_reimbursement_status` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py $'check_expenses_reimbursement_status'

Length of output: 355

from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping
from fyle_integrations_platform_connector import PlatformConnector
from qbosdk.exceptions import InvalidTokenError, WrongParamsError

from apps.fyle.actions import update_expenses_in_progress
from apps.fyle.models import Expense, ExpenseGroup, Reimbursement
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings, Reimbursement
Copy link

Choose a reason for hiding this comment

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

Remove unused import: Reimbursement.

The static analysis tool flagged that Reimbursement is imported but unused. Removing it will clean up the code.

- from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings, Reimbursement
+ from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings, Reimbursement
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
Tools
Ruff

14-14: apps.fyle.models.Reimbursement imported but unused

Remove unused import: apps.fyle.models.Reimbursement

(F401)

Comment on lines 581 to 582
expense_group_settings = ExpenseGroupSettings.objects.get(workspace_id=workspace_id)
filter_credit_expenses = get_filter_credit_expenses(expense_group_settings=expense_group_settings)
Copy link
Contributor

Choose a reason for hiding this comment

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

do both of these at parent func so that we don't repeat db calls for every export

@@ -615,13 +628,13 @@ def create_bill_payment(workspace_id):
fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id)

platform = PlatformConnector(fyle_credentials)
platform.reimbursements.sync()
# platform.reimbursements.sync()
Copy link
Contributor

Choose a reason for hiding this comment

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

remove it off

Copy link

Tests Skipped Failures Errors Time
241 0 💤 0 ❌ 0 🔥 44.753s ⏱️

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

Files that changed from the base of the PR and between d8cc71f and 6d4f6ea.

Files selected for processing (2)
  • apps/quickbooks_online/tasks.py (3 hunks)
  • tests/test_quickbooks_online/test_tasks.py (2 hunks)
Additional context used
Ruff
apps/quickbooks_online/tasks.py

173-173: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


239-241: Use a single if statement instead of nested if statements

(SIM102)


240-241: Use a single if statement instead of nested if statements

(SIM102)


244-247: Use a single if statement instead of nested if statements

(SIM102)


253-253: Avoid extraneous parentheses

Remove extraneous parentheses

(UP034)


274-275: Use a single if statement instead of nested if statements

(SIM102)


278-279: Use a single if statement instead of nested if statements

(SIM102)


316-316: Comparison to None should be cond is None

Replace with cond is None

(E711)


316-316: Use implicit references for positional format fields

Remove explicit positional indices

(UP030)


316-316: Use f-string instead of format call

Convert to f-string

(UP032)


639-639: Use f-string instead of format call

Convert to f-string

(UP032)

tests/test_quickbooks_online/test_tasks.py

778-778: Comparison to None should be cond is None

Replace with cond is None

(E711)


779-779: Avoid equality comparisons to True; use if qbo_credentials.is_expired: for truth checks

Replace with qbo_credentials.is_expired

(E712)


836-836: Avoid equality comparisons to True; use if bill.paid_on_qbo: for truth checks

Replace with bill.paid_on_qbo

(E712)


837-837: Avoid equality comparisons to True; use if bill.payment_synced: for truth checks

Replace with bill.payment_synced

(E712)

Additional comments not posted (2)
apps/quickbooks_online/tasks.py (1)

574-594: Review of updated function check_expenses_reimbursement_status.

The function has been updated to handle more complex scenarios involving expense reimbursement statuses. The addition of workspace_id, platform, and filter_credit_expenses parameters allows for more flexible and dynamic handling of expense data. The function now checks if expenses are paid on Fyle and updates the paid_on_fyle flag accordingly.

Ensure that the function is covered by unit tests, especially with the new logic added.

tests/test_quickbooks_online/test_tasks.py (1)

668-668: Review of new test mocks for check_expenses_reimbursement_status.

The addition of mocks for fyle_integrations_platform_connector.apis.Expenses.get is appropriate for simulating the API behavior in tests. Ensure these mocks return values that test both the true and false paths through the function logic, including edge cases.

Also applies to: 708-708

from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping
from fyle_integrations_platform_connector import PlatformConnector
from qbosdk.exceptions import InvalidTokenError, WrongParamsError

from apps.fyle.actions import update_expenses_in_progress
from apps.fyle.models import Expense, ExpenseGroup, Reimbursement
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
Copy link

Choose a reason for hiding this comment

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

Remove unused import and approve new import.

The import ExpenseGroupSettings is correctly added and used in the updated function. However, as per previous reviews and static analysis, the Reimbursement import is unused and should be removed to clean up the code.

- from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings, Reimbursement
+ from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings

Copy link

Tests Skipped Failures Errors Time
241 0 💤 0 ❌ 0 🔥 51.970s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo added the deploy Triggers deployment of active branch to Staging label Jun 28, 2024
@Ashutosh619-sudo Ashutosh619-sudo merged commit 66d22ce into master Jun 28, 2024
4 checks passed
Ashutosh619-sudo added a commit that referenced this pull request Jun 28, 2024
* Changing process bill payments

* comment resolved and test fix

* dec code cov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Triggers deployment of active branch to Staging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants