141 lines
6.4 KiB
Python
141 lines
6.4 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 = '处理单审批'
|
|
_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('processing_order_approval_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="公司")
|
|
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='done')
|
|
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('property_id')
|
|
def _compute_contract_id(self):
|
|
for record in self:
|
|
if record.property_id:
|
|
contract_id = self.env["property.lease.contract.line"].search(
|
|
[('address_id', '=', record.property_id.id)],
|
|
limit=1
|
|
)
|
|
else:
|
|
contract_id = False
|
|
record.contract_id = contract_id.lease_id.id if contract_id else False
|
|
|
|
@api.depends("company_id")
|
|
def _compute_name(self):
|
|
self.name = False
|
|
if self.repair_id:
|
|
self.name = self.property_id.name + '-处理单'
|
|
if self.device_id:
|
|
self.name = self.device_id.name + '-处理单'
|
|
|
|
@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
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|