Files
public/directive_common/models/mrp_workorder.py

68 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from odoo import models
class MrpWorkorder(models.Model):
_name = "mrp.workorder"
_inherit = ["mrp.workorder", "directive.mixin"]
def action_iot_signal(self, payload: dict):
"""
Метод-обработчик завершения директивы оборудованием.
Записывает телеметрию в саму операцию и в головной заказ (MO).
"""
for wo in self:
telemetry = payload.get('telemetry', {})
temp = telemetry.get('temperature', 59)
vibro = telemetry.get('vibration', 'Норма')
message = (
f"IoT CNC [{wo.name}]: Операция завершена.<br/>"
f"Температура шпинделя: {temp}°C<br/>"
f"Вибрация: {vibro}."
)
if wo.production_id:
wo.production_id.message_post(
body=f"Отчет по операции {wo.name}: {message}"
)
return True
class MrpProduction(models.Model):
_inherit = 'mrp.production'
def action_choose_directive_group(self):
"""Открывает визард выбора группы директив для первой операции заказа.
У `mrp.production` нет собственного directive.origin, поэтому визард
открывается для первой операции (workorder_ids[:1]) — в типовом
сценарии MO имеет одну ключевую операцию. Внешний контракт (кнопка на
форме mrp.production открывает визард выбора группы) сохраняется.
"""
self.ensure_one()
workorder = self.workorder_ids[:1]
if not workorder:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Внимание',
'message': 'Сначала подтвердите заказ, чтобы появились операции (Work Orders)',
'type': 'warning',
'sticky': False,
}
}
return {
"type": "ir.actions.act_window",
"name": f"Назначить директивы для: {workorder.name}",
"res_model": "directive.choose.group.wizard",
"view_mode": "form",
"target": "new",
"context": {
"active_model": "mrp.workorder",
"active_id": workorder.id,
},
}