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

Fix: Adding default ccc bank account #180

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

Ashutosh619-sudo
Copy link
Contributor

@Ashutosh619-sudo Ashutosh619-sudo commented Dec 11, 2024

Description

Please add PR description here, add screenshots if needed

Clickup

Please add link here
https://app.clickup.com/1864988/v/l/li/901604887942

Summary by CodeRabbit

  • New Features

    • Enhanced account selection logic in the Journal Entry feature based on fund source.
    • Added new fields for CCC Bank Account ID and Name in the Export Settings.
    • Expanded attribute types in Business Central to include "BANK_ACCOUNT".
    • Updated workspace state management during company selection.
    • Included 'EMPLOYEE' in the attribute types for Fyle fields.
  • Bug Fixes

    • Improved error handling in connection management for Business Central credentials.
  • Migrations

    • Introduced new fields in the Export Setting model to support additional bank account information.
    • Renamed fields in the Export Setting model for consistent naming conventions.

Copy link

coderabbitai bot commented Dec 11, 2024

Walkthrough

This pull request introduces changes to the JournalEntry class in the models.py file, modifying the create_or_update_object method to adjust the logic for selecting the accounts_payable_account_id based on the fund_source of the expense. Additionally, it adds two new fields, default_ccc_bank_account_id and default_ccc_bank_account_name, to the ExportSetting model in the models.py file, enhancing its capability to store information related to credit card transactions. Modifications are also made to serializers for improved attribute handling and error management.

Changes

File Path Change Summary
apps/business_central/exports/journal_entry/models.py Modified create_or_update_object method in JournalEntry to conditionally set accounts_payable_account_id based on expense.fund_source.
apps/workspaces/migrations/0005_exportsetting_default_ccc_bank_account_id_and_more.py Added fields default_CCC_bank_account_id and default_CCC_bank_account_name to exportsetting model.
apps/workspaces/models.py Introduced fields default_ccc_bank_account_id and default_ccc_bank_account_name in ExportSetting class.
apps/business_central/serializers.py Updated BusinessCentralFieldSerializer, CompanySelectionSerializer, and Connectionserializer for attribute handling and error management.
apps/fyle/serializers.py Updated FyleFieldsSerializer to include 'EMPLOYEE' in the attribute_types list.
apps/workspaces/migrations/0006_rename_default_ccc_bank_account_id_exportsetting_default_ccc_bank_account_id_and_more.py Renamed fields default_CCC_bank_account_id to default_ccc_bank_account_id and default_CCC_bank_account_name to default_ccc_bank_account_name in ExportSetting.

Possibly related PRs

  • Feat: Support for dimension during export Journal Entry and purchase Invoice #174: The changes in this PR involve modifications to the JournalEntry class, specifically in the create_or_update_object method, which is directly related to the logic for selecting accounts payable accounts based on the fund source, similar to the changes made in the main PR.
  • Feat: Adding new Journal Entry changes #175: This PR also modifies the create_or_update_object method in the JournalEntry class, which is relevant as it alters the logic for handling expenses and line items, aligning with the focus of the main PR on the JournalEntry class.

Suggested reviewers

  • Hrishabh17
  • ruuushhh

Poem

In the fields where rabbits play,
New accounts come out to stay.
With CCC in sight, oh what a delight,
Journal entries now take flight!
Hopping with joy, we celebrate,
Changes that make our tasks first-rate! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 864592a and a4896b6.

📒 Files selected for processing (1)
  • apps/business_central/exports/journal_entry/models.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/business_central/exports/journal_entry/models.py

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 Dec 11, 2024
Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 8.515s ⏱️

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/workspaces/models.py (1)

189-190: LGTM! Model changes are consistent with existing patterns.

The new CCC bank account fields are well-placed and follow the established patterns in the codebase. Consider adding documentation about when these fields should be configured.

Consider adding a docstring to the ExportSetting class explaining the purpose of CCC-specific fields:

 class ExportSetting(BaseModel):
     """
     Table to store export settings
+    
+    CCC (Corporate Credit Card) specific fields:
+    - default_CCC_bank_account_name: Name of the bank account for CCC transactions
+    - default_CCC_bank_account_id: ID of the bank account for CCC transactions
     """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1679d80 and bb16404.

📒 Files selected for processing (3)
  • apps/business_central/exports/journal_entry/models.py (1 hunks)
  • apps/workspaces/migrations/0005_exportsetting_default_ccc_bank_account_id_and_more.py (1 hunks)
  • apps/workspaces/models.py (1 hunks)
🔇 Additional comments (2)
apps/workspaces/migrations/0005_exportsetting_default_ccc_bank_account_id_and_more.py (1)

