diff --git a/maintenance_timesheet/__init__.py b/maintenance_timesheet/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/maintenance_timesheet/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/maintenance_timesheet/__manifest__.py b/maintenance_timesheet/__manifest__.py new file mode 100644 index 00000000..bca3e0b5 --- /dev/null +++ b/maintenance_timesheet/__manifest__.py @@ -0,0 +1,24 @@ +{ + 'name': 'Equipment Timesheets', + 'version': '11.0.1.0.0', + 'author': 'Hibou Corp. ', + 'category': 'Human Resources', + 'summary': 'Record time on maintenance requests.', + 'description': """ +Equipment Timesheets +==================== + +Adds Timesheets to Maintenance Requests to record time and labor costs. +""", + 'website': 'https://hibou.io/', + 'depends': [ + 'maintenance_notebook', + 'hr_department_project', + 'hr_timesheet', + ], + 'data': [ + 'views/maintenance_views.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/maintenance_timesheet/models/__init__.py b/maintenance_timesheet/models/__init__.py new file mode 100644 index 00000000..12bf298f --- /dev/null +++ b/maintenance_timesheet/models/__init__.py @@ -0,0 +1 @@ +from . import maintenance diff --git a/maintenance_timesheet/models/maintenance.py b/maintenance_timesheet/models/maintenance.py new file mode 100644 index 00000000..202338af --- /dev/null +++ b/maintenance_timesheet/models/maintenance.py @@ -0,0 +1,55 @@ +from odoo import api, fields, models + + +class AnalyticLine(models.Model): + _inherit = 'account.analytic.line' + + maintenance_request_id = fields.Many2one('maintenance.request') + + +class MaintenanceEquipment(models.Model): + _inherit = 'maintenance.equipment' + + def action_open_maintenance_requests(self): + self.ensure_one() + action = self.env.ref('maintenance.hr_equipment_request_action_from_equipment').read()[0] + action['domain'] = [('equipment_id', '=', self.id)] + action['context'] = { + 'default_equipment_id': self.id, + 'default_employee_id': self.employee_id.id, + 'default_department_id': self.department_id.id, + } + return action + + +class MaintenanceRequest(models.Model): + _inherit = 'maintenance.request' + + project_id = fields.Many2one('project.project', string='Billing Project') + timesheet_ids = fields.One2many('account.analytic.line', 'maintenance_request_id', 'Timesheets') + effective_hours = fields.Float(compute='_hours_get', store=True, string='Hours Spent', + help="Computed using the sum of the maintenance work done.") + remaining_hours = fields.Float(compute='_hours_get', store=True, string='Remaining Hours', + help="Total remaining time.") + + @api.model + def create(self, values): + if not values.get('project_id') and values.get('department_id'): + department = self.env['hr.department'].browse(values.get('department_id')) + if department and department.project_ids: + values.update({'project_id': department.project_ids.ids[0]}) + return super(MaintenanceRequest, self).create(values) + + @api.depends('duration', 'timesheet_ids.unit_amount') + def _hours_get(self): + for request in self: + effective_hours = sum(request.sudo().timesheet_ids.mapped('unit_amount')) + request.effective_hours = effective_hours + request.remaining_hours = (request.duration or 0.0) - effective_hours + + @api.onchange('department_id') + def _onchange_department_id_project(self): + for request in self: + if request.department_id and request.department_id.project_ids: + request.project_id = request.department_id.project_ids[0] + diff --git a/maintenance_timesheet/views/maintenance_views.xml b/maintenance_timesheet/views/maintenance_views.xml new file mode 100644 index 00000000..f304b368 --- /dev/null +++ b/maintenance_timesheet/views/maintenance_views.xml @@ -0,0 +1,67 @@ + + + + equipment.form.inherited + maintenance.equipment + + + + + + + + + + maintenance.request.view.form.inherit.hr.inherited + maintenance.request + + + + + + + + + + + equipment.request.form.notebook.inherited + maintenance.request + + + + + + + + + + + + + + + + + + + + + + + + + + + equipment.request.tree.inherited + maintenance.request + + + + + + + + \ No newline at end of file