mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit maintenance_timesheet for 11.0
This commit is contained in:
1
maintenance_timesheet/__init__.py
Normal file
1
maintenance_timesheet/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
24
maintenance_timesheet/__manifest__.py
Normal file
24
maintenance_timesheet/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
'name': 'Equipment Timesheets',
|
||||
'version': '11.0.1.0.0',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'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,
|
||||
}
|
||||
1
maintenance_timesheet/models/__init__.py
Normal file
1
maintenance_timesheet/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import maintenance
|
||||
55
maintenance_timesheet/models/maintenance.py
Normal file
55
maintenance_timesheet/models/maintenance.py
Normal file
@@ -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]
|
||||
|
||||
67
maintenance_timesheet/views/maintenance_views.xml
Normal file
67
maintenance_timesheet/views/maintenance_views.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="hr_equipment_view_form_inherited">
|
||||
<field name="name">equipment.form.inherited</field>
|
||||
<field name="model">maintenance.equipment</field>
|
||||
<field name="inherit_id" ref="maintenance.hr_equipment_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']/button[1]" position="replace">
|
||||
<button name="action_open_maintenance_requests" type="object" class="oe_stat_button" icon="fa-ticket">
|
||||
<field string="Maintenance" name="maintenance_count" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="maintenance_request_view_form_inherit_hr_inherited">
|
||||
<field name="name">maintenance.request.view.form.inherit.hr.inherited</field>
|
||||
<field name="model">maintenance.request</field>
|
||||
<field name="inherit_id" ref="hr_maintenance.maintenance_request_view_form_inherit_hr"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='employee_id']" position="after">
|
||||
<field name="department_id"/>
|
||||
<field name="project_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="hr_equipment_request_view_form_notebook_inherited">
|
||||
<field name="name">equipment.request.form.notebook.inherited</field>
|
||||
<field name="model">maintenance.request</field>
|
||||
<field name="inherit_id" ref="maintenance_notebook.hr_equipment_request_view_form_notebook"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<page string="Timesheets" attrs="{'invisible': [('project_id', '=', False)]}">
|
||||
<field name="timesheet_ids" context="{'default_project_id': project_id}">
|
||||
<tree editable="bottom" string="Timesheet Activities" default_order="date">
|
||||
<field name="date"/>
|
||||
<field name="user_id" invisible="1"/>
|
||||
<field name="employee_id" required="1"/>
|
||||
<field name="name"/>
|
||||
<field name="unit_amount" string="Duration" widget="float_time"/>
|
||||
<field name="project_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<group>
|
||||
<group class="oe_subtotal_footer oe_right" name="project_hours">
|
||||
<field name="effective_hours" widget="float_time" readonly="1"/>
|
||||
<field name="remaining_hours" widget="float_time" class="oe_subtotal_footer_separator"
|
||||
readonly="1"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="hr_equipment_request_view_tree_inherited">
|
||||
<field name="name">equipment.request.tree.inherited</field>
|
||||
<field name="model">maintenance.request</field>
|
||||
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='stage_id']" position="after">
|
||||
<field name="effective_hours"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user