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 Jul 14, 2023
1 parent 2786b7e commit 1330f75
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 89 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
34 changes: 22 additions & 12 deletions helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ def setUpClass(cls):
)

def generate_timesheet(self, ticket, hours=1.0, days_ago=0):
return self.env["account.analytic.line"].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,
}
)
return

def generate_ticket(self):
return self.env["helpdesk.ticket"].create(
Expand All @@ -46,18 +37,37 @@ 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().create(
{
"amount": 0,
"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().create(
{
"amount": 0,
"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
18 changes: 6 additions & 12 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<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>
Expand Down Expand Up @@ -70,6 +66,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 +77,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 +86,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 +98,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 +108,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 +217,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 +228,7 @@
string="Start work"
tabindex="-1"
type="object"
groups="hr_timesheet.group_hr_timesheet_user"
/>
<a
name="button_end_work"
Expand All @@ -245,6 +238,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
26 changes: 13 additions & 13 deletions helpdesk_mgmt_timesheet/wizards/hr_timesheet_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class HrTimesheetSwitch(models.TransientModel):
def _closest_suggestion(self):
"""Allow searching best suggestion by helpdesk.ticket."""
result = super()._closest_suggestion()
try:
if not result and self.env.context["active_model"] == "helpdesk.ticket":
return self.env["account.analytic.line"].search(
[
("user_id", "=", self.env.user.id),
("ticket_id", "=", self.env.context["active_id"]),
],
order="date_time DESC",
limit=1,
)
except KeyError:
# If I don't know where's the user, I don't know what to suggest
pass
if (
not result
and self.env.context["active_model"] == "helpdesk.ticket"
and self.env.user
):
return self.env["account.analytic.line"].search(
[
("user_id", "=", self.env.user.id),
("ticket_id", "=", self.env.context["active_id"]),
],
order="date_time DESC",
limit=1,
)
return result
6 changes: 6 additions & 0 deletions setup/helpdesk_mgmt_timesheet/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 1330f75

Please sign in to comment.