13-24: LGTM! Migration is well-structured and backward compatible.

The migration correctly adds the new CCC bank account fields with appropriate field types and null constraints, ensuring backward compatibility with existing records.

apps/business_central/exports/journal_entry/models.py (1)

47-49: Verify CCC bank account ID availability.

While the logic is correct, we should ensure that default_CCC_bank_account_id is available when fund_source is 'CCC'.

Let's check for any existing CCC expenses that might be affected:

Comment on lines 47 to 49
if expense.fund_source == 'CCC':
accounts_payable_account_id = export_settings.default_CCC_bank_account_id

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for missing CCC bank account.

Consider adding validation to handle cases where default_CCC_bank_account_id is None for CCC expenses.

         if expense.fund_source == 'CCC':
+            if not export_settings.default_CCC_bank_account_id:
+                raise ValueError('CCC bank account not configured for workspace')
             accounts_payable_account_id = export_settings.default_CCC_bank_account_id
📝 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
if expense.fund_source == 'CCC':
accounts_payable_account_id = export_settings.default_CCC_bank_account_id
if expense.fund_source == 'CCC':
if not export_settings.default_CCC_bank_account_id:
raise ValueError('CCC bank account not configured for workspace')
accounts_payable_account_id = export_settings.default_CCC_bank_account_id

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 8.738s ⏱️

@@ -186,6 +186,8 @@ class ExportSetting(BaseModel):
)
default_bank_account_name = StringNullField(help_text='Bank account name')
default_bank_account_id = StringNullField(help_text='Bank Account ID')
default_CCC_bank_account_name = StringNullField(help_text='CCC Bank account name')
Copy link
Contributor

Choose a reason for hiding this comment

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

default_ccc_bank_account_name

@@ -186,6 +186,8 @@ class ExportSetting(BaseModel):
)
default_bank_account_name = StringNullField(help_text='Bank account name')
default_bank_account_id = StringNullField(help_text='Bank Account ID')
default_CCC_bank_account_name = StringNullField(help_text='CCC Bank account name')
default_CCC_bank_account_id = StringNullField(help_text='CCC Bank Account ID')
Copy link
Contributor

Choose a reason for hiding this comment

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

default_ccc_bank_account_id

accounts_payable_account_id = export_settings.default_bank_account_id

if expense.fund_source == 'CCC':
accounts_payable_account_id = export_settings.default_CCC_bank_account_id
Copy link
Contributor

Choose a reason for hiding this comment

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

default_ccc_bank_account_id

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 9.011s ⏱️

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 (1)
apps/business_central/serializers.py (1)

81-82: LGTM! Consider adding documentation about attribute filtering.

The addition of "BANK_ACCOUNT" to the excluded attribute types is correct and aligns with the CCC bank account integration.

Consider adding a docstring comment explaining that this method returns non-standard fields by excluding common attribute types:

 def format_business_central_fields(self, workspace_id):
