[IMP] maintenance_project_task_domain, maintenance_server_data, maintenance_service_http_monitoring, maintenance_create_requests_from_project_task: pre-commit execution

This commit is contained in:
Stéphan Sainléger
2026-03-17 22:01:38 +01:00
parent 30a19649d2
commit a563a9f860
43 changed files with 786 additions and 1051 deletions

View File

@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

View File

@@ -1,10 +1,12 @@
from odoo import fields, models, api
from odoo import api, fields, models
class ProjectTask(models.Model):
_inherit = "project.task"
maintenance_request_ids = fields.One2many("maintenance.request", "task_id", string="Maintenance Requests")
maintenance_request_ids = fields.One2many(
"maintenance.request", "task_id", string="Maintenance Requests"
)
maintenance_request_count = fields.Integer(
compute="_compute_maintenance_request_count"
)
@@ -18,7 +20,7 @@ class ProjectTask(models.Model):
def action_view_maintenance_request_ids(self):
"""
Access to the undone maintenance requests for this task
Access to the undone maintenance requests for this task.
"""
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id(

View File

@@ -1,2 +1,2 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_create_maintenance_requests_wizard,maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access,model_create_maintenance_requests_wizard,base.group_user,1,1,1,0
access_create_maintenance_requests_wizard,maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access,model_create_maintenance_requests_wizard,base.group_user,1,1,1,0
1 id name model_id/id group_id/id perm_read perm_write perm_create perm_unlink
2 access_create_maintenance_requests_wizard maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access model_create_maintenance_requests_wizard base.group_user 1 1 1 0

View File

@@ -1,17 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_task_form2_maintenance_inherited" model="ir.ui.view">
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="maintenance_request_count" invisible="1"/>
<field name="maintenance_request_count" invisible="1" />
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<button name="action_view_maintenance_request_ids" type="object" attrs="{'invisible': [('maintenance_request_count', '=', 0)]}" class="oe_stat_button" icon="fa-tasks" >
<button
name="action_view_maintenance_request_ids"
type="object"
attrs="{'invisible': [('maintenance_request_count', '=', 0)]}"
class="oe_stat_button"
icon="fa-tasks"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value ">
<field name="maintenance_request_count" widget="statinfo" nolabel="1" />
<field
name="maintenance_request_count"
widget="statinfo"
nolabel="1"
/>
Maintenance Requests
</span>
</div>

View File

@@ -1,9 +1,10 @@
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.tools.safe_eval import safe_eval
class CreateMaintenanceRequestsWizard(models.TransientModel):
_name= "create.maintenance.requests.wizard"
_description= "Configure the maintenance requests to create from the current task."
_name = "create.maintenance.requests.wizard"
_description = "Configure the maintenance requests to create from the current task."
@api.model
def _default_task_id(self):
@@ -13,19 +14,28 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
def _default_equipment_model(self):
default_domain = []
task_id = self.env["project.task"].browse(self._context.get("active_ids"))
project_equipements = self.env["maintenance.equipment"].search([("project_id", "=", task_id.project_id.id)])
project_equipements = self.env["maintenance.equipment"].search(
[("project_id", "=", task_id.project_id.id)]
)
if project_equipements:
equipment_ids_list = [x.id for x in project_equipements]
default_domain.append(("id", "in", equipment_ids_list))
return default_domain
name = fields.Char("Title", required=True)
user_id = fields.Many2one('res.users', string='Technician')
priority = fields.Selection([('0', 'Very Low'), ('1', 'Low'), ('2', 'Normal'), ('3', 'High')], string='Priority')
maintenance_type = fields.Selection([('corrective', 'Corrective'), ('preventive', 'Preventive')], string='Maintenance Type', default="corrective")
schedule_date = fields.Datetime('Scheduled Date')
user_id = fields.Many2one("res.users", string="Technician")
priority = fields.Selection(
[("0", "Very Low"), ("1", "Low"), ("2", "Normal"), ("3", "High")],
string="Priority",
)
maintenance_type = fields.Selection(
[("corrective", "Corrective"), ("preventive", "Preventive")],
string="Maintenance Type",
default="corrective",
)
schedule_date = fields.Datetime("Scheduled Date")
duration = fields.Float(help="Duration in hours.")
description = fields.Html('Description')
description = fields.Html("Description")
equipment_domain = fields.Char("Equipment Domain", default=_default_equipment_model)
@@ -42,15 +52,14 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
Open the form view.
"""
return {
'name': _('Create maintenance requests'),
'type': 'ir.actions.act_window',
'res_model': 'create.maintenance.requests.wizard',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
"name": _("Create maintenance requests"),
"type": "ir.actions.act_window",
"res_model": "create.maintenance.requests.wizard",
"view_type": "form",
"view_mode": "form",
"target": "new",
}
def create_maintenance_requests(self):
"""
Create the maintenance requests with the data filled in the wizard form.
@@ -59,14 +68,17 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
maintenance_requests = self.env["maintenance.request"].sudo().create(vals_list)
return self._get_action(maintenance_requests)
def _compute_vals_list(self):
"""
Compute the list of data to use for all the maintenance requests creation
Compute the list of data to use for all the maintenance requests creation.
"""
equipment_list = self.env["maintenance.equipment"].search(safe_eval(self.equipment_domain))
equipment_list = self.env["maintenance.equipment"].search(
safe_eval(self.equipment_domain)
)
if len(equipment_list) == 0:
raise UserError("No equipment is matching the domain. Maintenance request creation is not possible.")
raise UserError(
"No equipment is matching the domain. Maintenance request creation is not possible."
)
vals_list = []
common_vals = {
@@ -78,7 +90,7 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
"duration": self.duration,
"description": self.description,
"task_id": self.task_id.id,
"project_id": self.task_id.project_id.id
"project_id": self.task_id.project_id.id,
}
for equipment in equipment_list:
@@ -90,20 +102,25 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
return vals_list
def _get_action(self, maintenance_requests):
"""
Provide the action to go to the tree view of the maintenance requests created.
"""
search_view_ref = self.env.ref('maintenance.hr_equipment_request_view_search', False)
form_view_ref = self.env.ref('maintenance.hr_equipment_request_view_form', False)
tree_view_ref = self.env.ref('maintenance.hr_equipment_request_view_tree', False)
search_view_ref = self.env.ref(
"maintenance.hr_equipment_request_view_search", False
)
form_view_ref = self.env.ref(
"maintenance.hr_equipment_request_view_form", False
)
tree_view_ref = self.env.ref(
"maintenance.hr_equipment_request_view_tree", False
)
return {
'domain': [('id', 'in', maintenance_requests.ids)],
'name': 'Maintenance Requests',
'res_model': 'maintenance.request',
'type': 'ir.actions.act_window',
'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')],
'search_view_id': search_view_ref and [search_view_ref.id],
return {
"domain": [("id", "in", maintenance_requests.ids)],
"name": "Maintenance Requests",
"res_model": "maintenance.request",
"type": "ir.actions.act_window",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
"search_view_id": search_view_ref and [search_view_ref.id],
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="create_maintenance_requests_wizard_view_form" model="ir.ui.view">
<field name="name">create.maintenance.requests.wizard.view.form</field>
@@ -12,10 +12,10 @@
</group>
<group name="domain" string="Equipments targetted">
<field
name="equipment_domain"
widget="domain"
name="equipment_domain"
widget="domain"
options='{"model": "maintenance.equipment"}'
/>
/>
</group>
<group name="data" string="Requests data">
<field name="user_id" />
@@ -27,8 +27,12 @@
</group>
</sheet>
<footer>
<button string="Create" name="create_maintenance_requests" type="object"
class="btn-primary" />
<button
string="Create"
name="create_maintenance_requests"
type="object"
class="btn-primary"
/>
<button string="Cancel" class="btn-secondary" special="cancel" />
</footer>
</form>
@@ -36,7 +40,9 @@
</record>
<record
id="action_create_maintenance_requests_wizard" model="ir.actions.act_window">
id="action_create_maintenance_requests_wizard"
model="ir.actions.act_window"
>
<field name="name">Create Maintenance Requests</field>
<field name="res_model">create.maintenance.requests.wizard</field>
<field name="view_mode">form</field>
@@ -44,10 +50,16 @@
<field name="target">new</field>
</record>
<record id="task_wizard_action_create_maintenance_requests" model="ir.actions.server">
<record
id="task_wizard_action_create_maintenance_requests"
model="ir.actions.server"
>
<field name="name">Create maintenance requests</field>
<field name="model_id" ref="maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard"/>
<field name="binding_model_id" ref="project.model_project_task"/>
<field
name="model_id"
ref="maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard"
/>
<field name="binding_model_id" ref="project.model_project_task" />
<field name="state">code</field>
<field name="code">action = model.action_open_wizard()</field>
</record>