Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] helpdesk_mgmt_sale: Access tickets from the order #633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion helpdesk_mgmt_sale/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions helpdesk_mgmt_sale/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])],
}
)

Expand Down
9 changes: 8 additions & 1 deletion helpdesk_mgmt_sale/views/helpdesk_ticket_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
name="action_view_sale_orders"
type="object"
class="oe_stat_button"
icon="fa-ticket"
icon="fa-dollar"
>
<field string="Sale Orders" name="so_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>
<record id="action_helpdesk_ticket" model="ir.actions.act_window">
<field name="name">Tickets</field>
<field name="res_model">helpdesk.ticket</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('sale_order_ids', 'in', active_id)]</field>
<field name="context">{'default_sale_order_ids': [(4, active_id)]}</field>
</record>
</odoo>
11 changes: 11 additions & 0 deletions helpdesk_mgmt_sale/views/sale_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
<field name="ticket_ids" widget="many2many_tags" />
</group>
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<button
name="%(action_helpdesk_ticket)d"
type="action"
class="btn btn-primary"
icon="fa-ticket"
context="{'default_sale_order_ids': [(4, id)]}"
>
<field string="Tickets" name="ticket_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>
</odoo>
Loading