+    """
+    Returns a list of non-standard Business Central fields by excluding common attribute types
+    like VENDOR, ACCOUNT, BANK_ACCOUNT etc.
+    
+    Args:
+        workspace_id: The ID of the workspace
+    
+    Returns:
+        List of unique attribute types and their display names
+    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bb16404 and cbdbfa2.

📒 Files selected for processing (1)
  • apps/business_central/serializers.py (1 hunks)
🔇 Additional comments (1)
apps/business_central/serializers.py (1)

81-82: Verify integration with CCC bank account feature.

Let's verify that this change properly integrates with the new CCC bank account functionality mentioned in the PR.

✅ Verification successful

Integration with CCC bank account feature is properly implemented

The code changes are properly integrated with the CCC bank account functionality. The evidence shows:

  • CCC bank account fields are properly defined in the workspace models
  • Bank account synchronization is implemented and tested
  • Journal entry exports correctly handle CCC bank accounts
  • The serializer's BANK_ACCOUNT attribute type is consistent with the rest of the implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for related CCC bank account handling code
echo "Checking for CCC bank account related code..."

# Look for CCC bank account related models
echo "Looking for model definitions..."
rg -l "default_CCC_bank_account" 

# Look for bank account handling in business logic
echo "Looking for bank account handling..."
rg -l "BANK_ACCOUNT.*attribute_type"

# Look for related tests
echo "Looking for related test coverage..."
rg -l "test.*bank.*account" --type=python

Length of output: 654


Script:

#!/bin/bash
# Let's check the actual implementation and usage of bank account related code

# Check the models file for bank account implementation
echo "Checking bank account implementation in models..."
rg -A 10 "BANK_ACCOUNT" apps/business_central/serializers.py

# Look for bank account related tests with proper file type
echo "Looking for test files..."
fd "test.*\.py$" | xargs rg -l "bank.*account"

# Check the export settings and journal entry models
echo "Checking export settings and journal entries..."
cat apps/workspaces/models.py | grep -A 10 "default_ccc_bank_account"
cat apps/business_central/exports/journal_entry/models.py | grep -A 10 "BANK_ACCOUNT"

Length of output: 946


Script:

#!/bin/bash
# Let's examine the test files and related implementations more closely

# Check the test files content
echo "Checking test file contents..."
cat tests/test_business_central/test_utils.py | grep -A 10 -B 10 "bank.*account"
cat tests/test_workspaces/test_view.py | grep -A 10 -B 10 "bank.*account"

# Look for CCC specific bank account configuration
echo "Checking CCC specific configurations..."
rg -A 5 "CCC.*bank.*account" 

# Check for bank account related constants or enums
echo "Checking for bank account related constants..."
rg -A 5 "BANK_ACCOUNT" apps/business_central/

Length of output: 7260

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 9.090s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo added deploy deploy to staging environment and removed deploy deploy to staging environment labels Dec 12, 2024
Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 9.019s ⏱️

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 9.510s ⏱️

@github-actions github-actions bot added the size/M Medium PR label Dec 12, 2024
@github-actions github-actions bot removed the size/S Small PR label Dec 12, 2024
@Ashutosh619-sudo Ashutosh619-sudo added deploy deploy to staging environment and removed deploy deploy to staging environment labels Dec 12, 2024
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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ffea6a and 864592a.

📒 Files selected for processing (2)
  • apps/workspaces/migrations/0005_exportsetting_default_ccc_bank_account_id_and_more.py (1 hunks)
  • apps/workspaces/migrations/0006_rename_default_ccc_bank_account_id_exportsetting_default_ccc_bank_account_id_and_more.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/workspaces/migrations/0005_exportsetting_default_ccc_bank_account_id_and_more.py
🔇 Additional comments (1)
apps/workspaces/migrations/0006_rename_default_ccc_bank_account_id_exportsetting_default_ccc_bank_account_id_and_more.py (1)

1-23: LGTM! Migration follows Django naming conventions.

The migration correctly renames the fields from CamelCase to snake_case, following Python/Django naming conventions (PEP 8).

Comment on lines +13 to +22
migrations.RenameField(
model_name='exportsetting',
old_name='default_CCC_bank_account_id',
new_name='default_ccc_bank_account_id',
),
migrations.RenameField(
model_name='exportsetting',
old_name='default_CCC_bank_account_name',
new_name='default_ccc_bank_account_name',
),
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: Found reference to old field name in business_central export model

The field default_CCC_bank_account_id in apps/business_central/exports/journal_entry/models.py still uses the old CamelCase naming convention and needs to be updated to match the new snake_case field name from the migration.

  • Update export_settings.default_CCC_bank_account_id to export_settings.default_ccc_bank_account_id in apps/business_central/exports/journal_entry/models.py
🔗 Analysis chain

Verify field name updates across the codebase.

Let's ensure all references to these fields have been updated to use the new snake_case names.


Let's check the content of the file that still contains references to the old field name.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to the old CamelCase field names
# which might cause runtime errors if not updated.

echo "Checking for old field name references..."
rg -l "default_CCC_bank_account" \
  --type py \
  --glob '!**/migrations/*.py'

# Check for any Django model or serializer references
ast-grep --pattern 'class $_(models.Model):
  $$$
  default_CCC_bank_account_$_
  $$$'

ast-grep --pattern 'class $_(serializers.ModelSerializer):
  $$$
  default_CCC_bank_account_$_
  $$$'

Length of output: 411


Script:

#!/bin/bash
# Check the content of the file to see the exact usage
rg "default_CCC_bank_account" apps/business_central/exports/journal_entry/models.py -A 2 -B 2

Length of output: 321

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 8.571s ⏱️

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 9.060s ⏱️

Copy link

Tests Skipped Failures Errors Time
125 0 💤 0 ❌ 0 🔥 8.930s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo merged commit 2b51bbc into bug-fixes-beta Dec 12, 2024
5 checks passed
Ashutosh619-sudo added a commit that referenced this pull request Dec 12, 2024
* Fix: Removing condition for bank account in sync data

* fix line item balanceAccountType check

* bug fix

* bug fix

* Fix: Adding default ccc bank account (#180)

* Fix: Adding default ccc bank account

* removing bank account from import settings

* bug fixed

* change name

* renamed

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

Successfully merging this pull request may close these issues.

2 participants