From bd6cb74bb6fec61395a2be30df3a928b0a3a9dd7 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Tue, 1 Oct 2024 09:56:29 +0200 Subject: [PATCH] [IMP] helpdesk_mgmt_sale: Access tickets from the order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the widget ‘many2many_tags’ it is not possible to click on a ticket in the order and access the form. By adding a smartbutton it is possible to access the list of tickets in the order and also consult the form for each one of them. TT50683 --- helpdesk_mgmt_sale/models/sale_order.py | 10 +++++++++- helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py | 4 ++-- helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml | 9 ++++++++- helpdesk_mgmt_sale/views/sale_order_views.xml | 11 +++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/helpdesk_mgmt_sale/models/sale_order.py b/helpdesk_mgmt_sale/models/sale_order.py index 23d0a7a3c3..b1e89a4605 100644 --- a/helpdesk_mgmt_sale/models/sale_order.py +++ b/helpdesk_mgmt_sale/models/sale_order.py @@ -1,7 +1,15 @@ -from odoo import fields, models +from odoo import api, fields, models class SaleOrder(models.Model): _inherit = "sale.order" ticket_ids = fields.Many2many("helpdesk.ticket") + ticket_count = fields.Integer( + string="Tickets Count", compute="_compute_ticket_count", store=True + ) + + @api.depends("ticket_ids") + def _compute_ticket_count(self): + for order in self: + order.ticket_count = len(order.ticket_ids) diff --git a/helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py b/helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py index b3523de33b..a8946e29b9 100644 --- a/helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py @@ -20,13 +20,13 @@ def setUpClass(cls): cls.sale_order_1 = cls.env["sale.order"].create( { "partner_id": cls.partner.id, - "ticket_ids": [(6, 0, [cls.ticket.id])], # Adaptación a Many2many + "ticket_ids": [(6, 0, [cls.ticket.id])], } ) cls.sale_order_2 = cls.env["sale.order"].create( { "partner_id": cls.partner.id, - "ticket_ids": [(6, 0, [cls.ticket.id])], # Adaptación a Many2many + "ticket_ids": [(6, 0, [cls.ticket.id])], } ) diff --git a/helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml b/helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml index 8ad5f9e9bd..7f4c831be7 100644 --- a/helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml +++ b/helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml @@ -15,11 +15,18 @@ name="action_view_sale_orders" type="object" class="oe_stat_button" - icon="fa-ticket" + icon="fa-dollar" > + + Tickets + helpdesk.ticket + tree,form + [('sale_order_ids', 'in', active_id)] + {'default_sale_order_ids': [(4, active_id)]} + diff --git a/helpdesk_mgmt_sale/views/sale_order_views.xml b/helpdesk_mgmt_sale/views/sale_order_views.xml index 2de013adbe..f5a4e1e74d 100644 --- a/helpdesk_mgmt_sale/views/sale_order_views.xml +++ b/helpdesk_mgmt_sale/views/sale_order_views.xml @@ -15,6 +15,17 @@ + + +