164 lines
8.4 KiB
Python
164 lines
8.4 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 datetime import timedelta
|
|
|
|
|
|
class PropertyManagement(models.Model):
|
|
_name = 'property.management'
|
|
_description = '物业管理变更'
|
|
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'soong.workflow.mixin']
|
|
_rec_name = 'name'
|
|
|
|
name = fields.Char(string='标题')
|
|
code = fields.Char(string="编号",
|
|
default=lambda self: self.env['ir.sequence'].next_by_code('property_management_code'))
|
|
reason_change = fields.Char(string="变更事由")
|
|
user_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user)
|
|
department_id = fields.Many2one('hr.department', related='user_id.employee_id.department_id',string="申请人部门", store=True)
|
|
handling_opinions = fields.Text(string="经办意见")
|
|
management_line2_ids = fields.One2many('property.management.line2', 'property_management_id', string="原物业信息")
|
|
management_line_ids = fields.One2many('property.management.line', 'property_management_id', string="物业信息")
|
|
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
|
|
default='normal')
|
|
is_issues = fields.Boolean(string='是否上会')
|
|
is_line = fields.Boolean(string='明细行隐藏')
|
|
issues_result = fields.Html(string="会议结果")
|
|
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
|
active = fields.Boolean('Active', default=True, tracking=True)
|
|
work_end = fields.Boolean(string="结束")
|
|
|
|
company_id = fields.Many2one('yuthon.property.company', string="公司")
|
|
purpose_id = fields.Many2one('yuthon.resource.purpose', string="管理类型")
|
|
admin_id_all = fields.Many2one('res.users', string="管理员")
|
|
precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区")
|
|
tenure_type = fields.Selection([('self', '自有'), ('agency', '代管')], string='权属类型')
|
|
start_time = fields.Date(string="生效日期", default=lambda self: fields.Date.today())
|
|
|
|
def _get_default_name_title(self):
|
|
return self._description if self._description else self._name
|
|
|
|
name_title = fields.Char(default=_get_default_name_title)
|
|
document_ids = fields.Many2many('ir.attachment', string="附件")
|
|
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
|
|
|
|
@api.onchange('precinct_id')
|
|
def _onchange_precinct_id(self):
|
|
if self.precinct_id:
|
|
self.admin_id_all = self.precinct_id.employee_id.user_id.id
|
|
|
|
@api.onchange('is_issues')
|
|
def _onchange_is_issues(self):
|
|
if self.is_issues:
|
|
issue_id = self.env['issue.library'].create({'name': self.name, 'is_invisible_workflow': True})
|
|
self.related_issues_id = issue_id.id
|
|
self.env['issue.library.approval.line'].create({
|
|
'issue_library_id': issue_id.id,
|
|
'workflow_name': self.name,
|
|
'approval_type': self.workflow_id.name,
|
|
'res_model': self._name,
|
|
'res_id': self.id,
|
|
'code': self.code,
|
|
'approval_date': fields.Datetime.now(),
|
|
})
|
|
|
|
@api.onchange('management_line2_ids')
|
|
def _onchange_management_line2_ids(self):
|
|
self.management_line_ids = [(5, 0, 0)]
|
|
for line in self.management_line2_ids:
|
|
if line.property_id:
|
|
self.management_line_ids = [(0, 0, {
|
|
'property_id': line.property_id.id,
|
|
'company_id': line.company_id.id,
|
|
'purpose_id': line.purpose_id.id,
|
|
'precinct_id': line.precinct_id.id,
|
|
'admin_id_all': line.admin_id_all.id,
|
|
'tenure_type': line.tenure_type
|
|
})]
|
|
|
|
def approval_end(self):
|
|
for record in self:
|
|
for line in record.management_line2_ids:
|
|
# 更新信息行的结束日期
|
|
if line.information_line_id:
|
|
line.information_line_id.write({'end_date': fields.Date.today()})
|
|
# 直接从关联的上一条记录获取值(如果存在)
|
|
prev_info = line.information_line_id
|
|
target_start_time = record.start_time
|
|
target_property_id = line.property_id.id
|
|
existing_info = self.env['manage.information.line'].search([
|
|
('yuthon_property_id', '=', target_property_id),
|
|
('start_time', '=', target_start_time)
|
|
], limit=1)
|
|
# 如果已有相同start_time的记录,跳过创建
|
|
if existing_info:
|
|
continue
|
|
|
|
# 创建新的信息行记录,从prev_info获取缺失的值
|
|
info_line_vals = {
|
|
'yuthon_property_id': line.property_id.id,
|
|
'purpose_id': record.purpose_id.id if record.purpose_id else prev_info.purpose_id.id,
|
|
'precinct_id': record.precinct_id.id if record.precinct_id else prev_info.precinct_id.id,
|
|
'management_area': prev_info.management_area if prev_info else 0.0,
|
|
'tenure_type': record.tenure_type or prev_info.tenure_type,
|
|
'rent_area': prev_info.rent_area if prev_info else 0.0,
|
|
'admin_id': record.precinct_id.employee_id.user_id.id if record.precinct_id else prev_info.admin_id.id,
|
|
'company_id': record.company_id.id if record.company_id else prev_info.company_id.id if prev_info else False,
|
|
'start_time': record.start_time,
|
|
}
|
|
prev_info.end_date = record.start_time - timedelta(days=1)
|
|
# 创建新记录
|
|
self.env['manage.information.line'].create(info_line_vals)
|
|
line.property_id.compute_information_fields()
|
|
|
|
record.write({'is_line': True})
|
|
|
|
def put_property_management(self):
|
|
return {
|
|
'name': '物业信息',
|
|
'type': 'ir.actions.act_window',
|
|
'res_model': 'property.management.wizard',
|
|
'view_mode': 'form',
|
|
'target': 'new',
|
|
'context': {'default_property_management_id': self.id}
|
|
}
|
|
|
|
def clear_the_details(self):
|
|
self.management_line_ids.unlink()
|
|
self.management_line2_ids.unlink()
|
|
|
|
# 结果保留明细行
|
|
class PropertyManagementLine(models.Model):
|
|
_name = 'property.management.line'
|
|
_description = '物业信息'
|
|
|
|
property_id = fields.Many2one('yuthon.property', string="物业名称")
|
|
property_management_id = fields.Many2one('property.management', string="关联物业分配申请表")
|
|
information_line_id = fields.Many2one('manage.information.line')
|
|
company_id = fields.Many2one('yuthon.property.company', string="公司")
|
|
purpose_id = fields.Many2one('yuthon.resource.purpose', string="管理类型")
|
|
admin_id_all = fields.Many2one('res.users', string="管理员")
|
|
precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区")
|
|
tenure_type = fields.Selection([('self', '自有'), ('agency', '代管')], string='权属类型')
|
|
state = fields.Selection(related='property_management_id.state', string='状态')
|
|
|
|
|
|
# 初始明细行
|
|
class PropertyManagementLine2(models.Model):
|
|
_name = 'property.management.line2'
|
|
_description = '物业信息'
|
|
|
|
property_management_id = fields.Many2one('property.management', string="关联物业分配申请表")
|
|
property_id = fields.Many2one('yuthon.property', string="物业名称")
|
|
purpose_id = fields.Many2one('yuthon.resource.purpose', string="管理类型")
|
|
information_line_id = fields.Many2one('manage.information.line')
|
|
tenure_type = fields.Selection(related='property_id.tenure_type', string='权属类型')
|
|
company_id = fields.Many2one(related='property_id.company_id', string="公司")
|
|
admin_id_all = fields.Many2one(related='property_id.admin_id', string="管理员")
|
|
precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区")
|
|
state = fields.Selection(related='property_management_id.state', string='状态')
|
|
|
|
|
|
class PropertyInformationDetailLines(models.Model):
|
|
_name = 'property.information.detail.lines' |