Skip to content

Commit

Permalink
[MIG] helpdesk_mgmt_timesheet: Migration 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aromera committed Aug 2, 2023
1 parent 2786b7e commit 2ee2806
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 95 deletions.
2 changes: 1 addition & 1 deletion helpdesk_mgmt_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"website": "https://github.com/OCA/helpdesk",
"license": "AGPL-3",
"category": "After-Sales",
"version": "14.0.1.0.1",
"version": "16.0.1.0.0",
"depends": [
"helpdesk_mgmt_project",
"hr_timesheet",
Expand Down
70 changes: 34 additions & 36 deletions helpdesk_mgmt_timesheet/demo/helpdesk_mgmt_timesheet_demo.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="project_1" model="project.project">
<field name="name">Helpdesk general project</field>
</record>
<record id="project_task_1" model="project.task">
<field name="name">Helpdesk general task</field>
<field name="project_id" ref="project_1" />
</record>
<record id="helpdesk_mgmt.helpdesk_team_2" model="helpdesk.ticket.team">
<field name="allow_timesheet" eval="True" />
<field name="default_project_id" ref="project_1" />
</record>
<record id="helpdesk_mgmt.helpdesk_ticket_1" model="helpdesk.ticket">
<field name="team_id" ref="helpdesk_mgmt.helpdesk_team_2" />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="planned_hours" eval="5" />
</record>
<record id="helpdesk_ticket_1_timesheet_1" model="account.analytic.line">
<field name="ticket_id" ref="helpdesk_mgmt.helpdesk_ticket_1" />
<field name="name">Initial analysis</field>
<field name="user_id" ref='base.user_admin' />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="unit_amount" eval="2.5" />
</record>
<record id="helpdesk_ticket_1_timesheet_2" model="account.analytic.line">
<field name="ticket_id" ref="helpdesk_mgmt.helpdesk_ticket_1" />
<field name="name">Resolution</field>
<field name="user_id" ref='base.user_admin' />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="unit_amount" eval="2" />
</record>
</data>
<odoo noupdate="1">
<record id="project_1" model="project.project">
<field name="name">Helpdesk general project</field>
</record>
<record id="project_task_1" model="project.task">
<field name="name">Helpdesk general task</field>
<field name="project_id" ref="project_1" />
</record>
<record id="helpdesk_mgmt.helpdesk_team_2" model="helpdesk.ticket.team">
<field name="allow_timesheet" eval="True" />
<field name="default_project_id" ref="project_1" />
</record>
<record id="helpdesk_mgmt.helpdesk_ticket_1" model="helpdesk.ticket">
<field name="team_id" ref="helpdesk_mgmt.helpdesk_team_2" />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="planned_hours" eval="5" />
</record>
<record id="helpdesk_ticket_1_timesheet_1" model="account.analytic.line">
<field name="ticket_id" ref="helpdesk_mgmt.helpdesk_ticket_1" />
<field name="name">Initial analysis</field>
<field name="user_id" ref='base.user_admin' />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="unit_amount" eval="2.5" />
</record>
<record id="helpdesk_ticket_1_timesheet_2" model="account.analytic.line">
<field name="ticket_id" ref="helpdesk_mgmt.helpdesk_ticket_1" />
<field name="name">Resolution</field>
<field name="user_id" ref='base.user_admin' />
<field name="project_id" ref="project_1" />
<field name="task_id" ref="project_task_1" />
<field name="unit_amount" eval="2" />
</record>
</odoo>
6 changes: 2 additions & 4 deletions helpdesk_mgmt_timesheet/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ def _relation_with_timesheet_line(self):
string="Allow Timesheet",
related="team_id.allow_timesheet",
)
planned_hours = fields.Float(string="Planned Hours", tracking=True)
planned_hours = fields.Float(tracking=True)
progress = fields.Float(
compute="_compute_progress_hours",
group_operator="avg",
store=True,
string="Progress",
)
remaining_hours = fields.Float(
compute="_compute_progress_hours",
readonly=True,
store=True,
string="Remaining Hours",
)
timesheet_ids = fields.One2many(
comodel_name="account.analytic.line",
inverse_name="ticket_id",
string="Timesheet",
)
total_hours = fields.Float(
compute="_compute_total_hours", readonly=True, store=True, string="Total Hours"
compute="_compute_total_hours", readonly=True, store=True
)
last_timesheet_activity = fields.Date(
compute="_compute_last_timesheet_activity",
Expand Down
4 changes: 1 addition & 3 deletions helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
class HelpdeskTicketTeam(models.Model):
_inherit = "helpdesk.ticket.team"

allow_timesheet = fields.Boolean(
string="Allow Timesheet",
)
allow_timesheet = fields.Boolean()
default_project_id = fields.Many2one(
comodel_name="project.project",
string="Default Project",
Expand Down
2 changes: 2 additions & 0 deletions helpdesk_mgmt_timesheet/report/report_timesheet_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
groups="helpdesk_mgmt.group_helpdesk_user"
/>
</xpath>
</template>
<template id="timesheet_table" inherit_id="hr_timesheet.timesheet_table">
<xpath expr="//table[hasclass('table-sm')]/thead/tr/th[3]" position="after">
<th
t-if="show_ticket"
Expand Down
45 changes: 34 additions & 11 deletions helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ def setUpClass(cls):
"default_project_id": cls.project_id.id,
}
)

