mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'mig/17.0/maintenance_usage' into '17.0'
WIP: mig/17.0/maintenance_usage into 17.0 See merge request hibou-io/hibou-odoo/suite!1753
This commit is contained in:
36
hr_department_project/README.rst
Normal file
36
hr_department_project/README.rst
Normal file
@@ -0,0 +1,36 @@
|
||||
*****************************
|
||||
Hibou - HR Department Project
|
||||
*****************************
|
||||
|
||||
Define a default project for every department.
|
||||
|
||||
For more information and add-ons, visit `Hibou.io <https://hibou.io/>`_.
|
||||
|
||||
|
||||
=============
|
||||
Main Features
|
||||
=============
|
||||
|
||||
* Adds new smart button to HR Department form view for projects which displays the number of projects for that department.
|
||||
* New project tree view for department-specific projects.
|
||||
* Adds new Department field to projects.
|
||||
* Adds new filter to group projects by Department.
|
||||
|
||||
.. image:: https://user-images.githubusercontent.com/15882954/41183026-42afc7b4-6b2d-11e8-9531-f3e56b92b332.png
|
||||
:alt: 'Project Create'
|
||||
:width: 988
|
||||
:align: left
|
||||
|
||||
.. image:: https://user-images.githubusercontent.com/15882954/41183324-fa790b84-6b2e-11e8-956b-3724a4b49e56.png
|
||||
:alt: 'Department Detail'
|
||||
:width: 988
|
||||
:align: left
|
||||
|
||||
|
||||
=======
|
||||
License
|
||||
=======
|
||||
|
||||
Please see `LICENSE <https://github.com/hibou-io/hibou-odoo-suite/blob/11.0/LICENSE>`_.
|
||||
|
||||
Copyright Hibou Corp. 2018
|
||||
2
hr_department_project/__init__.py
Normal file
2
hr_department_project/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import models
|
||||
24
hr_department_project/__manifest__.py
Normal file
24
hr_department_project/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
'name': 'HR Department Project',
|
||||
'version': '17.0.1.0.0',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'category': 'Human Resources',
|
||||
'summary': 'Provide default project per Department',
|
||||
'description': """
|
||||
HR Department Project
|
||||
=====================
|
||||
|
||||
Define a 'default project' for every department. This is a bridge module to allow other modules to use this behavior.
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'project',
|
||||
'hr',
|
||||
],
|
||||
'data': [
|
||||
'views/hr_views.xml',
|
||||
'views/project_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
3
hr_department_project/models/__init__.py
Normal file
3
hr_department_project/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import hr
|
||||
from . import project
|
||||
22
hr_department_project/models/hr.py
Normal file
22
hr_department_project/models/hr.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
_inherit = 'hr.department'
|
||||
|
||||
project_ids = fields.One2many('project.project', 'department_id', string='Projects')
|
||||
project_count = fields.Integer(compute='_compute_project_count', string='Project Count')
|
||||
|
||||
def _compute_project_count(self):
|
||||
for department in self:
|
||||
department.project_count = len(department.with_context(active_test=False).project_ids)
|
||||
|
||||
def project_tree_view(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('project.open_view_project_all').read()[0]
|
||||
action['domain'] = [('department_id', '=', self.id)]
|
||||
action['context'] = {
|
||||
'default_department_id': self.id,
|
||||
'default_user_id': self.manager_id.id if self.manager_id else 0,
|
||||
}
|
||||
return action
|
||||
7
hr_department_project/models/project.py
Normal file
7
hr_department_project/models/project.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
_inherit = 'project.project'
|
||||
|
||||
department_id = fields.Many2one('hr.department', string='Department')
|
||||
18
hr_department_project/views/hr_views.xml
Normal file
18
hr_department_project/views/hr_views.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="view_department_form_inherited">
|
||||
<field name="name">hr.department.form.inherited</field>
|
||||
<field name="model">hr.department</field>
|
||||
<field name="inherit_id" ref="hr.view_department_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<!-- <xpath expr="//widget[@name='web_ribbon']" position="before"> -->
|
||||
<xpath expr="//button[@name='action_plan_from_department']" position="after">
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button class="oe_stat_button" name="project_tree_view" type="object" icon="fa-puzzle-piece">
|
||||
<field string="Projects" name="project_count" widget="statinfo"/>
|
||||
</button>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
24
hr_department_project/views/project_views.xml
Normal file
24
hr_department_project/views/project_views.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="edit_project_inherited">
|
||||
<field name="name">project.project.form.inherited</field>
|
||||
<field name="model">project.project</field>
|
||||
<field name="inherit_id" ref="project.edit_project"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='user_id']" position="before">
|
||||
<field name="department_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_project_project_filter_inherited">
|
||||
<field name="name">project.project.select.inherited</field>
|
||||
<field name="model">project.project</field>
|
||||
<field name="inherit_id" ref="project.view_project_project_filter"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group/filter[@name='Manager']" position="before">
|
||||
<filter string="Department" name="group_department" context="{'group_by': 'department_id'}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
34
maintenance_timesheet/README.rst
Normal file
34
maintenance_timesheet/README.rst
Normal file
@@ -0,0 +1,34 @@
|
||||
*****************************
|
||||
Hibou - Maintenance Timesheet
|
||||
*****************************
|
||||
|
||||
Record time on maintenance requests.
|
||||
|
||||
For more information and add-ons, visit `Hibou.io <https://hibou.io/>`_.
|
||||
|
||||
|
||||
=============
|
||||
Main Features
|
||||
=============
|
||||
|
||||
* Adds Timesheets to Maintenance Requests to record time and labor costs.
|
||||
* New 'Timesheets' notebook tab on Maintenance Request form.
|
||||
|
||||
.. image:: https://user-images.githubusercontent.com/15882954/41261982-394a10b8-6d93-11e8-9602-c19a3e20065d.png
|
||||
:alt: 'Equipment Detail'
|
||||
:width: 988
|
||||
:align: left
|
||||
|
||||
=====
|
||||
Notes
|
||||
=====
|
||||
|
||||
* In order to add time sheets, you must first select a Billing Project from the dropdown menu.
|
||||
|
||||
=======
|
||||
License
|
||||
=======
|
||||
|
||||
Please see `LICENSE <https://github.com/hibou-io/hibou-odoo-suite/blob/11.0/LICENSE>`_.
|
||||
|
||||
Copyright Hibou Corp. 2018
|
||||
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': '17.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
|
||||
56
maintenance_timesheet/models/maintenance.py
Normal file
56
maintenance_timesheet/models/maintenance.py
Normal file
@@ -0,0 +1,56 @@
|
||||
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.")
|
||||
department_id = fields.Many2one('hr.department')
|
||||
|
||||
|
||||
@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]
|
||||
68
maintenance_timesheet/views/maintenance_views.xml
Normal file
68
maintenance_timesheet/views/maintenance_views.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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" invisible="not project_id">
|
||||
<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"/>
|
||||
<field name="company_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>
|
||||
@@ -11,8 +11,8 @@ class MaintenanceEquipmentCategory(models.Model):
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = 'maintenance.equipment'
|
||||
|
||||
employee_id = fields.Many2one(track_visibility=False)
|
||||
department_id = fields.Many2one(track_visibility=False)
|
||||
employee_id = fields.Many2one(tracking=False)
|
||||
department_id = fields.Many2one(tracking=False)
|
||||
usage_qty = fields.Float(string='Usage', default=0.0)
|
||||
usage_uom_id = fields.Many2one('uom.uom', related='category_id.usage_uom_id')
|
||||
usage_log_ids = fields.One2many('maintenance.usage.log', 'equipment_id', string='Usage')
|
||||
|
||||
Reference in New Issue
Block a user