Skip to content

Commit

Permalink
[ADD] helpdesk_mgmt_timesheet: work in progress
Browse files Browse the repository at this point in the history
Pending:
* demo data
* i18n
* README rebuild
  • Loading branch information
dalonsod committed Jul 28, 2020
1 parent 142535b commit c375341
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 106 deletions.
13 changes: 8 additions & 5 deletions helpdesk_mgmt_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
'author': 'Aresoltec Canarias, '
'Punt Sistemes, '
'SDi Soluciones Digitales, '
'Solvos, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/oca/helpdesk',
'website': 'https://github.com/OCA/helpdesk',
'license': 'AGPL-3',
'category': 'After-Sales',
'version': '12.0.1.0.0',
'depends': [
'helpdesk_mgmt',
'account',
'helpdesk_mgmt_project',
'hr_timesheet',
],
'data': [
'views/helpdesk_team.xml',
'views/helpdesk_ticket.xml',
'security/helpdesk_mgmt_timesheet_security.xml',
'views/helpdesk_team_view.xml',
'views/helpdesk_ticket_view.xml',
'views/hr_timesheet_view.xml',
]
}
2 changes: 1 addition & 1 deletion helpdesk_mgmt_timesheet/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###############################################################################
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from . import account_analytic_line
from . import hr_timesheet
from . import helpdesk_ticket
from . import helpdesk_ticket_team
13 changes: 0 additions & 13 deletions helpdesk_mgmt_timesheet/models/account_analytic_line.py

This file was deleted.

13 changes: 4 additions & 9 deletions helpdesk_mgmt_timesheet/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class HelpdeskTicket(models.Model):
string='Allow Timesheet',
related='team_id.allow_timesheet',
)
analytic_account_id = fields.Many2one(
comodel_name='account.analytic.account',
string='Analityc Account',
)
planned_hours = fields.Float(
string='Planned Hours',
track_visibility='onchange',
Expand Down Expand Up @@ -50,18 +46,17 @@ def impute_hours(self):
record.timesheet_ids.mapped('unit_amount')
)

@api.constrains('analytic_account_id')
def _constrains_account_timesheets(self):
@api.constrains('project_id')
def _constrains_project_timesheets(self):
for record in self:
record.timesheet_ids.update({
'account_id': record.analytic_account_id.id
'project_id': record.project_id.id
})

@api.onchange('team_id')
def _onchange_team_id(self):
for record in self:
record.analytic_account_id = \
record.team_id.default_analytic_account
record.project_id = record.team_id.default_project_id

