Files
gzth/yuthon_property_approval/models/property_split_approval.py
T
2025-03-13 17:40:11 +08:00

79 lines
4.1 KiB
Python

from odoo import models, fields, api, exceptions, _
from odoo.exceptions import UserError
class PropertySplitApproval(models.Model):
_name = 'property.split.approval'
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
_description = '物业拆分审批'
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('property_split_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="部门")
property_id = fields.Many2one('yuthon.property', string='物业名称')
units = fields.Char(related='property_id.units', string='单元')
property_floor = fields.Char(related='property_id.property_floor', string='楼层')
asset_type_id = fields.Many2one(related='property_id.asset_type_id', string='资产类型')
building_area = fields.Float(related='property_id.building_area', string='建筑面积')
rent_area = fields.Float(related='property_id.rent_area', string='可租面积')
remarks = fields.Char(string='备注')
is_issues = fields.Boolean(string='是否上会')
issues_result = fields.Html(string="会议结果")
related_issues_id = fields.Many2one('issue.library', string="关联议题")
name = fields.Char(string='标题')
reason = fields.Html(string="正文")
notice_documents_ids = fields.Many2many('ir.attachment', string="附件")
property_split_approval_line_ids = fields.One2many('property.split.approval.line', 'property_split_approval_id', string='关联物业拆分明细行')
split_quantity = fields.Integer(string='拆分数量', default=2)
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
default='normal')
active = fields.Boolean('Active', default=True, tracking=True)
def _get_default_name_title(self):
return self._description if self._description else self._name
name_title = fields.Char(default=_get_default_name_title)
def property_split_button(self):
if self.split_quantity < 2:
raise UserError('拆分数量必须是大于2')
if self.id.origin and self.property_id:
lines_to_create = []
for i in range(self.split_quantity):
lines_to_create.append({
'property_split_approval_id': self.id.origin,
'split_property': f"{self.property_id.name}-{i + 1}"
})
self.property_split_approval_line_ids.unlink()
self.env['property.split.approval.line'].create(lines_to_create)
def put_split_message(self):
property_list = []
for property_split in self.property_split_approval_line_ids:
property_id = self.env['yuthon.property'].create({
'name': property_split.split_property,
'building_area': property_split.split_building_area,
'rent_area': property_split.split_rent_area,
'asset_type_id': property_split.split_asset_type_id.id,
'property_merge_approval_id':self.property_id.id,
'is_done_merge': True
})
property_list.append([0, 0, {'property_id':property_id.id}])
self.property_id.write({'is_done_split': True})
self.property_id.disassembly_information_ids = property_list
class PropertySplitApprovalLine(models.Model):
_name = 'property.split.approval.line'
_description = '物业拆分明细行'
property_split_approval_id = fields.Many2one('property.split.approval', string='关联物业拆分审批')
split_property = fields.Char(string='物业名称')
split_units = fields.Char(string='单元')
split_property_floor = fields.Char(string='楼层')
split_asset_type_id = fields.Many2one('yuthon.resource.type', string='资产类型')
split_building_area = fields.Float(string='建筑面积')
split_rent_area = fields.Float(string='可租面积')
split_remarks = fields.Char(string='备注')