feat: implement added to cart worksheet functionality#431
Merged
Conversation
- 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.
elitonzky
approved these changes
Jun 9, 2026
MarcusviniciusLsantos
approved these changes
Jun 9, 2026
…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.
…e/added-to-cart-metrics-report
…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 |
There was a problem hiding this comment.
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 LINEThe 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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
ADDED_TO_CARTsection 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:ADDED_TO_CARTvalue inConversationsReportSections.get_added_to_cart_worksheetinBaseConversationsReportServiceand its concrete implementation inConversationsReportService.CONVERSATIONS_METRICS_ADDED_TO_CART_AGENT_UUID(required) andCONVERSATIONS_METRICS_ADDED_TO_CART_KEY(event key used to filter datalake events).AddedToCartAgentUUIDNotConfiguredErrorraised when the agent UUID is missing.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