Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt_timesheet: filter tickets with activity on timesh…
Browse files Browse the repository at this point in the history
…eets today
  • Loading branch information
dalonsod committed Feb 2, 2021
1 parent 6f9719b commit 869d9dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
15 changes: 15 additions & 0 deletions helpdesk_mgmt_timesheet/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class HelpdeskTicket(models.Model):
store=True,
string='Total Hours'
)
last_timesheet_activity = fields.Date(
compute='_compute_last_timesheet_activity',
readonly=True,
store=True,
)

@api.depends('timesheet_ids.unit_amount')
def _compute_total_hours(self):
Expand Down Expand Up @@ -71,3 +76,13 @@ def _compute_progress_hours(self):
2
)
ticket.remaining_hours = ticket.planned_hours - ticket.total_hours

@api.depends('timesheet_ids.date')
def _compute_last_timesheet_activity(self):
for record in self:
record.last_timesheet_activity = (
record.timesheet_ids and
record.timesheet_ids.sorted(
key='date', reverse=True
)[0].date
) or False
17 changes: 13 additions & 4 deletions helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
###############################################################################
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from datetime import timedelta
import logging

from odoo.addons.helpdesk_mgmt.tests import test_helpdesk_ticket
from odoo import fields

Expand All @@ -22,10 +24,10 @@ def setUpClass(cls):
'default_project_id': cls.project_id.id,
})

def generate_timesheet(self, ticket, hours=1.0):
def generate_timesheet(self, ticket, hours=1.0, days_ago=0):
return self.env['account.analytic.line'].create({
'amount': 0,
'date': fields.Date.today(),
'date': fields.Date.today() - timedelta(days=days_ago),
'name': 'Test Timesheet',
'unit_amount': hours,
'ticket_id': ticket.id,
Expand All @@ -50,12 +52,19 @@ def generate_timesheet_without_ticket(self, project_id, hours=1.0):

def test_helpdesk_mgmt_timesheet(self):
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
timesheet1 = self.generate_timesheet(ticket, 2)
timesheet2 = self.generate_timesheet(ticket, 1)
days_ago = 1
timesheet1 = \
self.generate_timesheet(ticket, hours=2, days_ago=days_ago)
self.assertEqual(
ticket.last_timesheet_activity,
fields.Date.today() - timedelta(days=days_ago))
timesheet2 = self.generate_timesheet(ticket, hours=1)
self.assertEqual(ticket.last_timesheet_activity, fields.Date.today())
self.assertEqual(
ticket.total_hours,
timesheet1.unit_amount + timesheet2.unit_amount)
Expand Down
4 changes: 4 additions & 0 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
groups="hr_timesheet.group_hr_timesheet_user"
domain="[('remaining_hours', '<', 0)]"/>
<separator/>
<filter name="with_activity_today" string="With activity today"
groups="hr_timesheet.group_hr_timesheet_user"
domain="[('last_timesheet_activity', '=', datetime.datetime.today())]"/>
<separator/>
</filter>
</field>
</record>
Expand Down

0 comments on commit 869d9dd

Please sign in to comment.