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: update default bank a/c options in BC #1098

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Dec 9, 2024

Description

We now show ACCOUNT as well as BANK_ACCOUNT attributes as options for default bank accounts. Only ACCOUNTs of category 'Assets' or 'Liabilities' are shown

Clickup

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

Summary by CodeRabbit

  • New Features

    • Added support for reimbursable bank account options in export settings.
    • Enhanced filtering capability for destination attributes based on specified categories.
  • Bug Fixes

    • Improved handling of bank account options in the user interface for reimbursable expenses.

We now show `ACCOUNT` as well as `BANK_ACCOUNT` attributes as options for default bank accounts.
Only `ACCOUNT`s of category 'Assets' or 'Liabilities' are shown
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes in this pull request involve modifications to several components related to the Business Central export settings. A new enum member REIMBURSABLE_BANK_ACCOUNT is added to the BCExportSettingDestinationOptionKey enum, enhancing export options. The MappingService class is updated to include a new optional parameter for filtering by categories in the getPaginatedDestinationAttributes method. Additionally, the HTML and TypeScript components for the Business Central export settings are updated to accommodate the new reimbursable bank account options, including changes to property names and data retrieval methods.

Changes

File Change Summary
src/app/core/models/enum/enum.model.ts Added new enum member: REIMBURSABLE_BANK_ACCOUNT to BCExportSettingDestinationOptionKey.
src/app/core/services/common/mapping.service.ts Updated getPaginatedDestinationAttributes method to include new optional parameter categories.
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html Modified properties in app-configuration-select-field components to reflect reimbursable bank options.
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts Added property reimbursableBankOptions and updated optionSearchWatcher and setupPage methods for new bank options.

Possibly related PRs

  • test: Export Settings QBO #931: Although this PR focuses on QuickBooks Online (QBO) export settings, it does not directly relate to the changes made in the main PR regarding the BCExportSettingDestinationOptionKey enum.
  • qbo code prepend changes #958: This PR modifies the MappingService class, which is also relevant to the changes in the main PR as it involves the same service and could potentially interact with the new enum member added in the main PR.
  • fix: text changes in business central configuration #1089: This PR includes changes to the business-central-export-settings.component.html, which directly relates to the changes made in the main PR regarding the BCExportSettingDestinationOptionKey enum, specifically the updates to the labels and sub-labels that reference the new enum member.
  • fix: JE fixes #1093: This PR addresses fixes related to the qbd-direct-export-settings.component, which may involve similar logic or components as those modified in the main PR, particularly in the context of export settings.

Suggested labels

deploy

Suggested reviewers

  • DhaaraniCIT
  • ashwin1111

Poem

In the fields where rabbits play,
New options hop in bright array.
With bank accounts that now can share,
Reimbursable dreams float in the air!
Hopping through code, we celebrate,
Changes that make our exports great! 🐇✨


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.

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (4)
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (1)

183-190: Consider refactoring the option update logic to avoid duplication

The code for updating and sorting options is similar in both the if and else blocks. Refactoring this logic into a separate method can enhance maintainability and reduce code duplication.

src/app/core/services/common/mapping.service.ts (1)

Line range hint 173-201: Update JSDoc comments to reflect the new parameter

The getPaginatedDestinationAttributes method now includes a new parameter categories. Update the method's documentation to include this parameter for clarity.

src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html (1)

94-95: Update the form control name for clarity

The form control name 'defaultBankName' might be misleading in the context of reimbursable expenses. Consider renaming it to 'reimbursableDefaultBankName' to improve clarity.

Apply this diff to rename the form control:

[formControllerName]="'defaultBankName'">
+ [formControllerName]="'reimbursableDefaultBankName'">

Also, update the corresponding TypeScript code to reflect this change.

src/app/core/models/enum/enum.model.ts (1)

705-706: Alphabetical ordering of enum members

For better readability and maintainability, consider ordering the enum members alphabetically.

