From 56ff75d806c331bf43fae900e34fa3eeb1c1f3f1 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Mon, 7 Jul 2025 17:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/property_lease_contract.py | 35 +++++++++++++++++-- .../views/inherit_yuthon_property_views.xml | 4 ++- .../views/property_lease_contract.xml | 7 ++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index db9077667..2f229523f 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -156,13 +156,13 @@ class PropertyLeaseContract(models.Model): miscellaneous = fields.Text(string="其他约定") number = fields.Integer(string="次数", default=0) total_area = fields.Float(string="总面积", digits=(16, 4)) - not_received = fields.Float(string="未收") + not_received = fields.Float(string="未收", compute="_compute_not_received", store=True) actual_receivable = fields.Float(string="实际应收") now_receivable = fields.Float(string="当期应收") total_receivable = fields.Float(string="总已收") comparison = fields.Selection([('outweigh', '大于'), ('equal', '等于'), ('less', '小于')], string="对比", compute='_compute_comparison') progress_percentage = fields.Float(string="合同进度", compute="_compute_progress_percentage") - condition = fields.Selection([('new', '新建'), ('approval', '审批中'), ('cancel', '作废'), ('be_executed', '待执行'), ('executed', '已执行'), ('expired', '已终止'), ('advance', '提前终止')], string="状态", default='new') + condition = fields.Selection([('new', '新建'), ('approval', '审批中'), ('cancel', '作废'), ('be_executed', '待执行'), ('executed', '已执行'), ('expired', '已终止')], string="状态", default='new') contract_type = fields.Selection([('lease_renewal', '续租'), ('interim', '临租'), ('new', '补充协议'), ('first', '首租')], string="合同类型", default='first') performance_bonds = fields.Float(string="经营履约保证金") utility_bills = fields.Float(string="水电费押金") @@ -213,6 +213,24 @@ class PropertyLeaseContract(models.Model): responsibility_book_name = fields.Char(string="安全生产责任书(住宅)名称", compute='_compute_attachment_names', store=True) + @api.depends() + def _compute_not_received(self): + not_reconciled_records = self.env['property.accounts.receivable'].search([ + ('contract_id', '=', self.id), + ('is_reconciliation', '=', False) + ]) + self.not_received = sum(record.submitted for record in not_reconciled_records) + + def update_not_received(self): + contract_ids = self.env["property.lease.contract"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for rec in contract_ids: + not_reconciled_records = self.env['property.accounts.receivable'].search([ + ('contract_id', '=', rec.id), + ('is_reconciliation', '=', False) + ]) + rec.not_received = sum(record.submitted for record in not_reconciled_records) + def update_admin_id(self): contract_ids = self.env["property.lease.contract"].browse( self._context.get('active_ids', self._context.get('active_id'))) @@ -1310,6 +1328,17 @@ class PropertyLeaseContract(models.Model): actual_start = contract.actual_start_time actual_end = contract.actual_end_time term_end = contract.term_end_time + effective_month = None + if actual_end: + # 获取实际结束日期所在月的最后一天 + last_day_of_month = calendar.monthrange(actual_end.year, actual_end.month)[1] + if actual_end.day == last_day_of_month: + # 如果是最后一天,生效月份为下月 + effective_month = fields.Date.to_date(f"{actual_end.year}-{actual_end.month}-{last_day_of_month}") + else: + # 如果不是最后一天,生效月份为当月 + effective_month = fields.Date.to_date(f"{actual_end.year}-{actual_end.month}-01") + # 根据时间条件更新状态 if not actual_start or today < actual_start: # 待执行:实际开始时间未到或未设置 @@ -1319,7 +1348,7 @@ class PropertyLeaseContract(models.Model): contract.contact_state = 'ing' elif today >= actual_end == term_end: contract.contact_state = 'complete' - elif today >= actual_end < term_end: + elif effective_month and today >= effective_month < term_end: contract.contact_state = 'terminate' diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml index d343a0947..9fbdd2a4a 100644 --- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml +++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml @@ -31,6 +31,8 @@ + + @@ -63,7 +65,7 @@ property.rent.list tree,search [('is_push', '=', False)] - {'group_by': ['admin_id', 'due_date:month']} + {'search_default_group_admin_id': True, 'search_default_group_due_date': True} diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 204ef121a..5e4ece38c 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -859,6 +859,13 @@ code action = model.all_end_approval() + + 更新未收金额 + + + code + action = model.update_not_received() + 同步更新管理员