diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index fb4b9cc3a..7a4076cca 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -98,25 +98,9 @@ class YuthonProperty(models.Model): else: record.first_letter = '' - @api.onchange('manage_information_ids', 'title_information_ids') + @api.onchange('title_information_ids') def _onchange_information_ids(self): - today = fields.Date.today() for rec in self: - valid_manage = rec.manage_information_ids.filtered( - lambda m: m.start_time and m.start_time <= today and - (not m.end_date or m.end_date >= today) - ) - if valid_manage: - latest_record_id = valid_manage[0] - rec.write({ - 'management_area':latest_record_id.management_area, - 'rent_area': latest_record_id.rent_area, - 'purpose_id':latest_record_id.purpose_id.id, - 'precinct_id': latest_record_id.precinct_id.id, - 'admin_id':latest_record_id.admin_id.id, - 'company_id':latest_record_id.company_id.id, - 'tenure_type': latest_record_id.tenure_type, - }) if rec.title_information_ids: latest_title_information = sorted(rec.title_information_ids, key=lambda x: x.start_time, reverse=True)[0] rec.write({ @@ -366,6 +350,42 @@ class YuthonProperty(models.Model): if record.manage_information_ids: record.manage_information_ids[0].precinct_id = precinct_id.id if precinct_id else '' + def revert_change(self): + property_ids = self.env["yuthon.property"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for record in property_ids: + lines = record.manage_information_ids + prev_line = lines[-2] + # 删除最后一条记录 + lines[-1].unlink() + # 更新当前记录的字段 + record.write({ + 'purpose_id': prev_line.purpose_id.id, + 'admin_id': prev_line.admin_id.id, + 'precinct_id': prev_line.precinct_id.id, + 'company_id': prev_line.company_id.id, + 'management_area': prev_line.management_area, + 'rent_area': prev_line.rent_area, + 'tenure_type': prev_line.tenure_type, + }) + # 合同信息还原 + contract = self.env['property.lease.contract.line'].search( + [('address_id', '=', record.id)], + limit=1 + ) + if contract: + lease_id = contract.lease_id + lease_id.write({'admin_id': prev_line.admin_id.id}) + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': '操作成功', + 'message': '物业变更信息已成功还原', + 'sticky': False, # 不显示关闭按钮,自动消失 + 'type': 'success', # 成功消息样式 + } + } class YuthonPropertyWater(models.Model): _name = 'yuthon.property.water' @@ -421,10 +441,10 @@ class ManageInformationLine(models.Model): management_area = fields.Float(string="管理面积", digits=(16, 4)) rent_area = fields.Float(string="可租面积", digits=(16, 4)) admin_id = fields.Many2one('res.users', string="管理员") - company_id = fields.Many2one('yuthon.property.company', string="公司") start_time = fields.Date(string="生效日期", default=fields.Date.today) end_date = fields.Date(string="失效日期") + create_date = fields.Date(string="创建日期", default=fields.Date.today) class DisassemblyInformationLine(models.Model): diff --git a/yuthon_property/views/yuthon_property_views.xml b/yuthon_property/views/yuthon_property_views.xml index 9ccd3c3ed..36f33173d 100644 --- a/yuthon_property/views/yuthon_property_views.xml +++ b/yuthon_property/views/yuthon_property_views.xml @@ -135,6 +135,7 @@ + @@ -372,4 +373,12 @@ code action = model.trigger_company_id() + + 还原物业变更信息 + + + code + action = model.revert_change() + + \ No newline at end of file diff --git a/yuthon_property_approval/models/property_management.py b/yuthon_property_approval/models/property_management.py index b07fb9176..ae9def672 100644 --- a/yuthon_property_approval/models/property_management.py +++ b/yuthon_property_approval/models/property_management.py @@ -106,7 +106,6 @@ class PropertyManagement(models.Model): '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, 'tenure_type': record.tenure_type or prev_info.tenure_type, - 'management_area': prev_info.management_area if prev_info else 0.0, 'rent_area': prev_info.rent_area if prev_info else 0.0, 'admin_id': record.admin_id_all.id if record.admin_id_all 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,