Skip to content

[ADD] helpdesk_mgmt_stock_purchase_origin: Pre-fill purchase order field on helpdesk ticket from an incoming picking - #968

Open
nicolas-delbovier-acsone wants to merge 2 commits into
OCA:16.0from
acsone:16.0-add-helpdesk_mgmt_stock_purchase_origin
Open

[ADD] helpdesk_mgmt_stock_purchase_origin: Pre-fill purchase order field on helpdesk ticket from an incoming picking#968
nicolas-delbovier-acsone wants to merge 2 commits into
OCA:16.0from
acsone:16.0-add-helpdesk_mgmt_stock_purchase_origin

Conversation

@nicolas-delbovier-acsone

@nicolas-delbovier-acsone nicolas-delbovier-acsone commented Mar 13, 2026

Copy link
Copy Markdown

Depends on #875

…eld on helpdesk ticket from an incoming picking

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause

The test failure occurs because the action_view_helpdesk_tickets method in stock_picking.py attempts to access self.origin on a stock picking, but for incoming pickings created from a purchase order, self.origin may be None or not match the purchase order name exactly. This causes the search for the purchase order to return no results, and thus default_purchase_order_ids is not set in the action context.

2. Suggested Fix

In helpdesk_mgmt_stock_purchase_origin/models/stock_picking.py, line ~15, the code should check if self.origin is not None and not empty before performing the search. Also, consider using self.env['purchase.order'].search([('name', '=', self.origin)], limit=1) instead of search_read to simplify the logic and avoid unnecessary field fetching.

# File: helpdesk_mgmt_stock_purchase_origin/models/stock_picking.py
# Line ~15
if picking_type_code == "incoming" and self.origin:
    origin_po = self.env["purchase.order"].search([("name", "=", self.origin)], limit=1)
    if origin_po:
        action["context"].update(
            {
                "default_purchase_order_ids": [Command.set([origin_po.id])]
            }
        )

3. Additional Code Issues

  • Redundant search_read usage: The code uses search_read to fetch only the id field, which is inefficient. It should use search directly.
  • No fallback handling: If self.origin does not match a purchase order name, the code silently does nothing. It would be better to log or handle this case explicitly.

4. Test Improvements

The current test only covers the happy path. Add the following test cases:

  • Test with no origin: Ensure that no default_purchase_order_ids is set when self.origin is None or empty.
  • Test with non-matching origin: Ensure that no default_purchase_order_ids is set when self.origin does not correspond to any purchase order.
  • Test with outgoing picking: Ensure that the code does not modify the action context for non-incoming pickings.
# In test_helpdesk_mgmt_stock_purchase_origin.py
def test_action_view_helpdesk_tickets_no_origin(self):
    # Create an incoming picking with no origin
    picking = self.env["stock.picking"].create({
        "picking_type_id": self.env.ref("stock.picking_type_in").id,
        "origin": None,
    })
    action = picking.action_view_helpdesk_tickets()
    self.assertNotIn("default_purchase_order_ids", action["context"])

def test_action_view_helpdesk_tickets_non_matching_origin(self):
    # Create an incoming picking with a non-existent origin
    picking = self.env["stock.picking"].create({
        "picking_type_id": self.env.ref("stock.picking_type_in").id,
        "origin": "NonExistentPO",
    })
    action = picking.action_view_helpdesk_tickets()
    self.assertNotIn("default_purchase_order_ids", action["context"])

def test_action_view_helpdesk_tickets_outgoing_picking(self):
    # Ensure outgoing pickings don't affect the context
    picking = self.env["stock.picking"].create({
        "picking_type_id": self.env.ref("stock.picking_type_out").id,
        "origin": self.po.name,
    })
    action = picking.action_view_helpdesk_tickets()
    self.assertNotIn("default_purchase_order_ids", action["context"])

These tests align with OCA's patterns using TransactionCase and cover edge cases to ensure robustness.


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:

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

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Aug 2, 2026

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok

@github-actions github-actions Bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants