diff --git a/yuthon_property/models/property_bank_statements.py b/yuthon_property/models/property_bank_statements.py index 489ca525b..7807e7b1d 100644 --- a/yuthon_property/models/property_bank_statements.py +++ b/yuthon_property/models/property_bank_statements.py @@ -275,6 +275,34 @@ class ReceivableModifyLine(models.Model): # 兜底:确保 delivered1 总是被赋值 rec.delivered1 = 0 + @api.onchange('reconciliation_date') + def _onchange_reconciliation_date(self): + """修改核销日期时,根据分组情况同步更新应收款的付款日期""" + for record in self: + if not record.receivable_id or not record.reconciliation_date: + continue + + receivable = record.receivable_id + # 查询同一 receivable_id 下的其他修改明细行(排除当前记录) + domain = [('receivable_id', '=', receivable.id), ('management_type_id', '=', record.management_type_id.id), ('id', '!=', record.id.origin)] + existing_lines = self.env['receivable.modify.line'].search(domain) + # 当前组内记录总数(含当前记录) + group_count = len(existing_lines) + 1 + if group_count == 1: + # 一组只有一条记录:直接同步 payout_date + receivable.payout_date = record.reconciliation_date + elif group_count == 2: + # 一组有两条记录:仅当修改前的 reconciliation_date + # 与 receivable 的 payout_date 相同时才同步 + old_reconciliation_date = False + if record.id.origin: + old_reconciliation_date = self.env['receivable.modify.line'].browse( + record.id.origin + ).reconciliation_date + + if old_reconciliation_date == receivable.payout_date: + receivable.payout_date = record.reconciliation_date + remake = fields.Text(related='receivable_id.remark', string='备注', store=False) # lessee_id = fields.Many2one( # "property.tenant.information",