Apply this diff to reorder the enum members:

 export enum BCExportSettingDestinationOptionKey {
+  ACCOUNT = 'ACCOUNT',
   REIMBURSABLE_BANK_ACCOUNT = 'REIMBURSABLE_BANK_ACCOUNT',
-  ACCOUNT = 'ACCOUNT',
   VENDOR = 'VENDOR',
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 80fb1e1 and 943d0c1.

📒 Files selected for processing (4)
  • src/app/core/models/enum/enum.model.ts (1 hunks)
  • src/app/core/services/common/mapping.service.ts (2 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html (1 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (4 hunks)
🔇 Additional comments (2)
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (1)

268-280: ⚠️ Potential issue

Verify the correspondence between observables and subscription parameters

In the forkJoin call, ensure that the number and order of observables match the parameters in the subscribe callback. There might be a mismatch leading to incorrect assignment of data.

Run the following script to check the number of observables and parameters:

If the counts do not match, consider adjusting the parameters accordingly.

✅ Verification successful

Let me try a different approach to verify this with more precise commands.


Let me try one more verification to understand the content of groupedAttributes which is spread into the forkJoin.


Based on the gathered information, I can now provide the final response:

Observable count mismatch detected in forkJoin subscription

The forkJoin combines:

  • 1 observable from getExportSettings()
  • 2 observables from groupedAttributes (ACCOUNT and VENDOR)
  • 2 observables from reimbursableBankAccountAttributes (BANK_ACCOUNT and ACCOUNT)

Total: 5 observables

However, the subscription destructures into: [exportSettingsResponse, accounts, vendors, reimbursableBankAccounts, reimbursableAccounts], which matches the 5 observables in the correct order:

  1. exportSettingsResponse → getExportSettings
  2. accounts → from groupedAttributes[0] (ACCOUNT)
  3. vendors → from groupedAttributes[1] (VENDOR)
  4. reimbursableBankAccounts → from reimbursableBankAccountAttributes[0] (BANK_ACCOUNT)
  5. reimbursableAccounts → from reimbursableBankAccountAttributes[1] (ACCOUNT)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check that the number of observables matches the number of parameters in the forkJoin subscribe callback.

# Count the number of observables in the forkJoin call
observables_count=$(grep -A 10 'forkJoin\(\[' src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts | grep -E 'this\..*' | wc -l)

# Count the number of parameters in the subscribe callback
parameters_count=$(grep -A 1 'forkJoin\(' src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts | grep -E 'subscribe\(\[' | sed 's/.*\[\(.*\)\].*/\1/' | awk -F',' '{print NF}')

echo "Number of observables: $observables_count"
echo "Number of subscribe parameters: $parameters_count"

Length of output: 672


Script:

#!/bin/bash
# Let's examine the content around the forkJoin to understand the structure better
rg -A 15 "forkJoin\(\[" src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts

# Also get the full subscribe line for parameter analysis
rg "\.subscribe\(\[\w+" src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts

Length of output: 1066


Script:

#!/bin/bash
# Let's find where groupedAttributes is defined
rg -B 10 "const groupedAttributes" src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts

Length of output: 575

src/app/core/services/common/mapping.service.ts (1)

198-201: Consistency in parameter naming and usage

Ensure that the parameter detail__category__in is consistently named and used throughout the codebase. Verify that the backend API supports filtering by detail__category__in.

Run the following script to check for consistent usage:

✅ Verification successful

Let me gather more information about the API parameter usage and related code.


Let me check the API service implementation to understand how these parameters are handled.


Based on the gathered information, I can now provide the final response:

Parameter naming follows Django-style filtering convention and is consistently used

The parameter detail__category__in follows the Django-style filter naming convention (double underscore for relationships) and is consistently used within the codebase. The parameter:

  • Is properly typed in the params interface
  • Is handled correctly by the ApiService's GET method which transforms it into HTTP parameters
  • Follows the same pattern as other similar filters (e.g., detail__account_type__in)
  • Is used exclusively in the mapping service for destination attribute filtering
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of 'detail__category__in' in API calls.

# Search for 'detail__category__in' in service files
rg 'detail__category__in' src/app/core/services/

# Check if the backend API documentation includes 'detail__category__in' as a supported parameter
# Expected: References to 'detail__category__in' in API service calls

Length of output: 428


Script:

#!/bin/bash
# Search for files that might contain API documentation or interface definitions
fd -e ts -e md "api|interface|type" src/app/core

# Look for similar parameter patterns in the codebase
rg "detail__\w+__in" src/app/core

# Check the mapping service implementation for context
rg -B 5 -A 5 "detail__category__in" src/app/core/services/common/mapping.service.ts

Length of output: 1781


Script:

#!/bin/bash
# Check API service implementation
cat src/app/core/services/common/api.service.ts

# Look for any tests that might verify these parameters
rg -A 5 "getPaginatedDestinationAttributes" src/app/core

# Check for any interface definitions related to these parameters
ast-grep --pattern 'interface $_ {
  $$$
  detail__category__in?: $_
  $$$
}'

Length of output: 4398

Copy link
Contributor

@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 (2)
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (2)

183-191: Extract common sorting logic

The sorting logic is duplicated across different sections of the code. Consider extracting it into a reusable method.

Create a utility method:

+private sortDestinationAttributes(attributes: DestinationAttribute[]): DestinationAttribute[] {
+  return attributes.sort((a, b) => (a.value || '').localeCompare(b.value || ''));
+}

-this.reimbursableBankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || ''));
+this.reimbursableBankOptions = this.sortDestinationAttributes(this.reimbursableBankOptions);

