1、设备维保优化
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import base64
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
import requests
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class SfMaintenanceEquipmentCategory(models.Model):
|
||||
@@ -122,6 +123,10 @@ class SfMaintenanceEquipment(models.Model):
|
||||
'sf_maintenance_equipment_ids', string='设备维保标准')
|
||||
eq_maintenance_id = fields.Many2one('equipment.maintenance.standards', string='设备保养标准',
|
||||
domain="[('maintenance_type','=','保养')]")
|
||||
|
||||
initial_action_date = fields.Date(string='初始保养日期')
|
||||
next_action_date = fields.Date(string='下次预防保养')
|
||||
initial_overhaul_date = fields.Date(string='初始维修日期')
|
||||
overhaul_date = fields.Date(string='下次预防检修')
|
||||
overhaul_period = fields.Integer(string='预防检修频次')
|
||||
overhaul_duration = fields.Float(string='检修时长')
|
||||
@@ -129,6 +134,52 @@ class SfMaintenanceEquipment(models.Model):
|
||||
overhaul_id = fields.Many2one('equipment.maintenance.standards', string='设备检修标准',
|
||||
domain="[('maintenance_type','=','检修')]")
|
||||
|
||||
def confirm_maintenance(self):
|
||||
"""
|
||||
确认保养/检修
|
||||
"""
|
||||
context = self.env.context
|
||||
initial_date = None
|
||||
next_date = None
|
||||
if context['type'] == '保养':
|
||||
if not self.initial_action_date:
|
||||
raise ValidationError('初始保养日期不能为空!!')
|
||||
elif self.initial_action_date < fields.Date.today():
|
||||
raise ValidationError('初始保养日期不能小于当前日期!!')
|
||||
else:
|
||||
initial_date = self.initial_action_date
|
||||
next_date = self.next_action_date
|
||||
elif context['type'] == '检修':
|
||||
if not self.initial_overhaul_date:
|
||||
raise ValidationError('初始检修日期不能为空!!')
|
||||
elif self.initial_overhaul_date < fields.Date.today():
|
||||
raise ValidationError('初始检修日期不能小于当前日期!!')
|
||||
else:
|
||||
initial_date = self.initial_overhaul_date
|
||||
next_date = self.overhaul_date
|
||||
|
||||
request_id = self.env['maintenance.request'].search([('stage_id.done', '=', False),
|
||||
('equipment_id', '=', self.id),
|
||||
('maintenance_type', '=', 'preventive'),
|
||||
('request_date', '=', next_date),
|
||||
('sf_maintenance_type', '=', context['type'])])
|
||||
if not request_id:
|
||||
if context['type'] == '保养':
|
||||
self._create_new_request(initial_date)
|
||||
elif context['type'] == '检修':
|
||||
self._create_new_request1(initial_date)
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': f'创建{context["type"]}计划',
|
||||
'message': f'{context["type"]}维保计划创建成功',
|
||||
'type': 'success'
|
||||
}
|
||||
}
|
||||
else:
|
||||
pass
|
||||
|
||||
@api.onchange('eq_maintenance_id', 'overhaul_id')
|
||||
def _compute_equipment_maintenance_standards_ids(self):
|
||||
for record in self:
|
||||
@@ -624,7 +675,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
if next_date < date_now:
|
||||
next_date = date_now
|
||||
else:
|
||||
next_date = equipment.effective_date + timedelta(days=equipment.period)
|
||||
next_date = equipment.initial_action_date + timedelta(days=equipment.period)
|
||||
equipment.next_action_date = next_date
|
||||
else:
|
||||
self.next_action_date = False
|
||||
@@ -668,7 +719,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
if next_date < date_now:
|
||||
next_date = date_now
|
||||
else:
|
||||
next_date = equipment.effective_date + timedelta(days=equipment.overhaul_period)
|
||||
next_date = equipment.initial_overhaul_date + timedelta(days=equipment.overhaul_period)
|
||||
equipment.overhaul_date = next_date
|
||||
else:
|
||||
self.overhaul_date = False
|
||||
@@ -678,7 +729,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('Preventive Maintenance - %s', self.name),
|
||||
'request_date': date,
|
||||
'request_date': fields.Date.today(),
|
||||
'schedule_date': date,
|
||||
'category_id': self.category_id.id,
|
||||
'equipment_id': self.id,
|
||||
@@ -698,7 +749,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('Preventive Maintenance - %s', self.name),
|
||||
'request_date': date,
|
||||
'request_date': fields.Date.today(),
|
||||
'schedule_date': date,
|
||||
'category_id': self.category_id.id,
|
||||
'equipment_id': self.id,
|
||||
|
||||
@@ -14,6 +14,8 @@ class SfMaintenanceEquipmentCategory(models.Model):
|
||||
equipment_maintenance_id = fields.Many2one('equipment.maintenance.standards', string='设备维保标准',
|
||||
domain="[('maintenance_type','=',sf_maintenance_type)]")
|
||||
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
@api.onchange('sf_maintenance_type')
|
||||
def _compute_equipment_maintenance_request_id(self):
|
||||
for record in self:
|
||||
|
||||
Reference in New Issue
Block a user