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 multiselect to choose types of accounts to import #1099

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Dec 9, 2024

Clickup

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

Summary by CodeRabbit

  • New Features

    • Added a multi-select dropdown for selecting chart of account types in import settings.
    • Introduced a new section in the UI for account selection based on user input.
    • Enhanced import settings with a new property for charts of accounts.
    • Improved handling of reimbursable bank accounts in export settings.
  • Bug Fixes

    • Updated default behavior for chart of accounts selection to include 'Expense'.
  • Chores

    • Integrated MultiSelectModule from primeng to support new dropdown functionality.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes in this pull request enhance the Business Central import settings by modifying the BusinessCentralImportSettings type and the associated model. A new property, charts_of_accounts, has been added, along with updates to the form handling and UI components to accommodate this new property. The HTML template now includes a multi-select dropdown for chart of account types, and the component logic has been adjusted to support these enhancements. Additionally, the BusinessCentralSharedModule has been updated to include the MultiSelectModule.

Changes

File Change Summary
src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts - Added property charts_of_accounts: string[] to BusinessCentralImportSettings.
- Updated mapAPIResponseToFormGroup to include chartOfAccountTypes.
- Updated createImportSettingPayload to include charts_of_accounts.
- Added static method getChartOfAccountTypesList().
src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.html - Introduced a new section for account selection with a multi-select dropdown for chart of account types.
src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.ts - Added readonly property chartOfAccountTypesList.
- Changed helper property access modifier from private to public.
src/app/integrations/business-central/business-central-shared/business-central-shared.module.ts - Imported MultiSelectModule from primeng into BusinessCentralSharedModule.
src/app/integrations/business-central/business-central-shared/business-central.fixture.ts - Added property charts_of_accounts: ['Expense'] to importSettingsResponse.
src/app/core/models/enum/enum.model.ts - Added new entry REIMBURSABLE_BANK_ACCOUNT to BCExportSettingDestinationOptionKey enum.
src/app/core/services/common/mapping.service.ts - Updated getPaginatedDestinationAttributes method to include optional categories parameter for filtering.
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html - Refined form structure and properties related to exporting settings for reimbursable and corporate card expenses.
src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts - Added property reimbursableBankOptions and updated logic for handling bank accounts.

Possibly related PRs

  • test: Export Settings QBO #931: The changes in the main PR enhance import settings functionality, which may relate to export settings management in the QBO context, as seen in the modifications to the QboExportSettingsComponent.
  • qbo code prepend changes #958: The updates in the main PR regarding import settings and chart of accounts management could connect with the changes in the QBO export settings, particularly in how import code fields are handled.
  • fix: update default bank a/c options in BC #1098: The addition of new bank account options in the main PR aligns with the updates in the QBD export settings, which also involve managing account types and their visibility in the application.
  • fix: JE fixes #1093: The changes in the main PR regarding account management and export settings may relate to the fixes in the QBD export settings, particularly in how account options are derived and displayed based on user selections.

Suggested reviewers

  • ashwin1111

Poem

🐰 In the fields where accounts do play,
New settings bloom, bright as day.
With charts to choose and forms to fill,
Importing data brings a thrill!
Hop along, let's set the pace,
Business Central finds its place! 🌼


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

🧹 Outside diff range and nitpick comments (6)
src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (2)

29-29: Consider extracting default value to a constant

The default value ['Expense'] should be extracted to a named constant for better maintainability and reuse.

