186 lines
8.8 KiB
Python
186 lines
8.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
from email.policy import default
|
|
|
|
from odoo import models, fields, api, exceptions, _
|
|
from odoo.exceptions import UserError, ValidationError
|
|
|
|
|
|
class ProcessingOrderApproval(models.Model):
|
|
_name = 'processing.order.approval'
|
|
_description = '处理单审批'
|
|
_rec_name = 'display_name'
|
|
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
|
|
|
|
name = fields.Char(string='标题', store=True)
|
|
display_name = fields.Char(string='名称', compute='_compute_name',)
|
|
code = fields.Char(string="编号",
|
|
default=lambda self: self.env['ir.sequence'].next_by_code('processing_order_approval_code'))
|
|
applicant_id = fields.Many2one('res.users', string="报修人")
|
|
repair_date = fields.Date(string="报修时间")
|
|
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="公司")
|
|
documents_ids = fields.Many2many('ir.attachment', string="维修图片")
|
|
active = fields.Boolean('Active', default=True, tracking=True)
|
|
work_end = fields.Boolean(string="结束")
|
|
self_users_ids = fields.Many2many('res.users', string="当前经办人",
|
|
default=lambda self: [(6, 0, [self.env.user.id])])
|
|
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
|
|
default='normal')
|
|
|
|
device_id = fields.Many2one('property.device.repair', string="报事报修(设备)")
|
|
device_name = fields.Char(string="设备名称/型号")
|
|
device_code = fields.Char(string="设备编号")
|
|
|
|
repair_id = fields.Many2one('property.report.repair', string="报事报修(物业)")
|
|
property_id = fields.Many2one('yuthon.property', string="物业")
|
|
lessee_id = fields.Many2one('property.tenant.information', string="承租方")
|
|
contract_id = fields.Many2one('property.lease.contract', string="合同", compute='_compute_contract_id')
|
|
contact = fields.Char(string="联系人")
|
|
phone = fields.Char(string="联系电话")
|
|
problem_description = fields.Text(string="问题描述")
|
|
|
|
repair_details = fields.Text(string="维修详情")
|
|
fault_reason = fields.Selection(
|
|
[
|
|
('hardware', '硬件故障'),
|
|
('software', '软件错误'),
|
|
('configuration', '配置问题'),
|
|
('virus', '病毒/恶意软件'),
|
|
('network', '网络问题'),
|
|
('power', '电源问题'),
|
|
('user_operation', '用户操作错误'),
|
|
('other', '其他原因')
|
|
],
|
|
string='故障原因',
|
|
)
|
|
processing_results = fields.Selection([('done', '已解决 '), ('undone', '未解决'), ('part', '部分解决')], string="处理结果", default='undone')
|
|
is_fee = fields.Boolean(string="是否产生费用")
|
|
|
|
labor_costs = fields.Float(string="人工费")
|
|
lamp_model = fields.Float(string="日光灯款")
|
|
stuff_costs = fields.Float(string="代垫用料费")
|
|
fee_description = fields.Text(string="费用说明")
|
|
|
|
follow_up = fields.Text(string="后续情况")
|
|
create_time = fields.Date(string="创建日期", default=fields.Datetime.now)
|
|
|
|
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("company_id", "repair_id", "device_id", "property_id")
|
|
def _compute_name(self):
|
|
for record in self:
|
|
if record.repair_id and record.property_id:
|
|
record.display_name = f"{record.property_id.name}-处理单"
|
|
elif record.device_id:
|
|
record.display_name = f"{record.device_id.name}-处理单"
|
|
else:
|
|
record.display_name = False
|
|
|
|
@api.depends('property_id')
|
|
def _compute_contract_id(self):
|
|
for record in self:
|
|
contract_id = self.env["property.lease.contract.line"].browse()
|
|
if record.property_id:
|
|
contract_id = self.env["property.lease.contract.line"].search(
|
|
[
|
|
('address_id', '=', record.property_id.id),
|
|
],
|
|
limit=1
|
|
)
|
|
else:
|
|
record.contract_id = False
|
|
|
|
if contract_id and contract_id.lease_id:
|
|
record.contract_id = contract_id.lease_id.id
|
|
else:
|
|
record.contract_id = False
|
|
|
|
def open_record(self):
|
|
if self.device_id:
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': self.device_id.display_name,
|
|
'res_model': 'property.device.repair',
|
|
'res_id': self.device_id.id,
|
|
'view_mode': 'form',
|
|
'view_type': 'form',
|
|
'target': 'new'
|
|
}
|
|
elif self.repair_id:
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': self.repair_id.display_name,
|
|
'res_model': 'property.report.repair',
|
|
'res_id': self.repair_id.id,
|
|
'view_mode': 'form',
|
|
'view_type': 'form',
|
|
'target': 'new'
|
|
}
|
|
|
|
@api.onchange('repair_id')
|
|
def onchange_repair_id(self):
|
|
if self.repair_id:
|
|
self.property_id = self.repair_id.property_id
|
|
self.lessee_id = self.repair_id.lessee_id
|
|
self.contact = self.repair_id.contact
|
|
self.phone = self.repair_id.phone
|
|
self.problem_description = self.repair_id.problem_description
|
|
else:
|
|
self.property_id = False
|
|
self.lessee_id = False
|
|
self.contact = False
|
|
self.phone = False
|
|
self.problem_description = False
|
|
|
|
def pull_accounts(self):
|
|
order_ids = self.env["processing.order.approval"].browse(
|
|
self._context.get('active_ids', self._context.get('active_id')))
|
|
for rec in order_ids:
|
|
if not rec.is_fee:
|
|
raise UserError('只有产生收费的维修才能生成应收!')
|
|
if rec.work_end:
|
|
raise UserError('流程未结束,不能生成应收!')
|
|
if rec.repair_id:
|
|
contract_id = rec.env["property.lease.contract.line"].search([('address_id', '=', rec.property_id.id)], limit=1)
|
|
management_type_id = rec.env["yuthon.management.type"].search([('name', '=', '人工费/日光灯款/代垫用料费')])
|
|
if not management_type_id:
|
|
management_type_id = rec.env["yuthon.management.type"].create({'name': '人工费/日光灯款/代垫用料费'})
|
|
remarks = []
|
|
if rec.labor_costs > 0:
|
|
remarks.append(f"人工费: {rec.labor_costs}")
|
|
if rec.lamp_model > 0:
|
|
remarks.append(f"日光灯款: {rec.lamp_model}")
|
|
if rec.stuff_costs > 0:
|
|
remarks.append(f"代垫用料费: {rec.stuff_costs}")
|
|
remark = ", ".join(remarks) if remarks else ""
|
|
if contract_id and contract_id.lease_id.lessee_id:
|
|
self.env['property.accounts.receivable'].create({
|
|
'contract_id': contract_id.lease_id.id,
|
|
'due_date': fields.Date.today(),
|
|
'management_type_id': management_type_id.id,
|
|
'original_amount': rec.labor_costs + rec.stuff_costs + rec.labor_costs,
|
|
'remark': remark
|
|
})
|
|
|
|
def end_approval(self):
|
|
for rec in self:
|
|
if rec.processing_results in ['done', 'part']:
|
|
menu_id = self.env['ir.ui.menu'].search([('name', '=', '处理单')])
|
|
url = f'https://oa.thtzjt.com/web#id={self.id}&cids=2&action={menu_id.action.id}&model=processing.order.approval&view_type=list&menu_id={menu_id.id}'
|
|
if rec.device_id:
|
|
rec.device_id.report_state = 'done'
|
|
else:
|
|
rec.repair_id.report_state = 'done'
|
|
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='oa',
|
|
user_id=rec.applicant_id.employee_id.wecom_userid,
|
|
title="处理单",
|
|
description="你有一份已处理的报时报修",
|
|
url=url, btntxt="详细信息")
|
|
|
|
|