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

Max retry for vendor payment limit #637

Merged
merged 6 commits into from
Sep 4, 2024
Merged

Conversation

Ashutosh619-sudo
Copy link
Contributor

@Ashutosh619-sudo Ashutosh619-sudo commented Sep 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a mechanism to conditionally skip vendor payments based on the age and update status of related task logs, enhancing payment processing efficiency.
  • Improvements

    • Enhanced the payment creation process by integrating new validation logic to ensure only relevant payments are processed.
    • Added new fields to track retry status for payment synchronization in the data model, improving operational management.
  • Tests

    • Added a new test to validate the behavior of the vendor payment creation process under specific conditions, ensuring correct handling of task log timestamps.

Copy link

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes introduce a new function, validate_for_skipping_payment, which determines if a payment should be skipped based on the age and update status of related task logs. The create_vendor_payment function is updated to use this validation, allowing for conditional skipping of payments during processing. Additionally, two new Boolean fields, is_retired, are added to the Bill and ExpenseReport models to track payment synchronization retries, accompanied by a new test function to ensure the correctness of this logic.

Changes

Files Change Summary
apps/netsuite/tasks.py Added validate_for_skipping_payment function to determine if payments should be skipped based on task log age; modified create_vendor_payment to call this function before processing payments.
tests/test_netsuite/test_tasks.py Introduced test_skipping_vendor_payment to validate create_vendor_payment behavior under specific conditions related to task logs; minor formatting changes in existing tests.
apps/netsuite/models.py Added is_retired Boolean field to Bill and ExpenseReport models to track payment synchronization retries.
apps/netsuite/migrations/0026_auto_20240902_1650.py Created migration to add is_retired field to bill and expensereport models.
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Updated SQL schema to include is_retired column for public.bills and public.expense_reports.

Poem

🐰 In the meadow where the bunnies play,
New logic hops in to brighten the day!
Payments now skip with a thoughtful glance,
Thanks to the logs, they’ll dance and prance!
So let’s celebrate with a joyful cheer,
For smoother payments, the bunnies hold dear! 🌼

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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

github-actions bot commented Sep 2, 2024

Tests Skipped Failures Errors Time
221 0 💤 0 ❌ 0 🔥 25.615s ⏱️

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, codebase verification and nitpick comments (1)
apps/netsuite/tasks.py (1)

1168-1189: Approved: New function to determine whether to skip payment processing.

The new validate_for_skipping_payment function implements the business logic to determine whether to skip processing a payment based on the age and update status of the related task log.

Consider the following refinements:

  1. Simplify the nested if-elif statements into a single if statement, as suggested by the static analysis hint:
if (now - relativedelta(months=2) > task_log.created_at) or \
        (now - relativedelta(months=1) > task_log.created_at and task_log.updated_at > now - relativedelta(months=1)) or \
        (task_log.updated_at > now - relativedelta(weeks=1)):
    return True
  1. Extract the magic numbers for months and weeks into constants:
TWO_MONTHS = relativedelta(months=2)  
ONE_MONTH = relativedelta(months=1)
ONE_WEEK = relativedelta(weeks=1)

Then use the constants in the if conditions for better readability.

Tools
Ruff

1184-1186: Use a single if statement instead of nested if statements

(SIM102)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2a58395 and 52deaec.

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

1184-1186: Use a single if statement instead of nested if statements

(SIM102)

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

1217-1219: Approved: Enhanced payment processing logic.

The changes made to the create_vendor_payment function incorporate the new validate_for_skipping_payment function to conditionally skip payment processing based on the related task log's timing. This enhances the control flow and functionality of the payment creation process.

Also applies to: 1231-1233

Copy link

github-actions bot commented Sep 2, 2024

Tests Skipped Failures Errors Time
222 0 💤 0 ❌ 0 🔥 25.063s ⏱️

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, codebase verification and nitpick comments (1)
tests/test_netsuite/test_tasks.py (1)

1887-1887: Remove unused variable.

The bill variable is assigned but never used. Consider removing this line.

-    bill = Bill.create_bill(expense_group)
Tools
Ruff

1887-1887: Local variable bill is assigned to but never used

Remove assignment to unused variable bill

(F841)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 52deaec and 952744a.

Files selected for processing (1)
  • tests/test_netsuite/test_tasks.py (2 hunks)
Additional context used
Ruff
tests/test_netsuite/test_tasks.py

1887-1887: Local variable bill is assigned to but never used

Remove assignment to unused variable bill

(F841)


1902-1902: timezone may be undefined, or defined from star imports

(F405)


1904-1904: timedelta may be undefined, or defined from star imports

(F405)


1912-1912: timedelta may be undefined, or defined from star imports

(F405)


1914-1914: timedelta may be undefined, or defined from star imports

(F405)

Additional comments not posted (1)
tests/test_netsuite/test_tasks.py (1)

1902-1902: Verify missing imports.

Some entities like timezone and timedelta are used but may not be imported. Please ensure the necessary imports are present.

To verify, search for the import statements in the file:

If the imports are missing, add them at the beginning of the file:

from datetime import timedelta
from django.utils import timezone

Also applies to: 1904-1904, 1912-1912, 1914-1914

Tools
Ruff

1902-1902: timezone may be undefined, or defined from star imports

(F405)

Copy link

github-actions bot commented Sep 2, 2024

Tests Skipped Failures Errors Time
222 0 💤 14 ❌ 10 🔥 26.983s ⏱️

Copy link

github-actions bot commented Sep 2, 2024

Tests Skipped Failures Errors Time
222 0 💤 14 ❌ 10 🔥 26.941s ⏱️

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 952744a and e4200ac.

Files selected for processing (3)
  • apps/netsuite/migrations/0026_auto_20240902_1650.py (1 hunks)
  • apps/netsuite/models.py (2 hunks)
  • apps/netsuite/tasks.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/netsuite/tasks.py
Additional comments not posted (22)
apps/netsuite/models.py (22)

Line range hint 32-45: LGTM!

The CustomSegment model class looks good and follows the standard Django model structure.


378-378: LGTM!

The new is_retired field is added correctly to the Bill model with a default value of False.


Line range hint 468-488:


Line range hint 620-638:


Line range hint 706-724:


796-796: LGTM!

The new is_retired field is added correctly to the ExpenseReport model with a default value of False.


Line range hint 874-893:


Line range hint 1007-1022:


Line range hint 1092-1108:


Line range hint 1230-1244:


Line range hint 22-35:


Line range hint 38-65:


Line range hint 68-95:


Line range hint 98-106:


Line range hint 109-119:


Line range hint 122-132:


Line range hint 135-154:


Line range hint 157-184:


Line range hint 187-226:


Line range hint 229-241:


Line range hint 244-268:


Line range hint 270-288:

Comment on lines +13 to +22
migrations.AddField(
model_name='bill',
name='is_retired',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),
migrations.AddField(
model_name='expensereport',
name='is_retired',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),
Copy link

Choose a reason for hiding this comment

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

Rename the field to align with the intended purpose.

There is an inconsistency between the field name is_retired and the help text "Is Payment sync retried". The field name suggests a retired state, while the help text and the PR title "Max retry for vendor payment limit" indicate that the field is intended to track the retry state of payment sync.

To align the field name with the intended purpose, apply this diff:

 migrations.AddField(
     model_name='bill',
-    name='is_retired',
+    name='is_payment_sync_retried',
     field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
 ),
 migrations.AddField(
     model_name='expensereport',
-    name='is_retired',
+    name='is_payment_sync_retried',
     field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
 ),
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
migrations.AddField(
model_name='bill',
name='is_retired',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),
migrations.AddField(
model_name='expensereport',
name='is_retired',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),
migrations.AddField(
model_name='bill',
name='is_payment_sync_retried',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),
migrations.AddField(
model_name='expensereport',
name='is_payment_sync_retried',
field=models.BooleanField(default=False, help_text='Is Payment sync retried'),
),

Copy link

github-actions bot commented Sep 2, 2024

Tests Skipped Failures Errors Time
222 0 💤 0 ❌ 0 🔥 25.224s ⏱️

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e4200ac and c941b35.

Files selected for processing (2)
  • apps/netsuite/tasks.py (5 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/netsuite/tasks.py
Additional comments not posted (3)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (3)

Line range hint 1-1: LGTM!

The changes to the public.bills table are approved. The new is_retired column can be used to manage the lifecycle of records in the table.


Line range hint 1-1: LGTM!

The changes to the public.expense_reports table are approved. The new is_retired column can be used to manage the lifecycle of records in the table.


Line range hint 1-1: LGTM!

The changes to the database dump version and the migration sequence value are approved. They are consistent with the addition of a new migration related to the changes made to the public.bills and public.expense_reports tables.

@Ashutosh619-sudo Ashutosh619-sudo added the deploy Triggers deployment of active branch to Staging label Sep 3, 2024
@Ashutosh619-sudo Ashutosh619-sudo added deploy Triggers deployment of active branch to Staging and removed deploy Triggers deployment of active branch to Staging labels Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

Tests Skipped Failures Errors Time
222 0 💤 0 ❌ 0 🔥 26.510s ⏱️

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c941b35 and a91082d.

Files selected for processing (1)
  • apps/netsuite/tasks.py (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/netsuite/tasks.py

@Ashutosh619-sudo Ashutosh619-sudo merged commit 3998b61 into master Sep 4, 2024
4 checks passed
Ashutosh619-sudo added a commit that referenced this pull request Sep 4, 2024
* Max retry for vendor payment limit

* test added

* added is_retried logic

* added is_retried

* fixed test

* bug fix
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.

3 participants