Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion helpdesk_mgmt_sale/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models
from odoo import _, api, fields, models


class HelpdeskTicket(models.Model):
Expand All @@ -23,3 +23,17 @@ def action_view_sale_orders(self):
"default_partner_id": self.partner_id.id,
}
return action

@api.model_create_multi
def create(self, vals_list):
tickets = super().create(vals_list)
if self.env.context.get("from_sale_order"):
# only one ticket is possible here
for sale in tickets.sale_order_ids:
sale.message_post(
body=_(
f"Helpdesk Ticket {tickets.name} created by {self.env.user.name}"
)
)

return tickets
19 changes: 19 additions & 0 deletions helpdesk_mgmt_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ class SaleOrder(models.Model):
def _compute_ticket_count(self):
for order in self:
order.ticket_count = len(order.ticket_ids)

def action_create_helpdesk_ticket(self):
self.ensure_one()

return {
"type": "ir.actions.act_window",
"name": "Create Helpdesk ticket",
"res_model": "helpdesk.ticket",
"view_mode": "form",
"view_id": self.env.ref("helpdesk_mgmt.ticket_view_form").id,
"target": "new",
"context": {
"default_partner_id": self.partner_id.id,
"default_name": self.name,
"default_origin": self.name,
"default_sale_order_ids": [(4, self.id)],
"from_sale_order": True,
},
}
3 changes: 3 additions & 0 deletions helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<field string="Sale Orders" name="so_count" widget="statinfo" />
</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!

</field>
</field>
</record>
<record id="action_helpdesk_ticket" model="ir.actions.act_window">
Expand Down
8 changes: 8 additions & 0 deletions helpdesk_mgmt_sale/views/sale_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<field string="Tickets" name="ticket_count" widget="statinfo" />
</button>
</xpath>
<xpath expr="//header" position="inside">
<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

class="btn btn-primary"
/>
</xpath>
</field>
</record>
</odoo>