def generate_timesheet(self, ticket, hours=1.0, days_ago=0):
return self.env["account.analytic.line"].create(
# users
cls.user_employee = cls.env["res.users"].create(
{
"amount": 0,
"date": fields.Date.today() - timedelta(days=days_ago),
"name": "Test Timesheet",
"unit_amount": hours,
"ticket_id": ticket.id,
"project_id": ticket.project_id.id,
"name": "User Employee",
"login": "user_employee",
"email": "[email protected]",
"groups_id": [
(6, 0, [cls.env.ref("hr_timesheet.group_hr_timesheet_user").id])
],
}
)
# employees
cls.empl_employee = cls.env["hr.employee"].create(
{
"name": "User Empl Employee",
"user_id": cls.user_employee.id,
}
)

Expand All @@ -46,18 +52,35 @@ def generate_ticket(self):
)

def test_helpdesk_mgmt_timesheet(self):
Timesheet = self.env["account.analytic.line"]
ticket = self.generate_ticket()
self.assertFalse(ticket.last_timesheet_activity)
ticket._onchange_team_id()
self.assertEqual(ticket.project_id.id, self.team_id.default_project_id.id)
ticket.planned_hours = 5
days_ago = 1
timesheet1 = self.generate_timesheet(ticket, hours=2, days_ago=days_ago)
timesheet1 = Timesheet.with_user(self.user_employee).create(
{
"date": fields.Date.today() - timedelta(days=days_ago),
"name": "Test Timesheet",
"unit_amount": 2,
"ticket_id": ticket.id,
"project_id": ticket.project_id.id,
}
)
self.assertEqual(
ticket.last_timesheet_activity,
fields.Date.today() - timedelta(days=days_ago),
)
timesheet2 = self.generate_timesheet(ticket, hours=1)
timesheet2 = Timesheet.with_user(self.user_employee).create(
{
"date": fields.Date.today() - timedelta(days=0),
"name": "Test Timesheet",
"unit_amount": 1,
"ticket_id": ticket.id,
"project_id": ticket.project_id.id,
}
)
self.assertEqual(ticket.last_timesheet_activity, fields.Date.today())
self.assertEqual(
ticket.total_hours, timesheet1.unit_amount + timesheet2.unit_amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datetime import datetime, timedelta

from odoo import exceptions, fields
from odoo import exceptions
from odoo.tests import common


Expand Down Expand Up @@ -92,10 +92,7 @@ def test_ticket_time_control_flow(self):
self.assertEqual(self.ticket.show_time_control, "start")
start_action = self.ticket.button_start_work()
wizard = self._create_wizard(start_action, self.ticket_line)
self.assertFalse(wizard.amount)
self.assertLessEqual(wizard.date_time, datetime.now())
self.assertLessEqual(wizard.date, fields.Date.context_today(wizard))
self.assertFalse(wizard.unit_amount)
self.assertEqual(wizard.account_id, self.ticket.project_id.analytic_account_id)
self.assertEqual(wizard.employee_id, self.env.user.employee_ids)
self.assertEqual(wizard.name, self.ticket_line.name)
Expand Down
22 changes: 7 additions & 15 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@
<field name="name">helpdesk.ticket.view.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk_mgmt.ticket_view_tree" />
<field
name="groups_id"
eval="[(6, 0, [ref('hr_timesheet.group_hr_timesheet_user')])]"
/>
<field name="arch" type="xml">
<xpath expr="." position="attributes">
<attribute name="decoration-danger">remaining_hours &lt; 0</attribute>
</xpath>
<field name="last_stage_update" position="after">
<field
name="planned_hours"
Expand All @@ -56,6 +49,7 @@
<field
name="remaining_hours"
widget="float_time"
decoration-danger="remaining_hours &lt; 0"
groups="hr_timesheet.group_hr_timesheet_user"
/>
</field>
Expand All @@ -70,6 +64,7 @@
icon="fa-play-circle text-success"
attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
class="oe_stat_button"
groups="hr_timesheet.group_hr_timesheet_user"
/>
<button
name="button_end_work"
Expand All @@ -80,6 +75,7 @@
icon="fa-stop-circle text-warning"
attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
class="oe_stat_button"
groups="hr_timesheet.group_hr_timesheet_user"
/>
</tree>
</field>
Expand All @@ -88,10 +84,6 @@
<field name="name">timesheet.helpdesk.ticket.form.view</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk_mgmt.ticket_view_form" />
<field
name="groups_id"
eval="[(6, 0, [ref('hr_timesheet.group_hr_timesheet_user')])]"
/>
<field name="priority" eval="20" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
Expand All @@ -104,6 +96,7 @@
icon="fa-play-circle text-success"
attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
class="oe_stat_button"
groups="hr_timesheet.group_hr_timesheet_user"
/>
<button
name="button_end_work"
Expand All @@ -113,6 +106,7 @@
icon="fa-stop-circle text-warning"
attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
class="oe_stat_button"
groups="hr_timesheet.group_hr_timesheet_user"
/>
</div>
<xpath expr="//field[@name='partner_email']" position="after">
Expand Down Expand Up @@ -221,10 +215,6 @@
>helpdesk.ticket.kanban (in helpdesk_mgmt_timesheet_time_control)</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk_mgmt.view_helpdesk_ticket_kanban" />
<field
name="groups_id"
eval="[(6, 0, [ref('hr_timesheet.group_hr_timesheet_user')])]"
/>
<field name="arch" type="xml">
<xpath expr="//*[hasclass('oe_kanban_bottom_left')]" position="inside">
<field name="show_time_control" invisible="1" />
Expand All @@ -236,6 +226,7 @@
string="Start work"
tabindex="-1"
type="object"
groups="hr_timesheet.group_hr_timesheet_user"
/>
<a
name="button_end_work"
Expand All @@ -245,6 +236,7 @@
string="Stop work"
tabindex="-1"
type="object"
groups="hr_timesheet.group_hr_timesheet_user"
/>
</xpath>
</field>
Expand Down
23 changes: 15 additions & 8 deletions helpdesk_mgmt_timesheet/views/hr_timesheet_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<record id="hr_timesheet_line_search" model="ir.ui.view">
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_search" />
<field
name="groups_id"
eval="[(4, ref('helpdesk_mgmt.group_helpdesk_user'))]"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="ticket_id" />
<field name="ticket_partner_id" />
<field name="ticket_id" groups="helpdesk_mgmt.group_helpdesk_user" />
<field
name="ticket_partner_id"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
</xpath>
<xpath expr="//filter[@name='month']" position="before">
<filter
name="ticket"
string="With ticket"
domain="[('ticket_id', '!=', False)]"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
<separator />
</xpath>
Expand All @@ -26,12 +26,14 @@
name="groupby_ticket_partner"
domain="[]"
context="{'group_by':'ticket_partner_id'}"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
<filter
string="Ticket"
name="groupby_ticket"
domain="[]"
context="{'group_by':'ticket_id'}"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
</xpath>
</field>
Expand All @@ -41,8 +43,11 @@
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="ticket_partner_id" />
<field name="ticket_id" />
<field
name="ticket_partner_id"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
<field name="ticket_id" groups="helpdesk_mgmt.group_helpdesk_user" />
</xpath>
</field>
</record>
Expand All @@ -54,10 +59,12 @@
<field
name="ticket_id"
required="context.get('ticket_required', False)"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
<field
name="ticket_partner_id"
attrs="{'invisible': [('ticket_id', '=', False)]}"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
</field>
</field>
Expand Down
Loading

0 comments on commit 2ee2806

Please sign in to comment.