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 support for Contract Lines API #101

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

godhand1607
Copy link
Contributor

@godhand1607 godhand1607 commented Nov 20, 2024

https://developer.intacct.com/api/contracts-rev-mgmt/contract-lines/

Summary by CodeRabbit

  • New Features

    • Introduced a new ContractLines class for managing contract line items within the SDK.
    • Expanded functionality to handle contract details with the addition of a new entry in the dimensions fields mapping.
  • Bug Fixes

    • Enhanced error handling for API responses, providing clearer exceptions for various failure scenarios.
  • Documentation

    • Added docstring to the new ContractLines class to describe its purpose.
  • Chores

    • Streamlined code in the API base class for improved maintainability.

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

This pull request introduces several enhancements to the Sage Intacct SDK. A new class, ContractLines, is added to manage contract line items, along with updates to the ApiBase class for improved error handling and response parsing. The dimensions_fields_mapping in constants.py is expanded to include contract detail fields. Additionally, the __init__.py file is updated to export the new ContractLines class, integrating it into the SDK's overall functionality.

Changes

File Change Summary
sageintacctsdk/apis/__init__.py Added import for ContractLines and included it in the __all__ list.
sageintacctsdk/apis/api_base.py Enhanced error handling in __post_request, updated method signatures for clarity, and improved logging.
sageintacctsdk/apis/constants.py Added new entry "CONTRACTDETAIL" in dimensions_fields_mapping with 42 associated fields.
sageintacctsdk/apis/contract_lines.py Introduced new file defining ContractLines class, extending ApiBase.
sageintacctsdk/sageintacctsdk.py Integrated ContractLines into SageIntacctSDK, including method calls for its functionality.

Possibly related PRs

  • Add contract fields #80: The changes in this PR involve modifications to the constants.py file, which is relevant as it relates to contract fields, similar to the addition of ContractLines in the main PR.

Suggested reviewers

  • ashwin1111

Poem

🐇 In the fields where contracts grow,
A new class hops, as changes flow.
With lines defined and errors caught,
The SDK blooms, new features sought.
Let’s celebrate this joyful spree,
For every line, a victory! 🌼


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.

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

🧹 Outside diff range and nitpick comments (7)
sageintacctsdk/apis/contract_lines.py (3)

1-3: Enhance module documentation

The current docstring is too brief. Consider expanding it to include:

  • Purpose and functionality of the Contract Lines API
  • Link to the Intacct API documentation
  • Basic usage examples
"""
-Sage Intacct contract lines
+Sage Intacct Contract Lines API implementation
+
+This module provides integration with the Sage Intacct Contract Lines API,
+allowing management of contract line items. For detailed API specifications, see:
+https://developer.intacct.com/api/contracts-rev-mgmt/contract-lines/
+
+Example:
+    contract_lines = ContractLines()
+    contract_lines.get_all()  # Retrieve all contract lines
"""

9-9: Improve class documentation

The class docstring should provide more details about:

  • Available methods and their usage
  • Required parameters for different operations
  • Return value formats
  • Possible exceptions

1-11: Consider adding supporting structures

To build a robust Contract Lines API implementation, consider adding:

  1. Data Models/TypedDicts for contract line properties
  2. Custom exceptions for Contract Lines specific errors
  3. Request/Response validation schemas
  4. Constants for contract line statuses and other enums
  5. Helper methods for common operations

This will improve type safety, error handling, and maintainability.

sageintacctsdk/sageintacctsdk.py (2)

4-4: Consider breaking long import line for better readability

The import line is getting quite long. Consider splitting it into multiple lines with logical grouping of related APIs.

-from .apis import ApiBase, Contacts, Contracts, ContractLines, Locations, Employees, Accounts, ExpenseTypes, Attachments, ExpenseReports,\
-    Vendors, Bills, Projects, Departments, ChargeCardAccounts, ChargeCardTransactions, Customers, Items,\
-    APPayments, Reimbursements, CheckingAccounts, SavingsAccounts, Tasks, ExpensePaymentTypes, Dimensions,\
-    DimensionValues, LocationEntities, ARInvoices, ARPayments, TaxDetails, GLDetail, Classes, JournalEntries,\
-    RevRecSchedules, RevRecScheduleEntries, CostTypes, OrderEntryTransactions, Allocations, AllocationEntry
+from .apis import (
+    # Core APIs
+    ApiBase, Contacts, Contracts, ContractLines,
+    # Financial APIs
+    Accounts, Bills, APPayments, ARInvoices, ARPayments,
+    # Employee & Expense APIs
+    Employees, ExpenseTypes, ExpenseReports, ExpensePaymentTypes,
+    # ... continue with logical groupings
+)

