From 98923c1797fbcc47eaa0f78caed76ef419ffa223 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 22 Oct 2024 17:52:20 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AE=BE=E5=A4=87=E7=BB=B4=E4=BF=9D?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_maintenance/models/sf_maintenance.py | 61 +++++++++- .../models/sf_maintenance_requests.py | 2 + sf_maintenance/security/ir.model.access.csv | 2 +- sf_maintenance/views/maintenance_views.xml | 115 +++++++++++------- 4 files changed, 130 insertions(+), 50 deletions(-) diff --git a/sf_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index d5bfa6b4..95e38d02 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -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, diff --git a/sf_maintenance/models/sf_maintenance_requests.py b/sf_maintenance/models/sf_maintenance_requests.py index 8686926b..397c8c90 100644 --- a/sf_maintenance/models/sf_maintenance_requests.py +++ b/sf_maintenance/models/sf_maintenance_requests.py @@ -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: diff --git a/sf_maintenance/security/ir.model.access.csv b/sf_maintenance/security/ir.model.access.csv index abbd4878..0317cf7a 100644 --- a/sf_maintenance/security/ir.model.access.csv +++ b/sf_maintenance/security/ir.model.access.csv @@ -20,7 +20,7 @@ access_maintenance_equipment_agv_log,maintenance_equipment_agv_log,model_mainten -access_maintenance_system_user,equipment.request system user,maintenance.model_maintenance_request,base.group_user,1,0,0,0 +access_maintenance_system_user,equipment.request system user,maintenance.model_maintenance_request,base.group_user,1,1,1,0 access_maintenance_equipment_group_plan_dispatch,maintenance.equipment,maintenance.model_maintenance_equipment,sf_base.group_plan_dispatch,1,0,0,0 access_maintenance_equipment_oee_group_plan_dispatch,maintenance_equipment_oee,model_maintenance_equipment_oee,sf_base.group_plan_dispatch,1,0,0,0 diff --git a/sf_maintenance/views/maintenance_views.xml b/sf_maintenance/views/maintenance_views.xml index 8c6cb40d..4fe044d3 100644 --- a/sf_maintenance/views/maintenance_views.xml +++ b/sf_maintenance/views/maintenance_views.xml @@ -60,9 +60,9 @@ - + + domain="[('brand_id', '=', brand_id)]"/> @@ -73,7 +73,7 @@ + options="{'no_create': True}"/>