@api.depends('planned_hours', 'total_hours')
def _compute_progress_hours(self):
Expand Down
14 changes: 7 additions & 7 deletions helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class HelpdeskTicketTeam(models.Model):
allow_timesheet = fields.Boolean(
string='Allow Timesheet',
)
default_analytic_account = fields.Many2one(
comodel_name='account.analytic.account',
string='Default Analytic Account',
default_project_id = fields.Many2one(
comodel_name='project.project',
string='Default Project',
)
reset_default_analytic_account = fields.Boolean(
string='Reset Analytic Account',
reset_default_project = fields.Boolean(
string='Reset Project',
)

@api.constrains('allow_timesheet')
def _constrains_allow_timesheet(self):
if not self.allow_timesheet:
self.default_analytic_account = False
self.default_project = False

def action_clear(self):
self.default_analytic_account = False
self.default_project_id = False
27 changes: 27 additions & 0 deletions helpdesk_mgmt_timesheet/models/hr_timesheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
###############################################################################
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from odoo import api, fields, models


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

ticket_id = fields.Many2one(
comodel_name='helpdesk.ticket',
string='Ticket',
groups="helpdesk_mgmt.group_helpdesk_user",
)
ticket_partner_id = fields.Many2one(
comodel_name='res.partner',
related="ticket_id.partner_id",
string="Ticket partner",
store=True,
groups="helpdesk_mgmt.group_helpdesk_user",
)

@api.onchange("ticket_id")
def onchange_ticket_id(self):
for record in self:
record.project_id = record.ticket_id.project_id
record.task_id = record.ticket_id.task_id
4 changes: 2 additions & 2 deletions helpdesk_mgmt_timesheet/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
To configure this module, you need to:

#. Allow Timesheet for a Helpdesk's Team
#. Set a Default Analytic Account (optional)
#. Set a Default Project (optional)

Allow Timesheet
~~~~~~~~~~~~~~~

#. Go to Helpdesk > Configuration > Teams.
#. Edit or create a new team.
#. Check Allow Timesheet option to allow timesheets for that team.
#. Select a Default Analytic Account for that team (optional).
#. Select a Project for that team (optional).
6 changes: 5 additions & 1 deletion helpdesk_mgmt_timesheet/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@

* `Punt Sistemes, S.L. <https://www.puntsistemes.es/>`_:

* Carlos Ramos
* Carlos Ramos

* `Solvos Consultoría Informática, S.L. <https://www.solvos.es/>`_:

* David Alonso
2 changes: 1 addition & 1 deletion helpdesk_mgmt_timesheet/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This module add Timesheet funcionality in Helpdesk module.
This module adds Timesheet funcionality in Helpdesk module.
2 changes: 1 addition & 1 deletion helpdesk_mgmt_timesheet/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#. Go to *Helpdesk* or *Helpdesk > Dashboard* to see the tickets dashboard.
#. In the Kanban view, click in the kanban card of a team to see their tickets and create new ones.
#. If there is not a Default Analytic Account you will need select an Analytic Account for the Ticket to show the Timesheet Table.
#. If there is not a Default Project you will need select a Project for the Ticket to show the Timesheet Table.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<data noupdate="0">
<record id="helpdesk_mgmt.group_helpdesk_user_own" model="res.groups">
<field name="implied_ids" eval="[(4, ref('hr_timesheet.group_hr_timesheet_user'))]"/>
</record>
</data>

</odoo>
2 changes: 1 addition & 1 deletion helpdesk_mgmt_timesheet/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###############################################################################
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from . import tests_helpdesk_ticket
from . import test_helpdesk_mgmt_timesheet
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,49 @@
_log = logging.getLogger(__name__)


class TestHelpdeskTicketTimesheet(test_helpdesk_ticket.TestHelpdeskTicket):
class TestHelpdeskMgmtTimesheet(test_helpdesk_ticket.TestHelpdeskTicket):

@classmethod
def setUpClass(cls):
super(TestHelpdeskTicketTimesheet, cls).setUpClass()
cls.account_id = cls.env['account.analytic.account'].create({
'name': 'Test Account',
super(TestHelpdeskMgmtTimesheet, cls).setUpClass()
cls.project_id = cls.env['project.project'].create({
'name': 'Project',
})
cls.team_id = cls.env['helpdesk.ticket.team'].create({
'name': "Team 1",
'allow_timesheet': True,
'default_analytic_account': cls.account_id.id,
'default_project_id': cls.project_id.id,
})

def generate_timesheet(self, hours=1.0):
def generate_timesheet(self, ticket, hours=1.0):
return self.env['account.analytic.line'].create({
'amount': 0,
'company_id': 1,
#'company_id': 1,
'date': fields.Date.today(),
'name': 'Test Timesheet',
'unit_amount': hours,
'ticket_id': ticket.id,
'project_id': ticket.project_id.id,
})

def generate_ticket(self):
return self.env['helpdesk.ticket'].create({
'name': 'Test Ticket 1',
'description': 'Test ticket description',
'team_id': self.team_id.id,
})

def test_total_and_remaining_hours(self):
def test_helpdesk_mgmt_timesheet(self):
ticket = self.generate_ticket()
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(2)
timesheet1.ticket_id = ticket.id
timesheet2 = self.generate_timesheet(1)
timesheet2.ticket_id = ticket.id
self.assertEqual(ticket.total_hours, 3)
self.assertEqual(ticket.remaining_hours, 2)
timesheet1 = self.generate_timesheet(ticket, 2)
timesheet2 = self.generate_timesheet(ticket, 1)
self.assertEqual(
ticket.total_hours,
timesheet1.unit_amount + timesheet2.unit_amount)
self.assertEqual(
ticket.remaining_hours,
ticket.planned_hours - ticket.total_hours)
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='alias_user_id']" position="after">
<field name="allow_timesheet" type="checkbox" />
<field name="default_analytic_account" attrs="{'invisible':[('allow_timesheet', '=', False)]}" help=" Change the Default Analytic Account will not have retroactive effects."/>
<button name="action_clear" help=" Clean Default Analytic Account" type="object" icon="fa-trash" attrs="{'invisible':['|',('allow_timesheet', '=', False),('default_analytic_account', '=', False)]}" class="oe_highlight" />
<field name="default_project_id" attrs="{'invisible':[('allow_timesheet', '=', False)]}" help=" Change the Default Project will not have retroactive effects."/>
<button name="action_clear" help=" Clean Default Project" type="object" icon="fa-trash" attrs="{'invisible':['|',('allow_timesheet', '=', False),('default_project_id', '=', False)]}" class="oe_highlight">
Clean Default Project
</button>
</xpath>
</field>
</record>
Expand Down
49 changes: 0 additions & 49 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket.xml

This file was deleted.

Loading

0 comments on commit c375341

Please sign in to comment.