-this.bankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || ''));
+this.bankOptions = this.sortDestinationAttributes(this.bankOptions);

-this.vendorOptions.sort((a, b) => (a.value || '').localeCompare(b.value || ''));
+this.vendorOptions = this.sortDestinationAttributes(this.vendorOptions);

Also applies to: 218-220, 222-224


270-274: Extract reimbursable bank account categories as constant

The categories array ['Assets', 'Liabilities'] is used in multiple places. Consider extracting it as a constant.

Add a constant at the class level:

+private readonly REIMBURSABLE_ACCOUNT_CATEGORIES = ['Assets', 'Liabilities'] as const;

-'ACCOUNT', undefined, undefined, undefined, undefined, ['Assets', 'Liabilities']
+'ACCOUNT', undefined, undefined, undefined, undefined, this.REIMBURSABLE_ACCOUNT_CATEGORIES
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 943d0c1 and ad1919b.

📒 Files selected for processing (1)
  • src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (4 hunks)
🔇 Additional comments (3)
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (3)

34-34: Initialize 'reimbursableBankOptions' to an empty array

To prevent potential undefined errors when accessing reimbursableBankOptions, it should be initialized as an empty array.


304-306: Ensure uniqueness when merging reimbursable bank options

When combining results from both API calls, duplicate entries might occur.


173-191: Verify filtering of account categories

Please ensure that the filtering of accounts by 'Assets' and 'Liabilities' categories works as expected and doesn't exclude any valid accounts.

Also applies to: 270-274

✅ Verification successful

The search results show that the account categories 'Assets' and 'Liabilities' are consistently used in the codebase. Let me verify the complete implementation by checking the mapping service definition.


Let me try a different approach to verify the mapping service implementation.


Based on the search results, I can now provide a final response. The code shows that:

  1. The mapping service's getPaginatedDestinationAttributes method properly supports filtering by categories through its parameters.
  2. The Business Central export settings component consistently uses the 'Assets' and 'Liabilities' categories filter when fetching ACCOUNT type attributes.
  3. The implementation is used in both the search functionality and initial loading of options.
  4. The filtering is consistently applied across the codebase.

Filtering of accounts by 'Assets' and 'Liabilities' categories is correctly implemented

The implementation properly filters accounts by the specified categories. The code consistently uses the category filter parameter in both the search and initial load scenarios, ensuring that only accounts from 'Assets' and 'Liabilities' categories are included in the reimbursable bank options.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the account categories being used
# Test: Search for account category usage in the codebase

echo "Searching for account category references:"
rg -A 2 "Assets|Liabilities" --type ts

echo "Searching for getPaginatedDestinationAttributes usage with categories:"
ast-grep --pattern 'getPaginatedDestinationAttributes($$$, $$$, $$$, $$$, $$$, $_)'

Length of output: 1894


Script:

#!/bin/bash
# Check the mapping service implementation
ast-grep --pattern 'getPaginatedDestinationAttributes($$$) {
  $$$
}'

# Also check for any tests related to this functionality
rg -l "getPaginatedDestinationAttributes.*Assets.*Liabilities" --type spec

Length of output: 297


Script:

#!/bin/bash
# Search for the mapping service file and its implementation
fd -e ts mapping.service

# Check for any test files related to account filtering
fd -e spec.ts -e test.ts | xargs rg -l "Assets.*Liabilities|ACCOUNT.*category"

# Look for the service method implementation
rg -A 5 "getPaginatedDestinationAttributes" --type ts

Length of output: 43624

Copy link

Unit Test Coverage % values
Statements 34.15% ( 4197 / 12287 )
Branches 27.94% ( 1209 / 4327 )
Functions 26.77% ( 922 / 3443 )
Lines 34.31% ( 4128 / 12031 )

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername merged commit cf56738 into business-central-beta-2 Dec 10, 2024
5 checks passed
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Dec 10, 2024
* feat: add multiselect to choose types of accounts to import

* fix: update default bank a/c options in BC (#1098)

* fix: update default bank a/c options in BC

We now show `ACCOUNT` as well as `BANK_ACCOUNT` attributes as options for default bank accounts.
Only `ACCOUNT`s of category 'Assets' or 'Liabilities' are shown

* fix: after autocomplete search, reset the in progress state of the field
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