+private static readonly DEFAULT_CHART_OF_ACCOUNTS = ['Expense'];

 static mapAPIResponseToFormGroup(importSettings: BusinessCentralImportSettingsGet | null, businessCentralFields: IntegrationField[]): FormGroup {
     const expenseFieldsArray = importSettings?.mapping_settings ? this.constructFormArray(importSettings.mapping_settings, businessCentralFields) : [] ;
     return new FormGroup({
         importCategories: new FormControl(importSettings?.import_settings?.import_categories ?? false),
-        chartOfAccountTypes: new FormControl(importSettings?.import_settings.charts_of_accounts ? importSettings?.import_settings.charts_of_accounts : ['Expense']),
+        chartOfAccountTypes: new FormControl(importSettings?.import_settings.charts_of_accounts ?? this.DEFAULT_CHART_OF_ACCOUNTS),

48-50: Consider making chart types configurable

The hard-coded list of chart account types could be problematic for maintenance. Consider:

  1. Moving this to a configuration file
  2. Fetching supported types from the backend
  3. Adding validation against supported types

This would make the system more maintainable and prevent potential mismatches with backend capabilities.

src/app/integrations/business-central/business-central-shared/business-central.fixture.ts (1)

51-52: Consider adding more test cases

While the basic case is covered, consider adding test fixtures for:

  1. Multiple selected account types
  2. Empty array case
  3. Edge cases with invalid values

This would help ensure robust testing of the new functionality.

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

34-41: Enhance accessibility and error handling for the multi-select component

The multi-select implementation could benefit from improved accessibility and error handling:

- <p-multiSelect [optionDisabled]="'Expense'" [placeholder]="'Select Chart of Accounts'" [options]="chartOfAccountTypesList" styleClass="tw-z-2 tw-py-8-px tw-px-12-px" [formControlName]="'chartOfAccountTypes'">
+ <p-multiSelect 
+   [optionDisabled]="'Expense'" 
+   [placeholder]="'Select Chart of Accounts'" 
+   [options]="chartOfAccountTypesList" 
+   styleClass="tw-z-2 tw-py-8-px tw-px-12-px" 
+   [formControlName]="'chartOfAccountTypes'"
+   ariaLabel="Select chart of accounts types"
+   [showClear]="true"
+   [maxSelectedLabels]="3"
+   [loading]="isChartOfAccountTypesLoading">
src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.ts (2)

53-53: Add loading state management for chart of account types

The component should manage a loading state for the chart of account types to provide better user feedback.

+ isChartOfAccountTypesLoading: boolean = false;

  readonly chartOfAccountTypesList: string[] = BusinessCentralImportSettingsModel.getChartOfAccountTypesList();

73-73: Consider keeping helper service private

The helper service is made public solely for template access. Consider keeping it private and exposing only the required functionality through component methods.

- public helper: HelperService,
+ private helper: HelperService,

+ // Add public method to access required helper functionality
+ public sentenceCaseConversion(text: string): string {
+   return this.helper.sentenseCaseConversion(text);
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3de2e0e and 80fb1e1.

📒 Files selected for processing (5)
  • src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (3 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.html (1 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.ts (2 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central-shared.module.ts (2 hunks)
  • src/app/integrations/business-central/business-central-shared/business-central.fixture.ts (1 hunks)
🔇 Additional comments (5)
src/app/integrations/business-central/business-central-shared/business-central-shared.module.ts (1)

7-7: LGTM: MultiSelect module integration

The addition of PrimeNG's MultiSelectModule is appropriate for implementing the chart of accounts selector functionality.

Also applies to: 17-17

src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (2)

8-9: LGTM: Type definition update

The addition of charts_of_accounts to the import settings interface is well-structured and properly typed.


41-42: LGTM: Payload construction

The payload construction correctly includes the new chart of accounts field.

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

25-44: Verify error handling for required selection

The multi-select section should indicate if a selection is required and display validation errors.

src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.ts (1)

53-54: Verify the completeness of chart of account types list

Ensure that the static list includes all possible account types from Business Central.

✅ Verification successful

Let me analyze the results. I can see that the getChartOfAccountTypesList() method for Business Central is implemented in src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts and returns the following account types:

  • Expense
  • Assets
  • Income
  • Equity
  • Liabilities
  • Others
  • Cost of Goods Sold

Let me verify if this list matches with Business Central's account types by searching for any related documentation or schema definitions.


Let me search for any Business Central API models or interfaces that might define the account types.


Let me search for any Business Central account type definitions in the API models.


Let me check the content of these enums to see if they define the account types.


Based on the analysis of the codebase, I can now provide a final response:

The chart of account types list is complete and accurate

The implementation in BusinessCentralImportSettingsModel.getChartOfAccountTypesList() returns all the standard account types used in Business Central:

  • Expense
  • Assets
  • Income
  • Equity
  • Liabilities
  • Others
  • Cost of Goods Sold

These account types align with the standard accounting categories in Business Central and cover all the main types of accounts needed for financial reporting and accounting operations. The list is comprehensive and includes both balance sheet accounts (Assets, Liabilities, Equity) and income statement accounts (Income, Expense, Cost of Goods Sold), plus a catch-all 'Others' category for special cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the implementation of getChartOfAccountTypesList
rg -A 10 "getChartOfAccountTypesList" src/

Length of output: 16438


Script:

#!/bin/bash
# Search for Business Central account types in the codebase
rg -i "account.*type" --type ts src/app/core/models/business-central/

Length of output: 701


Script:

#!/bin/bash
# Search for Business Central API interfaces and type definitions
rg -A 5 "interface.*Business.*Central.*" src/
rg -A 5 "type.*Business.*Central.*" src/

Length of output: 19370


Script:

#!/bin/bash
# Search for Business Central account types in models and API files
rg -i "account.*type.*=.*" src/app/core/models/business-central/
rg -i "enum.*business.*central" src/

Length of output: 511


Script:

#!/bin/bash
# Check the content of Business Central related enums
rg -A 10 "enum BusinessCentral" src/app/core/models/enum/enum.model.ts

Length of output: 1658

* 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
@github-actions github-actions bot added size/M Medium PR and removed size/S Small PR labels Dec 10, 2024
Copy link

Unit Test Coverage % values
Statements 34.06% ( 4196 / 12316 )
Branches 27.73% ( 1206 / 4348 )
Functions 26.69% ( 922 / 3454 )
Lines 34.22% ( 4128 / 12060 )

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 (5)
src/app/core/services/common/mapping.service.ts (3)

175-175: Fix typo in type definition.

There's a typo in the interface property name: detail__accout_type__in should be detail__account_type__in.

-    const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, value?: string, display_name__in?: string, detail__accout_type__in?: string[], detail__category__in?: string[]} = {
+    const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, value?: string, display_name__in?: string, detail__account_type__in?: string[], detail__category__in?: string[]} = {

198-201: Consider adding input validation for categories.

While the implementation is correct, consider adding validation to ensure the categories array is not empty when provided. This would prevent unnecessary API calls with empty category filters.

     if (categories) {
+      if (categories.length > 0) {
         params.detail__category__in = categories;
+      }
     }

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

Test coverage needed for new filtering functionality

The mapping service lacks proper test coverage:

  • The mapping.service.spec.ts only contains a basic creation test
  • No test cases exist for getPaginatedDestinationAttributes method and its filtering capabilities
  • The API endpoint /workspaces/{id}/mappings/paginated_destination_attributes/ is used in QBO fixtures with similar filtering parameters, suggesting the endpoint supports such filtering

Please add test cases to cover:

  • Basic filtering with categories
  • Multiple category filtering
  • Interaction with other filter parameters
🔗 Analysis chain

Line range hint 173-201: Verify API endpoint compatibility and test coverage.

Please ensure:

  1. The API endpoint /workspaces/{id}/mappings/paginated_destination_attributes/ supports the new detail__category__in filter parameter.
  2. Unit tests are updated to cover the new categories filtering functionality.

Let me gather more information about the test coverage by searching for spec files specifically.


Let me check the specific content of the mapping service spec file to see if there are any tests for the getPaginatedDestinationAttributes method.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for test coverage and API endpoint usage

# Check for test file existence and content
echo "Checking for test coverage..."
rg -l "getPaginatedDestinationAttributes.*categories" --type ts "spec.ts$"

# Check for API endpoint usage with the new parameter
echo "Checking API endpoint usage..."
rg -A 5 "detail__category__in" --type ts

Length of output: 1392


Script:

#!/bin/bash
# Search for mapping service spec file
echo "Searching for mapping service spec file..."
fd "mapping.service.spec.ts"

# If found, check its content for test cases
echo "Checking test content..."
rg -A 10 "describe.*MappingService" --type ts

Length of output: 6362


Script:

#!/bin/bash
# Check content of mapping.service.spec.ts
echo "Checking mapping service spec content..."
cat src/app/core/services/common/mapping.service.spec.ts

# Check if the API endpoint is used elsewhere in the codebase
echo "Checking API endpoint usage..."
rg -A 2 "mappings/paginated_destination_attributes" --type ts

Length of output: 1579

src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (2)

173-191: Consider optimizing duplicate checking in 'optionSearchWatcher' method

In the optionSearchWatcher method, when handling REIMBURSABLE_BANK_ACCOUNT, the duplicate check uses find inside a forEach loop, resulting in O(n²) time complexity for large datasets.

Consider using a Set or Map to store destination_ids for faster lookup, improving performance for larger data sets.

Possible code change:

+ const existingIds = new Set(this.reimbursableBankOptions.map(option => option.destination_id));
  newOptions.forEach((newOption) => {
-   if (!this.reimbursableBankOptions.find((existingOption) => existingOption.destination_id === newOption.destination_id)) {
+   if (!existingIds.has(newOption.destination_id)) {
      this.reimbursableBankOptions.push(newOption);
+     existingIds.add(newOption.destination_id);
    }
  });

209-214: Optimize duplicate checking when updating 'existingOptions'

The duplicate check in updating existingOptions uses find inside a forEach loop, which can be inefficient for larger datasets.

Use a Set to store existing destination_ids for faster lookup.

Possible code change:

+ const existingIds = new Set(existingOptions.map(option => option.destination_id));
  response.results.forEach((option) => {
-   if (!existingOptions.find((existingOption) => existingOption.destination_id === option.destination_id)) {
+   if (!existingIds.has(option.destination_id)) {
      existingOptions.push(option);
+     existingIds.add(option.destination_id);
    }
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 80fb1e1 and 3d065a4.

📒 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 (7)
src/app/core/services/common/mapping.service.ts (1)

173-173: LGTM! Method signature change maintains backward compatibility.

The addition of the optional categories parameter is well-placed and follows TypeScript conventions.

src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts (4)

34-35: Addition of 'reimbursableBankOptions' property is appropriate

The new property reimbursableBankOptions: DestinationAttribute[]; is correctly declared and will hold the destination attributes for reimbursable bank accounts.


217-225: LGTM

The code correctly updates and sorts the bankOptions and vendorOptions based on the search results.


269-276: LGTM

The reimbursableBankAccountAttributes observables are correctly defined to fetch bank accounts and accounts with categories 'Assets' and 'Liabilities'.


304-306: LGTM

The reimbursableBankOptions are properly initialized by combining and sorting the results from reimbursableBankAccounts and reimbursableAccounts.

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

94-95: Updated binding of 'destinationAttributes' and 'destinationOptionKey'

The destinationAttributes now correctly bind to reimbursableBankOptions, and the destinationOptionKey is updated to BCExportSettingDestinationOptionKey.REIMBURSABLE_BANK_ACCOUNT, aligning with the new handling of reimbursable bank accounts.

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

705-706: Addition of 'REIMBURSABLE_BANK_ACCOUNT' to Enum

The new enum value REIMBURSABLE_BANK_ACCOUNT = 'REIMBURSABLE_BANK_ACCOUNT' is correctly added to BCExportSettingDestinationOptionKey.

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