Skip to content

[16.0][IMP] helpdesk_mgmt_sale: add button create ticket and display sales#947

Open
matthieusaison wants to merge 4 commits intoOCA:16.0from
akretion:16-imp-helpdesk_mgmt_sale_create_ticket
Open

[16.0][IMP] helpdesk_mgmt_sale: add button create ticket and display sales#947
matthieusaison wants to merge 4 commits intoOCA:16.0from
akretion:16-imp-helpdesk_mgmt_sale_create_ticket

Conversation

@matthieusaison
Copy link
Copy Markdown

add button to create a ticket with value of active sale order.
display and default filled sale_order_ids.

@matthieusaison matthieusaison force-pushed the 16-imp-helpdesk_mgmt_sale_create_ticket branch from b7d8b33 to 4647bf4 Compare February 18, 2026 11:41
@CristianoMafraJunior
Copy link
Copy Markdown
Member

@matthieusaison Can you increase the test coverage?

<button
name="action_create_helpdesk_ticket"
type="object"
string="Créer un ticket"
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.

Text must be in english and add a translation to your language.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, sorry it's a mistake, I fix this in my last commit

</button>
</xpath>
<field name="channel_id" position="after">
<field name="sale_order_ids" widget="many2many_tags" />
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.

If sale orders are already displayed in the smart button, what is the need to add it here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

When you create a ticket from sale, you may need to add an other sale linked. And if you create ticket from helpdesk menu, you may need to link to sale directly.

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, I see your point of view. It seems strange to me to see duplicate data about sale orders in both the field and the button. However, it is true that from the button it is not possible to add existing sale orders, only to create a new one. Anyway, LGTM!

@matthieusaison matthieusaison changed the title [IMP] helpdesk_mgmt_sale: add button create ticket and display sales [16.0][IMP] helpdesk_mgmt_sale: add button create ticket and display sales Feb 24, 2026
Copy link
Copy Markdown
Contributor

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

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

LGTM!

@pedrobaeza pedrobaeza added this to the 16.0 milestone Feb 25, 2026
Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Sorry, I don't think this is the way, but to pass in the existing smart-button the default_... context key for using it when pressing "Create" button inside ticket list.

Copy link
Copy Markdown

@marcos-mendez marcos-mendez left a comment

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 is due to a database connection error (Connection to the database failed) during the Odoo server startup, not directly caused by the code changes in the PR. This is likely a transient infrastructure issue in the test environment (e.g., Runboat).


2. Suggested Fix

No functional code fix is needed for the test failure itself, but to prevent future failures, ensure that:

  • The test environment has a stable database connection.
  • The Odoo server is started with proper database configuration.

However, in terms of code correctness:

  • The create method in helpdesk.ticket correctly uses self.env.context.get("from_sale_order") and is safe.
  • The action_create_helpdesk_ticket method in sale.order correctly sets the context with from_sale_order: True.

3. Additional Code Issues

  • Missing @api.model decorator: In helpdesk.ticket.create, the method create is correctly defined with @api.model_create_multi, which is fine. However, the method should not be using self inside the loop as self refers to the class, not the instance. This is a potential bug.

    Fix:

    # Replace:
    for sale in tickets.sale_order_ids:
        sale.message_post(...)
    # With:
    for ticket in tickets:
        for sale in ticket.sale_order_ids:
            sale.message_post(...)

    File: helpdesk_mgmt_sale/models/helpdesk_ticket.py
    Lines: 29–36


4. Test Improvements

The existing tests are good, but can be improved to better cover edge cases and ensure robustness:

Suggested Tests:

  1. Test with multiple sale orders:

    • Create a ticket with multiple sale_order_ids.
    • Ensure messages are posted for each sale order.
  2. Test with empty sale orders list:

    • Create a ticket without any sale_order_ids.
    • Ensure no message is posted.
  3. Test action_create_helpdesk_ticket with different user contexts:

    • Use with_user() to test behavior with different users.
    • Ensure correct default_partner_id and default_name are set.
  4. Use SavepointCase for transaction safety:

    • The current BaseCommon (likely TransactionCase) is acceptable, but for better test isolation, consider using SavepointCase for tests involving message_post.

OCA Testing Patterns:

  • Use SavepointCase for tests involving message_post or complex data changes.
  • Use tagged to mark tests for specific scenarios (e.g., @tagged('post_install') for context-based logic).

Summary

Item Status
Root Cause Database connection issue (environmental)
Code Bug self used instead of ticket in loop (line 30)
Test Coverage Good, but can be improved with edge cases
Suggested Fix Replace self with ticket in message posting loop

Let me know if you'd like a patch for the bug fix.


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

…ale-create_ticket_custom_msg

[16.0][IMP] helpdesk_mgmt_sale: make the ticket creation message overridable
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.

7 participants