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: add exchage rate support for JE #700

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

ruuushhh
Copy link
Contributor

@ruuushhh ruuushhh commented Nov 27, 2024

Description

feat: add exchage rate support for JE

Clickup

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

Summary by CodeRabbit

  • New Features

    • Added an exchange_rate field to the journal entry model, enabling multi-currency transaction support.
    • Enhanced handling of multi-currency transactions in journal entries, including automatic retrieval and storage of exchange rates.
  • Bug Fixes

    • Improved error handling for posting journal entries and adjusted transaction dates in closed accounting periods.
  • Chores

    • Updated comments in the database dump to reflect the correct version numbers.

Copy link

coderabbitai bot commented Nov 27, 2024

Walkthrough

This pull request introduces a new exchange_rate field to the journalentry model in the quickbooks_online application, allowing for the storage of exchange rate information. It modifies the import statements in the models.py file to include additional mapping classes and updates the QBOConnector class in utils.py to enhance multi-currency transaction handling. Additionally, a PostgreSQL database dump file is updated to reflect these changes. The overall structure and functionality of existing methods remain unchanged.

Changes

File Path Change Summary
apps/quickbooks_online/migrations/0017_journalentry_exchange_rate.py Added exchange_rate field (FloatField, nullable) to journalentry model; established migration dependency.
apps/quickbooks_online/models.py Added import statements for mapping classes; added exchange_rate field to JournalEntry model.
apps/quickbooks_online/utils.py Enhanced QBOConnector to handle multi-currency transactions; updated method signatures for journal entry construction and posting.
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Updated comments to reflect new PostgreSQL version (from 15.9 to 15.7); added exchange_rate column to public.journal_entries table.

Possibly related PRs

  • fix: Tax Details JE #696: The changes in this PR involve modifications to the QBOConnector class in apps/quickbooks_online/utils.py, which is also affected by the main PR's updates to journal entry handling, particularly in relation to the construction of journal entry payloads that may include the new exchange_rate field.

Suggested labels

size/XS

Suggested reviewers

  • ashwin1111

Poem

In fields of numbers, we hop and play,
An exchange rate added, hip-hip-hooray!
With journal entries, we dance and twirl,
Multi-currency magic, watch it unfurl!
So let’s celebrate, with carrots and cheer,
For every new feature, we hold so dear! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb1f13 and 90c129a.

📒 Files selected for processing (1)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql

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/S Small PR label Nov 27, 2024
Copy link

Tests Skipped Failures Errors Time
261 0 💤 2 ❌ 2 🔥 58.886s ⏱️

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9eeb58d and 9eb1f13.

📒 Files selected for processing (4)
  • apps/quickbooks_online/migrations/0017_journalentry_exchange_rate.py (1 hunks)
  • apps/quickbooks_online/models.py (2 hunks)
  • apps/quickbooks_online/utils.py (2 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql
🧰 Additional context used
🪛 Ruff (0.8.0)
apps/quickbooks_online/utils.py

1242-1242: Use exchange_rate.get('Rate', 1) instead of an if block

Replace with exchange_rate.get('Rate', 1)

(SIM401)

🔇 Additional comments (4)
apps/quickbooks_online/utils.py (1)

1244-1245: Confirm that the exchange_rate field is nullable if not always available

Since you're saving journal_entry.exchange_rate = journal_entry_payload['ExchangeRate'], ensure that the exchange_rate field in the JournalEntry model is nullable or has a default value to handle cases where the exchange rate might not be available.

Verify the JournalEntry model field:

✅ Verification successful

Exchange rate field is properly nullable in the model

The exchange_rate field in the JournalEntry model is correctly defined as nullable with null=True, which safely handles cases where the exchange rate might not be available in the payload.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the `exchange_rate` field in the `JournalEntry` model is nullable.

# Test: Search for the `exchange_rate` field definition in the models.py file.
# Expect: The field should have `null=True` and `blank=True` if it can be empty.

fd -e py 'models.py' --exec grep -nH 'exchange_rate' {}

Length of output: 285

apps/quickbooks_online/migrations/0017_journalentry_exchange_rate.py (1)

13-17: Consider adding currency fields for complete exchange rate tracking

The current schema only tracks the exchange rate without explicitly storing the source and target currencies. This might lead to ambiguity in multi-currency scenarios. Consider adding source_currency and target_currency fields to maintain a clear record of the currency conversion context.

Let's verify if currency information is stored elsewhere in the model:

apps/quickbooks_online/models.py (2)

13-13: LGTM!

The import statement changes look good. The imported mapping classes are used throughout the file for handling various mapping operations.


741-741: Verify exchange rate handling in related components.

The addition of the exchange_rate field to the JournalEntry model looks good and aligns with the PR objective. Since this is a new field that affects currency conversion:

  1. Ensure the exchange rate is properly populated when creating journal entries
  2. Verify that the exchange rate is correctly used in calculations

Let's verify the exchange rate handling implementation:

✅ Verification successful

Exchange rate handling is properly implemented across components

The verification shows that exchange rate handling is correctly implemented:

  1. The exchange_rate field is properly populated in both Bills and JournalEntries when creating entries:

    • Exchange rates are fetched from the connection's exchange rates service
    • The rate is stored in the model only when multi-currency is allowed and currencies differ
    • There's a fallback to rate=1 when no exchange rate is found
  2. The implementation follows consistent patterns across both Bill and JournalEntry components, ensuring uniform currency conversion handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for exchange rate usage in related files

# Look for exchange rate related code
rg -l "exchange_rate" --type py

# Check for currency conversion logic
ast-grep --pattern 'def $FUNC($$$) {
  $$$
  exchange_rate
  $$$
}'

Length of output: 357


Script:

#!/bin/bash
# Let's examine the exchange rate usage in the utils and models files
rg "exchange_rate" apps/quickbooks_online/utils.py -B 2 -A 2

# Check models.py for exchange rate field definitions and usage
rg "exchange_rate" apps/quickbooks_online/models.py -B 2 -A 2

# Look for currency conversion related functions
ast-grep --pattern 'def $FUNC($$$) {
  $$$
  currency
  $$$
}'

Length of output: 2031

apps/quickbooks_online/utils.py Show resolved Hide resolved
apps/quickbooks_online/utils.py Show resolved Hide resolved
apps/quickbooks_online/utils.py Show resolved Hide resolved
Copy link

Tests Skipped Failures Errors Time
261 0 💤 0 ❌ 0 🔥 1m 0s ⏱️

@ruuushhh ruuushhh added the deploy Triggers deployment of active branch to Staging label Nov 27, 2024
@ruuushhh ruuushhh merged commit 999ccde into master Nov 27, 2024
7 checks passed
ruuushhh added a commit that referenced this pull request Nov 27, 2024
* feat: add exchage rate support for JE

* fix tests

---------

Co-authored-by: GitHub Actions <[email protected]>
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 size/S Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants