[ADD] helpdesk_mgmt_stock_sale_origin: Pre-fill sale order field on helpdesk ticket created from an outgoing picking#969
Conversation
…elpdesk ticket created from an outgoing picking
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failure is caused by a database connection error (Connection to the database failed) during the Odoo startup, which prevents the test suite from running. This is likely due to misconfiguration or an invalid database URL in the test environment setup.
2. Suggested Fix
Ensure the database connection parameters in the test environment are correctly configured. Specifically, verify that:
- The
databaseparameter in the Odoo configuration file or environment variables points to a valid, accessible PostgreSQL instance. - The
db_useranddb_passwordare correctly set if authentication is required. - The
test-requirements.txtdoes not introduce conflicting dependencies or incorrect references (e.g.,odoo-addon-helpdesk-mgmt-stock @ git+https://github.com/OCA/helpdesk.git@refs/pull/875/head#subdirectory=setup/helpdesk_mgmt_stockmay be unstable or invalid).
3. Additional Code Issues
-
In
stock_picking.py: Thesearch_readcall is inefficient and potentially redundant. It can be simplified to a directsearchif only theidis needed:origin_so = self.env["sale.order"].search([("name", "=", self.origin)], limit=1) if origin_so: action["context"].update({ "default_sale_order_ids": [Command.set([origin_so.id])] })
This avoids fetching unnecessary data and improves performance.
-
In
test_helpdesk_mgmt_stock_sale_origin.py: The test usesCommand.set()which is correct, but it's better to ensure thatself.sois properly initialized with anamefield that matchesself.origin. Currently,sale.order'snamefield is auto-generated (e.g.,SO001), soself.originin the picking may not matchself.so.name. This could cause the test to fail.
4. Test Improvements
To improve test coverage and robustness, add the following test cases:
- Test with no matching sale order: Ensure
action["context"]is not modified whenself.origindoes not match any sale order. - Test with
self.originbeingNoneor empty: Ensure no error occurs in such edge cases. - Test with multiple sale orders having the same
name: Ensure only one is picked (or behavior is well-defined). - Use
SavepointCasefor more complex scenarios where data isolation is required, as per OCA patterns.
Example:
def test_action_view_helpdesk_tickets_no_origin(self):
# Test with no origin
self.out_pick.origin = False
action = self.out_pick.action_view_helpdesk_tickets()
self.assertNotIn("default_sale_order_ids", action["context"])
def test_action_view_helpdesk_tickets_no_matching_so(self):
# Test with non-matching origin
self.out_pick.origin = "NONEXISTENT"
action = self.out_pick.action_view_helpdesk_tickets()
self.assertNotIn("default_sale_order_ids", action["context"])These tests ensure that the logic handles edge cases gracefully and matches OCA's testing standards.
Reciprocal Review Request
Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):
My open PRs across OCA:
- server-tools#3554 [MIG] datetime_formatter: Migration to 18.0
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
Reviewing each other's work helps the whole community move forward. Thank you!
Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b
Depends on #875