mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-23 20:52:07 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import hr_timesheet
|
||||
from . import maintenance_equipment
|
||||
from . import maintenance_request
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# © 2019 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountAnalyticLine(models.Model):
|
||||
_inherit = "account.analytic.line"
|
||||
|
||||
maintenance_request_id = fields.Many2one(comodel_name="maintenance.request")
|
||||
|
||||
@api.onchange("maintenance_request_id")
|
||||
def onchange_maintenance_request_id(self):
|
||||
if self.maintenance_request_id and not self.project_id:
|
||||
self.project_id = self.maintenance_request_id.project_id
|
||||
self.task_id = self.maintenance_request_id.task_id
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
maintenance_request_ids = [
|
||||
vals.get("maintenance_request_id")
|
||||
for vals in vals_list
|
||||
if vals.get("maintenance_request_id")
|
||||
]
|
||||
self._check_request_done(maintenance_request_ids)
|
||||
return super().create(vals_list)
|
||||
|
||||
def write(self, values):
|
||||
current_request = self.maintenance_request_id
|
||||
new_request_id = values.get("maintenance_request_id", False)
|
||||
if current_request:
|
||||
self._check_request_done(current_request.id)
|
||||
if new_request_id:
|
||||
self._check_request_done(new_request_id)
|
||||
return super().write(values)
|
||||
|
||||
def unlink(self):
|
||||
self._check_request_done(
|
||||
self.filtered(lambda x: x.maintenance_request_id).maintenance_request_id.ids
|
||||
)
|
||||
return super().unlink()
|
||||
|
||||
def _check_request_done(self, request_id: int | list[int]):
|
||||
"""
|
||||
Editing a timesheet related to a finished request is forbidden.
|
||||
"""
|
||||
request_ids = [request_id] if isinstance(request_id, int) else request_id
|
||||
if any(
|
||||
self.env["maintenance.request"].browse(request_ids).stage_id.mapped("done")
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Cannot save or delete a timesheet for "
|
||||
"a maintenance request already done"
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2019 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = "maintenance.equipment"
|
||||
|
||||
def _prepare_project_from_equipment_values(self):
|
||||
data = super()._prepare_project_from_equipment_values()
|
||||
data["allow_timesheets"] = True
|
||||
return data
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
# © 2019 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MaintenanceRequest(models.Model):
|
||||
_inherit = "maintenance.request"
|
||||
|
||||
timesheet_ids = fields.One2many(
|
||||
string="Timesheets",
|
||||
comodel_name="account.analytic.line",
|
||||
inverse_name="maintenance_request_id",
|
||||
)
|
||||
timesheet_total_hours = fields.Float(
|
||||
compute="_compute_timesheet_total_hours", readonly=True, store=True
|
||||
)
|
||||
planned_hours = fields.Float(tracking=True)
|
||||
progress = fields.Float(
|
||||
compute="_compute_progress_hours",
|
||||
group_operator="avg",
|
||||
store=True,
|
||||
)
|
||||
remaining_hours = fields.Float(
|
||||
compute="_compute_progress_hours",
|
||||
readonly=True,
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.depends("planned_hours", "timesheet_total_hours")
|
||||
def _compute_progress_hours(self):
|
||||
for item in self:
|
||||
item.progress = 0.0
|
||||
if item.planned_hours > 0.0:
|
||||
if item.timesheet_total_hours > item.planned_hours:
|
||||
item.progress = 100
|
||||
else:
|
||||
item.progress = round(
|
||||
100.0 * item.timesheet_total_hours / item.planned_hours, 2
|
||||
)
|
||||
item.remaining_hours = item.planned_hours - item.timesheet_total_hours
|
||||
|
||||
def _add_followers(self):
|
||||
"""
|
||||
Members of maintenance team are included as followers to automatically
|
||||
grant request visibility and timesheet permissions for this request
|
||||
"""
|
||||
res = super()._add_followers()
|
||||
for request in self:
|
||||
partner_ids = request.maintenance_team_id.member_ids.mapped(
|
||||
"partner_id"
|
||||
).ids
|
||||
request.message_subscribe(partner_ids=partner_ids)
|
||||
return res
|
||||
|
||||
@api.depends("timesheet_ids.unit_amount")
|
||||
def _compute_timesheet_total_hours(self):
|
||||
for request in self:
|
||||
request.timesheet_total_hours = sum(
|
||||
request.timesheet_ids.mapped("unit_amount")
|
||||
)
|
||||
|
||||
def action_view_timesheet_ids(self):
|
||||
"""
|
||||
Access to the current timesheets for this maintenance request
|
||||
The view will be restricted to the current request and only HR managers
|
||||
could create timesheets for every employee
|
||||
"""
|
||||
self.ensure_one()
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id(
|
||||
"maintenance_timesheet.timesheet_action_from_request"
|
||||
)
|
||||
action["domain"] = [("maintenance_request_id", "=", self.id)]
|
||||
action["context"] = {
|
||||
"default_project_id": self.project_id.id,
|
||||
"default_task_id": self.task_id.id,
|
||||
"default_maintenance_request_id": self.id,
|
||||
"readonly_employee_id": not self.env.user.has_group(
|
||||
"hr_timesheet.group_timesheet_manager"
|
||||
),
|
||||
}
|
||||
return action
|
||||
Loading…
Add table
Add a link
Reference in a new issue