From cf91ef5604b5037f924b0178036887e00a2c9bee Mon Sep 17 00:00:00 2001 From: "qihao.gong@jikimo.com" Date: Mon, 26 Jun 2023 17:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=B4=E4=BF=9D=E8=AE=A1?= =?UTF-8?q?=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_maintenance/models/__init__.py | 3 +- .../sf_equipment_maintenance_standards.py | 2 +- sf_maintenance/models/sf_maintenance.py | 28 +++++---- .../models/sf_maintenance_requests.py | 15 +++++ .../views/maintenance_request_views.xml | 63 ++++++++++++++----- sf_maintenance/views/maintenance_views.xml | 48 +++++++------- 6 files changed, 109 insertions(+), 50 deletions(-) diff --git a/sf_maintenance/models/__init__.py b/sf_maintenance/models/__init__.py index cf75b7d8..130f2688 100644 --- a/sf_maintenance/models/__init__.py +++ b/sf_maintenance/models/__init__.py @@ -1,3 +1,4 @@ # -*-coding:utf-8-*- from . import sf_maintenance -from . import sf_equipment_maintenance_standards \ No newline at end of file +from . import sf_equipment_maintenance_standards +from . import sf_maintenance_requests \ No newline at end of file diff --git a/sf_maintenance/models/sf_equipment_maintenance_standards.py b/sf_maintenance/models/sf_equipment_maintenance_standards.py index 9de3a2d9..0d290e49 100644 --- a/sf_maintenance/models/sf_equipment_maintenance_standards.py +++ b/sf_maintenance/models/sf_equipment_maintenance_standards.py @@ -23,6 +23,6 @@ class SfEquipmentSaintenanceStandards(models.Model): name = fields.Char(string='名称') created_user_id = fields.Many2one('res.users', string='创建人', default=lambda self: self.env.user) maintenance_equipment_category_id = fields.Many2one('maintenance.equipment.category', string='设备类别') - maintenance_equipment_ids = fields.Many2many('maintenance.equipment', 'equipment_maintenance_standards_ids', string='设备') + maintenance_equipment_ids = fields.Many2many('maintenance.equipment', 'sf_maintenance_equipment_ids', string='设备') maintenance_projects = fields.Char('维保项目') maintenance_standards = fields.Char('维保标准') diff --git a/sf_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index d8ee1af5..6c2f1dcd 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -33,7 +33,7 @@ class SfMaintenanceEquipment(models.Model): num = "%04d" % m return num - equipment_maintenance_standards_ids = fields.Many2many('equipment.maintenance.standards', 'maintenance_equipment_ids', string='设备维保标准') + equipment_maintenance_standards_ids = fields.Many2many('equipment.maintenance.standards', 'sf_maintenance_equipment_ids', string='设备维保标准') eq_maintenance_id =fields.Many2one('equipment.maintenance.standards', string='设备保养标准', domain="[('maintenance_type','=','保养')]") overhaul_date = fields.Date(string='下次预防检修') overhaul_period = fields.Integer(string='预防检修频次') @@ -41,17 +41,21 @@ class SfMaintenanceEquipment(models.Model): overhaul_id = fields.Many2one('equipment.maintenance.standards', string='设备检修标准', domain="[('maintenance_type','=','检修')]") - # @api.depends('eq_maintenance_id', 'overhaul_id') - # def _compute_equipment_maintenance_standards_ids(self): - # for record in self: - # if record.eq_maintenance_id == False: - # record.equipment_maintenance_standards_ids = [ - # (6, 0, [record.overhaul_id.id]),(3,record.eq_maintenance_id.id,0)] - # if record.overhaul_id == False: - # record.equipment_maintenance_standards_ids = [ - # (6, 0, [record.eq_maintenance_id.id]),(3,record.overhaul_id.id,0)] - # else: - # record.equipment_maintenance_standards_ids = [(6, 0, [record.eq_maintenance_id.id, record.overhaul_id.id])] + @api.onchange('eq_maintenance_id', 'overhaul_id') + def _compute_equipment_maintenance_standards_ids(self): + for record in self: + if record.eq_maintenance_id and record.overhaul_id: + record.equipment_maintenance_standards_ids = [(6, 0, [record.eq_maintenance_id.id, record.overhaul_id.id])] + break + if record.eq_maintenance_id: + record.equipment_maintenance_standards_ids = [(6, 0, [record.eq_maintenance_id.id])] + break + if record.overhaul_id: + record.equipment_maintenance_standards_ids = [(6, 0, [record.overhaul_id.id])] + break + else: + record.equipment_maintenance_standards_ids = False + MTcode = fields.Char("编码", default=get_no) diff --git a/sf_maintenance/models/sf_maintenance_requests.py b/sf_maintenance/models/sf_maintenance_requests.py index 1bf528dc..1d623892 100644 --- a/sf_maintenance/models/sf_maintenance_requests.py +++ b/sf_maintenance/models/sf_maintenance_requests.py @@ -9,5 +9,20 @@ class SfMaintenanceEquipmentCategory(models.Model): _inherit = 'maintenance.request' _description = '维保计划' + sf_maintenance_type = fields.Selection([('保养', '保养'), ('检修', '检修')], string='维保类别', default='保养') + + equipment_maintenance_id = fields.Many2one('equipment.maintenance.standards', string='设备维保标准', + domain="[('maintenance_type','=',sf_maintenance_type)]") + + @api.onchange('sf_maintenance_type') + def _compute_equipment_maintenance_request_id(self): + for record in self: + if record.sf_maintenance_type == '保养': + record.equipment_maintenance_id = record.equipment_id.eq_maintenance_id + if record.sf_maintenance_type == '检修': + record.equipment_maintenance_id = record.equipment_id.overhaul_id + if not record.equipment_maintenance_id: + raise UserError(_("设备没有配置维保标准,请配置后再保存")) + diff --git a/sf_maintenance/views/maintenance_request_views.xml b/sf_maintenance/views/maintenance_request_views.xml index de631cf6..b3f257b1 100644 --- a/sf_maintenance/views/maintenance_request_views.xml +++ b/sf_maintenance/views/maintenance_request_views.xml @@ -1,20 +1,53 @@ - - - - - - - - - - - - - - + + + sf.equipment.request.form + maintenance.request + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 维保计划 + maintenance.request + kanban,tree,form,pivot,graph,calendar + + {'default_user_id': uid} + +

+ Add a new maintenance request +

+ Follow the process of the request and communicate with the collaborator. +

+
+
@@ -22,7 +55,7 @@ id="menu_m_request_form" name="维保计划" parent="maintenance.menu_m_request" - action="maintenance.hr_equipment_request_action" + action="hr_equipment_request_action" groups="maintenance.group_equipment_manager,base.group_user" sequence="1"/> diff --git a/sf_maintenance/views/maintenance_views.xml b/sf_maintenance/views/maintenance_views.xml index 1f3b8b07..6b4ee016 100644 --- a/sf_maintenance/views/maintenance_views.xml +++ b/sf_maintenance/views/maintenance_views.xml @@ -18,33 +18,30 @@ + + + - - + + + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -112,7 +118,7 @@ hours - +