99 lines
4.3 KiB
Python
99 lines
4.3 KiB
Python
# -*-coding:utf-8-*-
|
|
from odoo import api, fields, models, SUPERUSER_ID, _
|
|
from odoo.exceptions import UserError
|
|
|
|
class SfEquipmentSaintenanceStandards(models.Model):
|
|
_name = 'equipment.maintenance.standards'
|
|
_description = '设备维保标准'
|
|
|
|
def get_no(self):
|
|
partner = self.env['equipment.maintenance.standards'].sudo().search(
|
|
[('code', '!=', '')],
|
|
limit=1,
|
|
order="id desc")
|
|
if not partner:
|
|
num = "%04d" % 1
|
|
|
|
else:
|
|
m = int(partner.code[-4:]) + 1
|
|
num = "%04d" % m
|
|
return num
|
|
code = fields.Char(string='编码')
|
|
remark = fields.Char('备注')
|
|
maintenance_type = fields.Selection([('保养', '保养'), ("检修", "检修")], string='类型', default='保养')
|
|
name = fields.Char(string='名称')
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if not vals['code']:
|
|
if vals['maintenance_type']:
|
|
if vals['maintenance_type'] == '保养':
|
|
vals['code'] = 'BY' + self.get_no()
|
|
else:
|
|
vals['code'] = 'JX' + self.get_no()
|
|
if not vals['name']:
|
|
if vals['maintenance_equipment_category_id']:
|
|
ma_name = self.env['maintenance.equipment.category'].sudo().search(
|
|
[('id', '=', vals['maintenance_equipment_category_id'])]).name
|
|
vals['name'] = ma_name + '-' + vals['maintenance_type'] + '标准-' + vals[
|
|
'code']
|
|
return super().create(vals_list)
|
|
|
|
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',
|
|
'sf_maintenance_equipment_ids',
|
|
string='适用设备',
|
|
domain="[('category_id', '=', maintenance_equipment_category_id)]"
|
|
)
|
|
maintenance_standards_ids = fields.One2many('maintenance.standards', 'equipment_maintenance_standards_id',
|
|
string='维保项目', widget='one2many_list')
|
|
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)]})
|
|
|
|
# @api.onchange("maintenance_standards_ids")
|
|
# def _reset_work_order_sequence(self):
|
|
# for rec in self:
|
|
# current_sequence = 1
|
|
# for work in rec.maintenance_standards_ids:
|
|
# work.sequence = current_sequence
|
|
# current_sequence += 1
|
|
|
|
class SfSaintenanceStandards(models.Model):
|
|
_name = 'maintenance.standards'
|
|
_description = '维保项目'
|
|
_order = 'sequence'
|
|
|
|
sequence = fields.Integer('序号')
|
|
name = fields.Char('维保项目')
|
|
maintenance_standards = fields.Char('维保标准')
|
|
fault_type = fields.Selection(
|
|
[('电气类', '电气类'), ('机械类', '机械类'), ('程序类', '程序类'), ('系统类', '系统类')], string='类别')
|
|
equipment_maintenance_standards_id = fields.Many2one('equipment.maintenance.standards', string='设备维保标准')
|
|
images = fields.One2many('maintenance.standard.image', 'standard_id', string='反馈图片')
|
|
maintenance_request_ids = fields.Many2many('maintenance.request', string='维保计划')
|
|
Period = fields.Integer('周期/频次(天)')
|
|
remark = fields.Char('备注说明')
|
|
|
|
|
|
class MaintenanceStandardImage(models.Model):
|
|
_name = 'maintenance.standard.image'
|
|
_description = 'maintenance.standard.image'
|
|
|
|
image = fields.Binary(string='维保图片')
|
|
standard_id = fields.Many2one('maintenance.standards', string='Standard')
|
|
|
|
|
|
|
|
|