处理设备与设备维保标准的关联关系方法,新增设备故障报警日志页面
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
'security/group_security.xml',
|
'security/group_security.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/maintenance_views.xml',
|
'views/maintenance_views.xml',
|
||||||
|
'views/maintenance_logs_views.xml',
|
||||||
'views/equipment_maintenance_standards_views.xml',
|
'views/equipment_maintenance_standards_views.xml',
|
||||||
'views/maintenance_request_views.xml',
|
'views/maintenance_request_views.xml',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*-coding:utf-8-*-
|
# -*-coding:utf-8-*-
|
||||||
from . import sf_maintenance
|
from . import sf_maintenance
|
||||||
|
from . import sf_maintenance_logs
|
||||||
from . import sf_equipment_maintenance_standards
|
from . import sf_equipment_maintenance_standards
|
||||||
from . import sf_maintenance_requests
|
from . import sf_maintenance_requests
|
||||||
@@ -26,3 +26,19 @@ class SfEquipmentSaintenanceStandards(models.Model):
|
|||||||
maintenance_equipment_ids = fields.Many2many('maintenance.equipment', 'sf_maintenance_equipment_ids', string='设备')
|
maintenance_equipment_ids = fields.Many2many('maintenance.equipment', 'sf_maintenance_equipment_ids', string='设备')
|
||||||
maintenance_projects = fields.Char('维保项目')
|
maintenance_projects = fields.Char('维保项目')
|
||||||
maintenance_standards = fields.Char('维保标准')
|
maintenance_standards = fields.Char('维保标准')
|
||||||
|
eq_maintenance_ids = fields.One2many('maintenance.equipment', 'eq_maintenance_id', string='保养设备')
|
||||||
|
overhaul_ids = fields.One2many('maintenance.equipment', 'overhaul_id', string='检修设备')
|
||||||
|
|
||||||
|
@api.onchange('maintenance_equipment_ids')
|
||||||
|
def onchange_maintenance_equipment_ids(self):
|
||||||
|
for record in self:
|
||||||
|
if record.maintenance_type == '保养':
|
||||||
|
record.write({'eq_maintenance_ids': [(6, 0, record.maintenance_equipment_ids.ids)]})
|
||||||
|
if record.maintenance_type == '检修':
|
||||||
|
record.write({'overhaul_ids': [(6, 0, record.maintenance_equipment_ids.ids)]})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
24
sf_maintenance/models/sf_maintenance_logs.py
Normal file
24
sf_maintenance/models/sf_maintenance_logs.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# -*-coding:utf-8-*-
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
class SfMaintenanceLogs(models.Model):
|
||||||
|
_name = 'sf.maintenance.logs'
|
||||||
|
_description = '设备故障日志'
|
||||||
|
|
||||||
|
code = fields.Char(string='编码')
|
||||||
|
name = fields.Char(string='名称')
|
||||||
|
type = fields.Selection([('type1', '类型1'), ('type2', '类型2')], string='类型')
|
||||||
|
brand = fields.Char(string='品牌')
|
||||||
|
model = fields.Char(string='型号')
|
||||||
|
code_location = fields.Char(string='编码位置')
|
||||||
|
fault_type = fields.Selection([('电气类', '电气类'), ('机械类', '机械类'), ('程序类', '程序类'), ('系统类', '系统类')], string='故障类型')
|
||||||
|
fault_code = fields.Char(string='故障代码')
|
||||||
|
fault_alarm_info = fields.Char(string='故障报警信息')
|
||||||
|
alarm_level = fields.Selection([('一级', '一级(严重)'), ('二级', '二级(中等)'), ('三级', '三级(轻微)')], string='报警级别')
|
||||||
|
alarm_time = fields.Datetime(string='报警时间')
|
||||||
|
alarm_way = fields.Selection([('文本提示报警', '文本提示报警'), ('声光报警', '声光报警'), ('图文报警', '图文报警')], string='报警方式')
|
||||||
|
fault_process = fields.Text(string='故障处理方法')
|
||||||
|
operator = fields.Many2one('res.users', string='处理人')
|
||||||
|
recovery_time = fields.Datetime(string='复原时间')
|
||||||
|
fault_duration = fields.Float(string='故障时长')
|
||||||
|
note = fields.Text(string='备注')
|
||||||
@@ -19,10 +19,23 @@ class SfMaintenanceEquipmentCategory(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
if record.sf_maintenance_type == '保养':
|
if record.sf_maintenance_type == '保养':
|
||||||
record.equipment_maintenance_id = record.equipment_id.eq_maintenance_id
|
record.equipment_maintenance_id = record.equipment_id.eq_maintenance_id
|
||||||
|
|
||||||
if record.sf_maintenance_type == '检修':
|
if record.sf_maintenance_type == '检修':
|
||||||
record.equipment_maintenance_id = record.equipment_id.overhaul_id
|
record.equipment_maintenance_id = record.equipment_id.overhaul_id
|
||||||
if not record.equipment_maintenance_id:
|
if not record.equipment_maintenance_id:
|
||||||
raise UserError(_("设备没有配置维保标准,请配置后再保存"))
|
record.equipment_maintenance_id = False
|
||||||
|
|
||||||
|
|
||||||
|
maintenance_projects = fields.Char(string='维保项目', related='equipment_maintenance_id.maintenance_projects')
|
||||||
|
maintenance_standards = fields.Char(string='维保标准', related='equipment_maintenance_id.maintenance_standards')
|
||||||
|
|
||||||
|
@api.constrains('equipment_maintenance_id')
|
||||||
|
def _check_equipment_maintenance_id(self):
|
||||||
|
for record in self:
|
||||||
|
if not record.equipment_maintenance_id:
|
||||||
|
raise UserError(_("设备维保标准不能为空,请选择后再保存"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_equipment_maintenance_standards,equipment_maintenance_standards,model_equipment_maintenance_standards,base.group_user,1,1,1,1
|
access_equipment_maintenance_standards,equipment_maintenance_standards,model_equipment_maintenance_standards,base.group_user,1,1,1,1
|
||||||
|
access_sf_maintenance_logs,sf_maintenance_logs,model_sf_maintenance_logs,base.group_user,1,1,1,1
|
||||||
|
access_maintenance_equipment,maintenance_equipment,model_maintenance_equipment,base.group_user,1,1,1,1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
|
1
sf_maintenance/tests/__init__.py
Normal file
1
sf_maintenance/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# -*-coding:utf-8-*-
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# -*-coding:utf-8-*-
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
class TestEquipmentMaintenanceStandards(TransactionCase):
|
||||||
|
def setUp(self, *args, **kwargs):
|
||||||
|
result = super().setUp(*args, **kwargs)
|
||||||
|
|
||||||
|
# Define global variables to be used in the test cases
|
||||||
|
self.user = self.env.ref('base.user_admin')
|
||||||
|
self.equipment_category = self.env['maintenance.equipment.category'].create({
|
||||||
|
'name': 'Test Equipment Category'
|
||||||
|
})
|
||||||
|
self.equipment = self.env['maintenance.equipment'].create({
|
||||||
|
'name': 'Test Equipment',
|
||||||
|
'category_id': self.equipment_category.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def test_create_equipment_maintenance_standard(self):
|
||||||
|
"""Test creating a new equipment maintenance standard"""
|
||||||
|
maintenance_standard = self.env['equipment.maintenance.standards'].create({
|
||||||
|
'name': 'Test Maintenance Standard',
|
||||||
|
'maintenance_type': '保养',
|
||||||
|
'maintenance_equipment_category_id': self.equipment_category.id,
|
||||||
|
'maintenance_equipment_ids': [(6, 0, [self.equipment.id])],
|
||||||
|
'maintenance_projects': 'Test Maintenance Project',
|
||||||
|
'maintenance_standards': 'Test Maintenance Standard',
|
||||||
|
})
|
||||||
|
self.assertTrue(maintenance_standard)
|
||||||
|
|
||||||
|
def test_maintenance_standard_code(self):
|
||||||
|
"""Test that the maintenance standard code is generated correctly"""
|
||||||
|
maintenance_standard_1 = self.env['equipment.maintenance.standards'].create({
|
||||||
|
'name': 'Test Maintenance Standard 1',
|
||||||
|
'maintenance_type': '保养',
|
||||||
|
'maintenance_equipment_category_id': self.equipment_category.id,
|
||||||
|
'maintenance_equipment_ids': [(6, 0, [self.equipment.id])],
|
||||||
|
'maintenance_projects': 'Test Maintenance Project',
|
||||||
|
'maintenance_standards': 'Test Maintenance Standard',
|
||||||
|
})
|
||||||
|
maintenance_standard_2 = self.env['equipment.maintenance.standards'].create({
|
||||||
|
'name': 'Test Maintenance Standard 2',
|
||||||
|
'maintenance_type': '保养',
|
||||||
|
'maintenance_equipment_category_id': self.equipment_category.id,
|
||||||
|
'maintenance_equipment_ids': [(6, 0, [self.equipment.id])],
|
||||||
|
'maintenance_projects': 'Test Maintenance Project',
|
||||||
|
'maintenance_standards': 'Test Maintenance Standard',
|
||||||
|
})
|
||||||
|
self.assertEqual(maintenance_standard_1.code, '0001')
|
||||||
|
self.assertEqual(maintenance_standard_2.code, '0002')
|
||||||
|
|
||||||
|
def test_maintenance_standard_fields(self):
|
||||||
|
"""Test that the maintenance standard fields are correctly set"""
|
||||||
|
maintenance_standard = self.env['equipment.maintenance.standards'].create({
|
||||||
|
'name': 'Test Maintenance Standard',
|
||||||
|
'maintenance_type': '保养',
|
||||||
|
'maintenance_equipment_category_id': self.equipment_category.id,
|
||||||
|
'maintenance_equipment_ids': [(6, 0, [self.equipment.id])],
|
||||||
|
'maintenance_projects': 'Test Maintenance Project',
|
||||||
|
'maintenance_standards': 'Test Maintenance Standard',
|
||||||
|
})
|
||||||
|
self.assertEqual(maintenance_standard.name, 'Test Maintenance Standard')
|
||||||
|
self.assertEqual(maintenance_standard.maintenance_type, '保养')
|
||||||
|
self.assertEqual(maintenance_standard.maintenance_equipment_category_id.id, self.equipment_category.id)
|
||||||
|
self.assertIn(self.equipment, maintenance_standard.maintenance_equipment_ids)
|
||||||
|
self.assertEqual(maintenance_standard.maintenance_projects, 'Test Maintenance Project')
|
||||||
|
self.assertEqual(maintenance_standard.maintenance_standards, 'Test Maintenance Standard')
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
<field name="maintenance_equipment_ids" widget="many2many_tags"/>
|
<field name="maintenance_equipment_ids" widget="many2many_tags"/>
|
||||||
<field name="maintenance_projects" required="1"/>
|
<field name="maintenance_projects" required="1"/>
|
||||||
<field name="maintenance_standards" required="1"/>
|
<field name="maintenance_standards" required="1"/>
|
||||||
|
<field name="eq_maintenance_ids"/>
|
||||||
|
<field name="overhaul_ids" />
|
||||||
|
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
|
|||||||
117
sf_maintenance/views/maintenance_logs_views.xml
Normal file
117
sf_maintenance/views/maintenance_logs_views.xml
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<!-- Tree View -->
|
||||||
|
<record id="view_maintenance_logs_tree" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.logs.tree</field>
|
||||||
|
<field name="model">sf.maintenance.logs</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree>
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="brand"/>
|
||||||
|
<field name="model"/>
|
||||||
|
<field name="code_location"/>
|
||||||
|
<field name="fault_type"/>
|
||||||
|
<field name="fault_code"/>
|
||||||
|
<field name="fault_alarm_info"/>
|
||||||
|
<field name="alarm_level"/>
|
||||||
|
<field name="alarm_time"/>
|
||||||
|
<field name="alarm_way"/>
|
||||||
|
<field name="fault_process"/>
|
||||||
|
<field name="operator"/>
|
||||||
|
<field name="recovery_time"/>
|
||||||
|
<field name="fault_duration"/>
|
||||||
|
<field name="note"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Form View -->
|
||||||
|
<record id="view_maintenance_logs_form" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.logs.form</field>
|
||||||
|
<field name="model">sf.maintenance.logs</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="设备故障日志">
|
||||||
|
<group>
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="brand"/>
|
||||||
|
<field name="model"/>
|
||||||
|
<field name="code_location"/>
|
||||||
|
<field name="fault_type"/>
|
||||||
|
<field name="fault_code"/>
|
||||||
|
<field name="fault_alarm_info"/>
|
||||||
|
<field name="alarm_level"/>
|
||||||
|
<field name="alarm_time"/>
|
||||||
|
<field name="alarm_way"/>
|
||||||
|
<field name="fault_process"/>
|
||||||
|
<field name="operator"/>
|
||||||
|
<field name="recovery_time"/>
|
||||||
|
<field name="fault_duration"/>
|
||||||
|
<field name="note"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Search View -->
|
||||||
|
<record id="view_maintenance_logs_search" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.logs.search</field>
|
||||||
|
<field name="model">sf.maintenance.logs</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<search>
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="brand"/>
|
||||||
|
<field name="model"/>
|
||||||
|
<field name="code_location"/>
|
||||||
|
<field name="fault_type"/>
|
||||||
|
<field name="fault_code"/>
|
||||||
|
<field name="fault_alarm_info"/>
|
||||||
|
<field name="alarm_level"/>
|
||||||
|
<field name="alarm_time"/>
|
||||||
|
<field name="alarm_way"/>
|
||||||
|
<field name="fault_process"/>
|
||||||
|
<field name="operator"/>
|
||||||
|
<field name="recovery_time"/>
|
||||||
|
<field name="fault_duration"/>
|
||||||
|
<field name="note"/>
|
||||||
|
</search>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Action -->
|
||||||
|
|
||||||
|
<record id="action_maintenance_logs" model="ir.actions.act_window">
|
||||||
|
<field name="name">设备维保标准</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">sf.maintenance.logs</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
<field name="view_id" ref="view_maintenance_logs_tree"/>
|
||||||
|
<field name="help" type="html">
|
||||||
|
<p class="oe_view_nocontent_create">
|
||||||
|
设备故障日志
|
||||||
|
</p>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- <record id="action_maintenance_logs" model="ir.actions.act_window">-->
|
||||||
|
<!-- <field name="name">设备故障日志</field>-->
|
||||||
|
<!-- <field name="res_model">sf.maintenance.logs</field>-->
|
||||||
|
<!-- <field name="view_type">form</field>-->
|
||||||
|
<!-- <field name="view_mode">tree,form</field>-->
|
||||||
|
<!-- <field name="view_id" ref="view_maintenance_logs_tree"/>-->
|
||||||
|
<!-- </record>-->
|
||||||
|
|
||||||
|
<!-- Menu -->
|
||||||
|
<menuitem name="设备故障日志" id="menu_maintenance_logs" parent="maintenance.menu_maintenance_title"
|
||||||
|
sequence="10" action="action_maintenance_logs"/>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
|
|
||||||
|
|
||||||
@@ -1,37 +1,34 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- equiment.request : actions -->
|
<!-- equiment.request : actions -->
|
||||||
|
|
||||||
<record model="ir.ui.view" id="sf_hr_equipment_request_view_form">
|
<record model="ir.ui.view" id="sf_hr_equipment_request_view_form">
|
||||||
<field name="name">sf.equipment.request.form</field>
|
<field name="name">sf.equipment.request.form</field>
|
||||||
<field name="model">maintenance.request</field>
|
<field name="model">maintenance.request</field>
|
||||||
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_form"/>
|
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='maintenance_type']" position="replace">
|
<xpath expr="//field[@name='maintenance_type']" position="replace">
|
||||||
<field name="sf_maintenance_type" widget="radio"/>
|
<field name="sf_maintenance_type" widget="radio"/>
|
||||||
<field name="equipment_maintenance_id"/>
|
<field name="equipment_maintenance_id"/>
|
||||||
|
|
||||||
</xpath>
|
</xpath>
|
||||||
<!-- <sheet>-->
|
<sheet>
|
||||||
|
|
||||||
<!-- <notebook>-->
|
|
||||||
<!-- <page string="维保标准">-->
|
|
||||||
<!-- <field name="equipment_maintenance_id" widget="many2one"/>-->
|
|
||||||
|
|
||||||
|
|
||||||
<!-- </page>-->
|
|
||||||
<!-- </notebook>-->
|
|
||||||
|
|
||||||
<!-- </sheet>-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
|
<notebook>
|
||||||
|
<page string="维保标准" attrs="{'invisible': [('equipment_maintenance_id', '=', False)]}">
|
||||||
|
<group>
|
||||||
|
<field name="maintenance_projects"/>
|
||||||
|
<field name="maintenance_standards"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
|
||||||
|
</sheet>
|
||||||
|
|
||||||
|
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record id="hr_equipment_request_action" model="ir.actions.act_window">
|
<record id="hr_equipment_request_action" model="ir.actions.act_window">
|
||||||
@@ -43,21 +40,21 @@
|
|||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
Add a new maintenance request
|
Add a new maintenance request
|
||||||
</p><p>
|
</p>
|
||||||
|
<p>
|
||||||
Follow the process of the request and communicate with the collaborator.
|
Follow the process of the request and communicate with the collaborator.
|
||||||
</p>
|
</p>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<menuitem
|
<menuitem
|
||||||
id="menu_m_request_form"
|
id="menu_m_request_form"
|
||||||
name="维保计划"
|
name="维保计划"
|
||||||
parent="maintenance.menu_m_request"
|
parent="maintenance.menu_m_request"
|
||||||
action="hr_equipment_request_action"
|
action="hr_equipment_request_action"
|
||||||
groups="maintenance.group_equipment_manager,base.group_user"
|
groups="maintenance.group_equipment_manager,base.group_user"
|
||||||
sequence="1"/>
|
sequence="1"/>
|
||||||
|
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
|
|
||||||
<xpath expr="//field[@name='next_action_date']" position="before">
|
<xpath expr="//field[@name='next_action_date']" position="before">
|
||||||
|
|
||||||
<field name='eq_maintenance_id'/>
|
<field name='eq_maintenance_id' force_save="1" widget="many2one"/>
|
||||||
|
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user