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