diff --git a/README.md b/README.md
index ea09ba914d..c7b24d31a4 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[helpdesk_mgmt](helpdesk_mgmt/) | 19.0.1.1.0 | | Helpdesk
-[helpdesk_product](helpdesk_product/) | 19.0.1.0.0 | | Add the option to select product in the tickets.
+[helpdesk_product](helpdesk_product/) | 19.0.1.1.0 | | Add the option to select product in the tickets.
[helpdesk_type](helpdesk_type/) | 19.0.1.0.0 | | Add a type to your tickets
[//]: # (end addons)
diff --git a/helpdesk_product/README.rst b/helpdesk_product/README.rst
index ff36f2476d..614e7d1ed1 100644
--- a/helpdesk_product/README.rst
+++ b/helpdesk_product/README.rst
@@ -11,7 +11,7 @@ Helpdesk Product
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:50b627b43f4db5e3056ce7640b144b1608c52a100c6a0505ba0f4a1f9cd64144
+ !! source digest: sha256:871dc4aaee4934cf5c8c6d2689ad675d01f2799c9bb6154efda0102cd81231c3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -32,7 +32,8 @@ Helpdesk Product
|badge1| |badge2| |badge3| |badge4| |badge5|
-This module adds the option to select product in the helpdesk tickets.
+This module adds the option to select product in the helpdesk tickets
+and view tickets related to products.
**Table of contents**
@@ -64,6 +65,10 @@ Contributors
- Maria Buscallà
+- `Tecnativa `__:
+
+ - David Bañón Gil
+
Maintainers
-----------
diff --git a/helpdesk_product/__manifest__.py b/helpdesk_product/__manifest__.py
index acd20c79a6..e1e108378b 100644
--- a/helpdesk_product/__manifest__.py
+++ b/helpdesk_product/__manifest__.py
@@ -2,7 +2,7 @@
"name": "Helpdesk Product",
"summary": "Add the option to select product in the tickets.",
"author": "ForgeFlow, Odoo Community Association (OCA)",
- "version": "19.0.1.0.0",
+ "version": "19.0.1.1.0",
"license": "AGPL-3",
"category": "After-Sales",
"website": "https://github.com/OCA/helpdesk",
diff --git a/helpdesk_product/i18n/helpdesk_product.pot b/helpdesk_product/i18n/helpdesk_product.pot
index b315829c05..b1449edaeb 100644
--- a/helpdesk_product/i18n/helpdesk_product.pot
+++ b/helpdesk_product/i18n/helpdesk_product.pot
@@ -31,6 +31,7 @@ msgstr ""
#. module: helpdesk_product
#: model:ir.model.fields,field_description:helpdesk_product.field_helpdesk_ticket__display_name
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_product__display_name
#: model:ir.model.fields,field_description:helpdesk_product.field_product_template__display_name
msgid "Display Name"
msgstr ""
@@ -42,11 +43,20 @@ msgstr ""
#. module: helpdesk_product
#: model:ir.model,name:helpdesk_product.model_helpdesk_ticket
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_product__helpdesk_ticket_ids
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_template__helpdesk_ticket_ids
msgid "Helpdesk Ticket"
msgstr ""
+#. module: helpdesk_product
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_product__helpdesk_ticket_count
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_template__helpdesk_ticket_count
+msgid "Helpdesk Ticket Count"
+msgstr ""
+
#. module: helpdesk_product
#: model:ir.model.fields,field_description:helpdesk_product.field_helpdesk_ticket__id
+#: model:ir.model.fields,field_description:helpdesk_product.field_product_product__id
#: model:ir.model.fields,field_description:helpdesk_product.field_product_template__id
msgid "ID"
msgstr ""
@@ -63,12 +73,22 @@ msgstr ""
msgid "Product Related"
msgstr ""
+#. module: helpdesk_product
+#: model:ir.model,name:helpdesk_product.model_product_product
+msgid "Product Variant"
+msgstr ""
+
#. module: helpdesk_product
#: model:ir.actions.act_window,name:helpdesk_product.product_template_action_helpdesk
#: model:ir.ui.menu,name:helpdesk_product.action_menu_view_products
msgid "Products"
msgstr ""
+#. module: helpdesk_product
+#: model_terms:ir.ui.view,arch_db:helpdesk_product.product_view_template
+msgid "Tickets"
+msgstr ""
+
#. module: helpdesk_product
#: model_terms:ir.actions.act_window,help:helpdesk_product.product_template_action_helpdesk
msgid ""
diff --git a/helpdesk_product/models/helpdesk_ticket.py b/helpdesk_product/models/helpdesk_ticket.py
index 26c91e2dbc..5c7775c50e 100644
--- a/helpdesk_product/models/helpdesk_ticket.py
+++ b/helpdesk_product/models/helpdesk_ticket.py
@@ -4,4 +4,8 @@
class HelpdeskTicket(models.Model):
_inherit = "helpdesk.ticket"
- product_id = fields.Many2one(string="Product", comodel_name="product.product")
+ product_id = fields.Many2one(
+ string="Product",
+ comodel_name="product.product",
+ domain=[("ticket_active", "=", True)],
+ )
diff --git a/helpdesk_product/models/product.py b/helpdesk_product/models/product.py
index fa4ec4f15a..586ef95648 100644
--- a/helpdesk_product/models/product.py
+++ b/helpdesk_product/models/product.py
@@ -1,9 +1,60 @@
-from odoo import fields, models
+from odoo import api, fields, models
-class Product(models.Model):
+class ProductTemplate(models.Model):
_inherit = "product.template"
- ticket_active = fields.Boolean(
- "Available for Helpdesk Tickets", default=True, required=True
+ ticket_active = fields.Boolean("Available for Helpdesk Tickets", default=True)
+ helpdesk_ticket_ids = fields.One2many(
+ related="product_variant_ids.helpdesk_ticket_ids"
)
+ helpdesk_ticket_count = fields.Integer(compute="_compute_helpdesk_ticket_count")
+
+ @api.depends("helpdesk_ticket_ids")
+ def _compute_helpdesk_ticket_count(self):
+ for template in self:
+ template.helpdesk_ticket_count = len(template.helpdesk_ticket_ids)
+
+ def action_view_helpdesk_tickets(self, product=None):
+ product = product or self
+ product.ensure_one()
+ action = self.env["ir.actions.actions"]._for_xml_id(
+ "helpdesk_mgmt.helpdesk_ticket_action"
+ )
+ if product.helpdesk_ticket_count <= 1:
+ ticket = product.helpdesk_ticket_ids
+ product_id = False
+ if product.is_product_variant or len(product.product_variant_ids) == 1:
+ product_id = product.product_variant_id.id
+ action.update(
+ {
+ "res_id": ticket.id,
+ "views": [(False, "form")],
+ "context": {"default_product_id": product_id},
+ }
+ )
+ else:
+ action.update(
+ {
+ "domain": [("id", "in", product.helpdesk_ticket_ids.ids)],
+ }
+ )
+ return action
+
+
+class ProductProduct(models.Model):
+ _inherit = "product.product"
+
+ helpdesk_ticket_ids = fields.One2many(
+ comodel_name="helpdesk.ticket", inverse_name="product_id"
+ )
+ helpdesk_ticket_count = fields.Integer(compute="_compute_helpdesk_ticket_count")
+
+ @api.depends("helpdesk_ticket_ids")
+ def _compute_helpdesk_ticket_count(self):
+ for template in self:
+ template.helpdesk_ticket_count = len(template.helpdesk_ticket_ids)
+
+ def action_view_helpdesk_tickets(self):
+ self.ensure_one()
+ return self.product_tmpl_id.action_view_helpdesk_tickets(product=self)
diff --git a/helpdesk_product/readme/CONTRIBUTORS.md b/helpdesk_product/readme/CONTRIBUTORS.md
index 109df4a27e..2dfe37499b 100644
--- a/helpdesk_product/readme/CONTRIBUTORS.md
+++ b/helpdesk_product/readme/CONTRIBUTORS.md
@@ -1,2 +1,4 @@
- [ForgeFlow](https://www.forgeflow.com):
- Maria Buscallà \<\>
+- [Tecnativa](https://www.tecnativa.com):
+ - David Bañón Gil
diff --git a/helpdesk_product/readme/DESCRIPTION.md b/helpdesk_product/readme/DESCRIPTION.md
index 522e1c55dc..4cc1973e01 100644
--- a/helpdesk_product/readme/DESCRIPTION.md
+++ b/helpdesk_product/readme/DESCRIPTION.md
@@ -1 +1 @@
-This module adds the option to select product in the helpdesk tickets.
+This module adds the option to select product in the helpdesk tickets and view tickets related to products.
diff --git a/helpdesk_product/static/description/index.html b/helpdesk_product/static/description/index.html
index 757fa5c837..512fdcea69 100644
--- a/helpdesk_product/static/description/index.html
+++ b/helpdesk_product/static/description/index.html
@@ -372,10 +372,11 @@
Helpdesk Product
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:50b627b43f4db5e3056ce7640b144b1608c52a100c6a0505ba0f4a1f9cd64144
+!! source digest: sha256:871dc4aaee4934cf5c8c6d2689ad675d01f2799c9bb6154efda0102cd81231c3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
This module adds the option to select product in the helpdesk tickets.
+
This module adds the option to select product in the helpdesk tickets
+and view tickets related to products.