Skip to content

feat: implement added to cart worksheet functionality#431

Merged
kallilsouza merged 8 commits into
mainfrom
feature/added-to-cart-metrics-report
Jun 11, 2026
Merged

feat: implement added to cart worksheet functionality#431
kallilsouza merged 8 commits into
mainfrom
feature/added-to-cart-metrics-report

Conversation

@kallilsouza

Copy link
Copy Markdown
Contributor

What

Adds a new ADDED_TO_CART section to the Conversations report. When this section is selected, the report builder generates an "Added to cart" worksheet containing each product-added-to-cart event with its URN, date, and product value, sourced from the datalake. The change introduces:

  • New ADDED_TO_CART value in ConversationsReportSections.
  • New abstract method get_added_to_cart_worksheet in BaseConversationsReportService and its concrete implementation in ConversationsReportService.
  • Two new settings: CONVERSATIONS_METRICS_ADDED_TO_CART_AGENT_UUID (required) and CONVERSATIONS_METRICS_ADDED_TO_CART_KEY (event key used to filter datalake events).
  • A new exception AddedToCartAgentUUIDNotConfiguredError raised when the agent UUID is missing.
  • Wiring of the new section into the worksheet mapping and the available widgets list.
  • Translations for "Added to cart" and "Product" (PT-BR / ES).
  • Tests for the serializer, the worksheet generation (with data, empty data, and missing-configuration error), and the worksheets dispatcher.

Why

Customers need visibility into the products added to cart so they can analyze data directly from the Conversations Report. Exposing this data as an additional worksheet inside the existing report keeps the flow consistent with the other sections (CSAT, NPS, Tool Results, etc.) and reuses the datalake integration already in place.

Sequence diagram

sequenceDiagram
    participant Client
    participant Serializer as RequestConversationsReportGenerationSerializer
    participant Service as ConversationsReportService
    participant Settings as Django settings
    participant Datalake as Datalake events source
    participant Worksheet as ConversationsReportWorksheet

    Client->>Serializer: POST report request (sections=[ADDED_TO_CART])
    Serializer-->>Service: validated_data (project, dates, sections)
    Service->>Service: _get_worksheets(report, start_date, end_date)
    Service->>Service: dispatch ADDED_TO_CART -> get_added_to_cart_worksheet
    Service->>Settings: read CONVERSATIONS_METRICS_ADDED_TO_CART_AGENT_UUID
    alt agent_uuid not configured
        Settings-->>Service: empty value
        Service-->>Client: raise AddedToCartAgentUUIDNotConfiguredError
    else agent_uuid configured
        Settings-->>Service: agent_uuid, key
        Service->>Datalake: get_datalake_events(event_name="weni_nexus_data", key, metadata=agent_uuid, date range)
        Datalake-->>Service: events [{contact_urn, date, value}, ...]
        Service->>Service: translate headers (URN, Date, Product) for requester language
        Service->>Service: build rows (empty placeholder row when no events)
        Service->>Worksheet: ConversationsReportWorksheet(name="Added to cart", data)
        Worksheet-->>Service: worksheet
        Service-->>Client: report including Added to cart worksheet
    end
Loading

- Added a new section for "Added to Cart" in the Conversations Report.
- Implemented the method get_added_to_cart_worksheet to retrieve relevant data.
- Introduced error handling for unconfigured agent UUID.
- Updated serializers and tests to validate the new functionality and ensure proper integration.
…sationsReportService

- Implemented get_added_to_cart_widget to retrieve the "Added to Cart" widget for a project.
- Integrated the new widget retrieval function into the ConversationsReportService.
- Updated tests to include verification for the added widget functionality.
- Updated test cases to mock and verify the "Added to Cart" widget in the ConversationsReportService.
- Created instances of the added to cart widget for testing scenarios.
- Ensured proper integration of the new widget in available widgets tests.
- Added mock for get_added_to_cart_widget in test_services.py to verify its integration.
- Updated test cases to ensure proper handling of the "Added to Cart" widget in available widgets tests.
- Removed "ADDED_TO_CART" from expected sections in test assertions to reflect changes in widget availability.
Base automatically changed from feature/added-to-cart-metrics to main June 11, 2026 20:56
…Service

- Added report, start_date, and end_date parameters to the get_added_to_cart_worksheet method call for improved functionality.
mock_get_crosstab_widgets,
):
"""Test get_available_widgets with only some special widgets available."""
mock_get_search_term_widget.return_value = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

References undefined variable mock_get_search_term_widget which is not declared in the function parameters or decorators. This will cause a NameError: name 'mock_get_search_term_widget' is not defined at runtime.

# Line 5190 should be removed as it references a non-existent mock
# mock_get_search_term_widget.return_value = True  # DELETE THIS LINE

The test decorators only include mocks for get_added_to_cart_widget, get_csat_ai_widget, get_nps_ai_widget, get_csat_human_widget, get_nps_human_widget, get_custom_widgets, and get_crosstab_widgets. There is no get_search_term_widget function being patched.

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

…te tests

- Integrated the get_added_to_cart_widget function into the ConversationsReportService.
- Updated unit tests to include the added to cart widget, ensuring proper functionality and coverage.
- Added unit tests for the get_added_to_cart_worksheet method, covering scenarios with both populated and empty data.
- Implemented validation for missing agent UUID configuration, ensuring proper error handling.
- Updated existing tests to include the new "ADDED_TO_CART" section in report configurations.
@kallilsouza kallilsouza merged commit 569e5d4 into main Jun 11, 2026
2 checks passed
@kallilsouza kallilsouza deleted the feature/added-to-cart-metrics-report branch June 11, 2026 21:42
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.

3 participants