Files
gzth/yuthon_maintain/models/property_device_repair.py
T
2026-03-20 15:15:37 +08:00

89 lines
4.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api, exceptions, _
from odoo.exceptions import UserError, ValidationError
class PropertyDeviceRelief(models.Model):
_name = 'property.device.repair'
_description = '报事报修'
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
name = fields.Char(string='标题', compute='_compute_name', store=True)
code = fields.Char(string="报修编号",
default=lambda self: self.env['ir.sequence'].next_by_code('property_device_repair_code'))
users_id = fields.Many2one('res.users', string="报修人", default=lambda self: self.env.user.id)
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
company_id = fields.Many2one(related='users_id.employee_id.company_id', string="公司")
software_processing_id = fields.Many2one('software.issues.processing', string="设备类型")
problem_description = fields.Text(string="问题描述")
report_state = fields.Selection([('to_submitted', '待提交'), ('to', '待处理'), ('done', '已处理')], string='状态', default='to_submitted')
create_time = fields.Date(string="填报日期", default=fields.Datetime.now)
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
default='normal')
documents_ids = fields.Many2many('ir.attachment', string="附件")
active = fields.Boolean('Active', default=True, tracking=True)
work_end = fields.Boolean(string="结束")
processing_order_id = fields.Many2one('processing.order.approval', string="处理单流程")
self_users_ids = fields.Many2many('res.users', string="当前经办人",
default=lambda self: [(6, 0, [self.env.user.id])])
def _get_default_name_title(self):
return self._description if self._description else self._name
name_title = fields.Char(default=_get_default_name_title)
@api.depends('software_processing_id', 'users_id')
def _compute_name(self):
for rec in self:
if rec.users_id and rec.software_processing_id:
rec.name = f"{rec.users_id.name}-{rec.software_processing_id.name}-{rec.problem_description}"
def device_delete(self):
self.unlink()
def open_record(self):
return {
"type": "ir.actions.act_window",
"res_model": 'processing.order.approval',
"res_id": self.processing_order_id.id,
"name": '详情',
"view_mode": "form",
}
def get_no_read_count(self):
return self.search_count([('report_state', '=', 'to'), ('users_id', '=', self.env.user.id)])
def pull_order(self):
soong_workflow_line_list = []
self.report_state = 'to'
if self.env['processing.order.approval'].search([('device_id', '=', self.id)]):
raise UserError('该设备已生成处理单')
order_id = self.env['processing.order.approval'].create({
'device_id': self.id,
'repair_date': self.create_time,
'applicant_id': self.users_id.id,
'name': self.problem_description,
'code': self.env['ir.sequence'].next_by_code('property_device_repair_code'),
})
workflow_record_id = self.env['soong.workflow.record'].search([
('code', '=', self.code),
], limit=1)
soong_workflow_line_list.append((0, 0, {
'model': 'processing.order.approval',
'res_id': order_id.id,
'workflow_record_id': workflow_record_id.id
}))
order_id.soong_record_ids = soong_workflow_line_list
self.processing_order_id = order_id.id
class PropertyDeviceLine(models.Model):
_name = 'property.device.line'
_description = '设备信息'
# 暂时保留
report_id = fields.Many2one('property.report.repair', string="设备信息")
name = fields.Char(string="设备名称")
device_specs = fields.Char(string="规格")
mac = fields.Char(string="MAC")
ip = fields.Char(string="IP")