[CLN] maintenance_service_http_monitoring: apply ruff

This commit is contained in:
Stéphan Sainléger
2026-06-15 17:16:15 +02:00
parent b9b8662bad
commit 2724d29f25

View File

@@ -3,7 +3,6 @@ from datetime import timedelta
from odoo import api, fields, models
try:
import requests as http_requests
except ImportError:
@@ -13,20 +12,18 @@ _logger = logging.getLogger(__name__)
WEBHOOK_TIMEOUT = 10 # seconds
class MaintenanceEquipment(models.Model):
_inherit = "maintenance.equipment"
maintenance_mode = fields.Boolean(
string="Maintenance Mode",
default=False,
tracking=True,
)
maintenance_mode_start = fields.Datetime(
string="Maintenance Mode Start",
readonly=True,
)
maintenance_mode_end = fields.Datetime(
string="Maintenance Mode End",
readonly=True,
help="Computed from start + configured duration",
)
@@ -116,31 +113,32 @@ class MaintenanceEquipment(models.Model):
self._notify_webhook(request, ko_services)
return request
def _notify_webhook(self, request, ko_services):
"""Send a webhook notification when a new maintenance request is created."""
ICP = self.env['ir.config_parameter'].sudo()
def _notify_webhook(self, request, ko_service):
"""
Send a webhook notification when a new maintenance request is created.
"""
ICP = self.env["ir.config_parameter"].sudo()
webhook_url = ICP.get_param(
'maintenance_service_http_monitoring.webhook_url', ''
"maintenance_service_http_monitoring.webhook_url", ""
)
if not webhook_url:
return
webhook_user = ICP.get_param(
'maintenance_service_http_monitoring.webhook_user', ''
"maintenance_service_http_monitoring.webhook_user", ""
)
webhook_password = ICP.get_param(
'maintenance_service_http_monitoring.webhook_password', ''
"maintenance_service_http_monitoring.webhook_password", ""
)
base_url = ICP.get_param('web.base.url', '')
base_url = ICP.get_param("web.base.url", "")
link = (
f"{base_url}/web#id={request.id}"
f"&model=maintenance.request&view_type=form"
f"{base_url}/web#id={request.id}&model=maintenance.request&view_type=form"
)
payload = {
'id': request.id,
'name': request.name,
'description': request.description or '',
'equipment': self.name,
'link': link,
"id": request.id,
"name": request.name,
"description": request.description or "",
"equipment": self.name,
"link": link,
}
auth = None
if webhook_user and webhook_password:
@@ -155,7 +153,8 @@ class MaintenanceEquipment(models.Model):
except Exception as e:
_logger.warning(
"Webhook notification failed for maintenance request %s: %s",
request.id, e,
request.id,
e,
)
def _build_ko_services_description(self, ko_services):