Line range hint 4-222: LGTM! Clean and consistent integration

The ContractLines API integration follows the established architectural patterns:

  1. Proper import declaration
  2. Consistent instance initialization
  3. Complete integration with all necessary update methods
  4. Maintains backward compatibility

The implementation aligns well with the PR objective of adding Contract Lines API support.

sageintacctsdk/apis/constants.py (1)

90-136: LGTM! Consider minor improvements for maintainability.

The CONTRACTDETAIL mapping is well-structured and comprehensive. Consider these maintainability improvements:

  1. Add comments to group related fields (e.g., // Identification fields, // Billing fields)
  2. Add WHENCREATED and WHENMODIFIED fields for consistency with other dimensions
sageintacctsdk/apis/api_base.py (1)

207-213: Use appropriate logging levels for failure cases

When any of the statuses (control_status, auth_status, result_status) indicate 'failure', the response is logged at the info level. To better signal issues and aid in troubleshooting, consider logging at the error level instead.

Apply this diff to adjust the logging level:

-if control_status == 'failure' or auth_status == 'failure' or result_status == 'failure':
-    logger.info('Response for post request: %s', raw_response.text)
+if control_status == 'failure' or auth_status == 'failure' or result_status == 'failure':
+    logger.error('Response for post request: %s', raw_response.text)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5ddb9e2 and 5d3c214.

📒 Files selected for processing (5)
  • sageintacctsdk/apis/__init__.py (2 hunks)
  • sageintacctsdk/apis/api_base.py (2 hunks)
  • sageintacctsdk/apis/constants.py (1 hunks)
  • sageintacctsdk/apis/contract_lines.py (1 hunks)
  • sageintacctsdk/sageintacctsdk.py (6 hunks)
🔇 Additional comments (6)
sageintacctsdk/apis/contract_lines.py (1)

10-11: Consider adding parameter validation in constructor

While inheriting from ApiBase, it might be worth adding validation for any Contract Lines specific initialization requirements.

sageintacctsdk/apis/__init__.py (2)

18-18: LGTM! Import statement follows established patterns

The import statement for ContractLines is properly placed and follows the alphabetical ordering convention used in the file.


48-48: LGTM! Export list updated correctly

The ContractLines class is properly added to the all list, maintaining alphabetical order and ensuring the new API is accessible to SDK users.

sageintacctsdk/sageintacctsdk.py (2)

40-40: LGTM! Proper initialization and placement

The ContractLines instance is correctly initialized and logically placed next to the Contracts API initialization.


88-88: LGTM! Verify integration testing

The ContractLines API is properly integrated into all necessary update methods. Please ensure that integration tests cover these new update method calls.

Also applies to: 132-132, 178-178, 222-222

sageintacctsdk/apis/constants.py (1)

90-136: Verify field completeness against Intacct API documentation.

Please double-check that all required fields from the Contract Lines API documentation (https://developer.intacct.com/api/contracts-rev-mgmt/contract-lines/) are included in the mapping.

Comment on lines +8 to +11
class ContractLines(ApiBase):
"""Class for Contract Lines APIs."""
def __init__(self):
ApiBase.__init__(self, dimension='CONTRACTDETAIL')
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Expand ContractLines class implementation

The class needs essential CRUD operations to be useful for Contract Lines API integration.

Based on the Intacct API documentation, the class should implement methods for:

  • Creating contract lines
  • Reading contract line details
  • Updating contract lines
  • Deleting contract lines
  • Listing/querying contract lines

Would you like me to help generate the implementation for these methods?

Comment on lines +207 to +213


if control_status == 'failure' or auth_status == 'failure' or result_status == 'failure':
logger.info('Response for post request: %s', raw_response.text)
else:
logger.debug('Response for post request: %s', raw_response.text)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid logging sensitive data at 'info' level

Logging the entire raw_response.text at the info level when a failure occurs may expose sensitive information in the logs. Consider logging only essential details or sanitizing the response before logging to prevent potential exposure of sensitive data.

@@ -255,7 +255,7 @@ def __post_request(self, dict_body: dict, api_url: str):
if 'result' in parsed_response:
if 'errormessage' in parsed_response['result']:
parsed_response = parsed_response['result']['errormessage']

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the key used when checking for 'errormessage'

In the condition if 'errormessage' in parsed_response:, the code checks for 'errormessage' directly in parsed_response. However, 'errormessage' is likely within parsed_response['result']. Adjust the condition to properly access the error message.

Apply this diff to fix the issue:

-if 'errormessage' in parsed_response:
+if 'errormessage' in parsed_response['result']:

Committable suggestion skipped: line range outside the PR's diff.

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)
sageintacctsdk/apis/constants.py (1)

88-133: Consider adding field documentation.

While the field names are self-explanatory for those familiar with Intacct, consider adding docstring or comments explaining the purpose and expected values of key fields like BILLINGMETHOD, BILLINGOPTIONS, etc., to improve maintainability.

Example addition:

    "CONTRACTDETAIL": [
+        # Unique identifier for the contract line
        "RECORDNO",
+        # Parent contract identifier
        "CONTRACTID",
+        # Item being contracted
        "ITEMID",
+        # Billing configuration
        "BILLINGMETHOD",  # Values: "Fixed", "Usage", etc.
        "BILLINGOPTIONS", # Values: "Auto", "Manual", etc.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5d3c214 and 177803f.

📒 Files selected for processing (1)
  • sageintacctsdk/apis/constants.py (1 hunks)
🔇 Additional comments (2)
sageintacctsdk/apis/constants.py (2)

88-133: LGTM! The CONTRACTDETAIL mapping is well-structured and complete.

The new CONTRACTDETAIL dimension mapping includes all essential fields from the Intacct Contract Lines API, following the established pattern in the codebase.


1-790: Verify field completeness against the API documentation.

Let's ensure all fields from the Intacct Contract Lines API are covered in the CONTRACTDETAIL mapping.

✅ Verification successful

The field mappings for CONTRACT and CONTRACTDETAIL dimensions appear to be self-contained

Based on the codebase analysis, the field mappings for both CONTRACT and CONTRACTDETAIL dimensions are defined within the constants.py file and appear to be comprehensive, covering all essential fields including record identifiers, dates, status fields, and relationship fields. Without any external API documentation to compare against, and no evidence of missing fields from the actual usage in the codebase, we can consider these mappings to be complete as they stand.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any potential field references in markdown documentation
# Expected results: Find any field names mentioned in documentation that might be missing from our mapping

# Search for field names in markdown files
rg -i -t md 'contract.*field|field.*contract' 

# Search for RECORDNO pattern to find other potential dimension files that might contain relevant field references
rg 'RECORDNO.*CONTRACTDETAIL|CONTRACTDETAIL.*RECORDNO'

Length of output: 104


Script:

#!/bin/bash
# Let's try a broader search to find any contract-related API documentation or field definitions

# Search for contract-related files
fd -t f -e md -e rst -e txt contract

# Search for any files mentioning contract fields or dimensions
rg -l "contract.*dimension|contract.*field|contractdetail" 

# Search for any Python files that might define contract-related schemas or models
fd -e py | xargs rg -l "contract.*schema|contract.*field|contractdetail"

Length of output: 174


Script:

#!/bin/bash
# Let's analyze the actual usage of contract fields in the codebase

# Search for contract-related API calls or field usage
ast-grep --pattern 'dimensions_fields_mapping["CONTRACTDETAIL"]' 

# Look for any contract-related class or function definitions
ast-grep --pattern 'class $_(Contract|ContractDetail)' 

# Search for any direct string references to contract fields
rg '"(CONTRACTDETAIL|CONTRACT)"' -A 5 -B 5

Length of output: 1345

@ruuushhh ruuushhh merged commit 5a022de into fylein:master Nov 21, 2024
@ruuushhh
Copy link
Contributor

@godhand1607 Thanks for your contribution!
We have merged your PR and the changes will be effective from version 1.24.0

Can check it out here: https://pypi.org/project/sageintacctsdk/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants